]> git.vomp.tv Git - vompserver.git/blob - config.h
Initial import
[vompserver.git] / config.h
1 /*
2     Copyright 2004-2005 Chris Tallon
3     Copyright 2004-2005 University Of Bradford
4
5     This file is part of VOMP.
6
7     VOMP is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation; either version 2 of the License, or
10     (at your option) any later version.
11
12     VOMP is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16
17     You should have received a copy of the GNU General Public License
18     along with VOMP; if not, write to the Free Software
19     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20 */
21
22 #ifndef CONFIG_H
23 #define CONFIG_H
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <pthread.h>
29 #include <ctype.h>
30
31 #define MAX_FILENAME_LENGTH 500
32 #define BUFFER_LENGTH 1500
33
34 class Config
35 {
36   public:
37     Config();
38
39     int init(char* fileName);
40     int shutdown();
41     int status();
42
43     char* getValueString(char* section, char* key);
44     long getValueLong(char* section, char* key, int* failure);
45     long long getValueLongLong(char* section, char* key, int* failure);
46     double getValueDouble(char* section, char* key, int* failure);
47
48     int setValueString(char* section, char* key, char* newValue);
49     int setValueLong(char* section, char* key, long newValue);
50     int setValueLongLong(char* section, char* key, long long newValue);
51     int setValueDouble(char* section, char* key, double newValue);
52
53     int deleteValue(char* section, char* key); // err.. delete "key".
54     char* getSectionKeyNames(char* section, int& numberOfReturns, int& length);
55
56   private:
57     pthread_mutex_t fileLock;
58     int initted;
59     int lastLineLength;
60
61     char fileName[MAX_FILENAME_LENGTH];
62     char fileNameTemp[MAX_FILENAME_LENGTH];
63
64     FILE* file;
65     char buffer[BUFFER_LENGTH];
66
67     int openFile();
68     void closeFile();
69     int readLine();
70     int findSection(char* section);
71     int findKey(char* key);
72     void trim(char* sting);
73     FILE* copyToHere(long position);
74     int copyRest(FILE* newFile);
75 };
76
77 #endif