ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/c++/Config.cpp
(Generate patch)

Comparing projects/cms/source/host/c++/Config.cpp (file contents):
Revision 1.4 by ab11, Thu Mar 1 20:10:53 2001 UTC vs.
Revision 1.7 by tdb, Sat May 18 18:15:56 2002 UTC

# Line 1 | Line 1
1 + /*
2 + * i-scream central monitoring system
3 + * Copyright (C) 2000-2002 i-scream
4 + *
5 + * This program is free software; you can redistribute it and/or
6 + * modify it under the terms of the GNU General Public License
7 + * as published by the Free Software Foundation; either version 2
8 + * of the License, or (at your option) any later version.
9 + *
10 + * This program is distributed in the hope that it will be useful,
11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 + * GNU General Public License for more details.
14 + *
15 + * You should have received a copy of the GNU General Public License
16 + * along with this program; if not, write to the Free Software
17 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 + */
19 +
20   #include "Config.h"
21  
22   Config::Config( string serverName, int serverPort, int printDebug ){
23          // the constructor for the class
24          
6        
25          configConnectionRetryTime = 1; // one second
26          debug = printDebug;
27 <        MAX_CONNECTION_ATTEMPTS = 10; //
27 >        MAX_CONNECTION_ATTEMPTS = 10;
28          
29          configName = serverName;
30          configPort = serverPort;
31          
32          if ( debug == 1 ){
33                  std::cout << "Config Constructor\n";
34 <        }
34 >        } // if
35          
36          
37          // make a reference to smallnet
# Line 21 | Line 39 | Config::Config( string serverName, int serverPort, int
39                  std::cout << "Config::Constructor::Constructing SmallNet\n";
40          }
41          net = new SmallNet(debug);
42 <        // net->setDebug(1);
25 <        
26 <        // read the values which we want to retrieve from the
27 <        // config manager from the "config.values.txt" file
28 <        //propertyNames = new string[20];
29 <        //propertyValues = new string[20];
30 <        
31 <        // FIX ME
42 >                
43          // sod that we are using defined values now..
44          propertyNames[0] = "UDPUpdateTime";
45          propertyNames[1] = "TCPUpdateTime";
46          propertyNames[2] = "FilterRetryTime";
47          propertyNames[3] = "ConfigRetryTime";
48 <        numProperties = 4;
48 >        propertyNames[4] = "AVERAGERUpdateTime";
49 >        propertyNames[5] = "MAXTCPFilterRetries";
50 >        numProperties = 5;
51          
39        // read the Chat dialog we 'expect' to have with the config
40        // manager from disk. This is a new idea so that the client
41        // won't have to be hard coded with the dialog (incase it changes)
42        
43        // FIX ME
44        
52          if ( loadConfig() == 0 ){
53                  // successful just continue
54                  if ( debug == 1 ){
55                          std::cout << "Config::Constructor::loadConfig() Successful\n";
56 <                }
57 <        }
51 <        else {
56 >                } // if
57 >        } else {
58                  if ( debug == 1 ){
59                          std::cout << "Config::Constructor::loadConfig() failed-retrying\n";
60 <                }
60 >                } // if
61 >                
62                  // woops something went wrong. we'll just keep retrying
63                  // and increasing the time between trys
64                  int loadConfigResult = -1;
# Line 62 | Line 69 | Config::Config( string serverName, int serverPort, int
69                  while ( loadConfigResult != 0 ){
70                          if ( retrys > MAX_CONNECTION_ATTEMPTS ){
71                                  std::cout << "Maxium number of retries reached, Quitting";
72 <                                // exit("Failed to connect");
66 <                        }
72 >                        } // if
73                          // make the connection retry time greater
74                          configConnectionRetryTime = configConnectionRetryTime * 2;
75                          std::cout << "Waiting " << configConnectionRetryTime << " seconds before retrying\n";
# Line 72 | Line 78 | Config::Config( string serverName, int serverPort, int
78                          retrys++;
79                          loadConfigResult = loadConfig();
80                  } // while
75                
76        
81          } // if
82          
83          if ( debug == 1 ){
84                  std::cout << "Config::Constructor - Finished!\n";
85 <        }
85 >        } // if
86          
87   } // Config
88  
# Line 88 | Line 92 | int Config::loadConfig(){
92          
93          if ( debug == 1 ){
94                  std::cout << "Config::loadConfig()\n";
95 <        }
95 >        } // if
96          
97          // make a connection
98          
99          if ( debug == 1 ){
100                  std::cout << "Config::loadConfig::establishing config connection\n";
101 <        }
101 >        } // if
102 >        
103          int established = establishConfig();
104          if ( established != 0 ){
105 +            destroyConfig();
106                  return established;
107 <        }
107 >        } // if
108          
109          // do the talk ;)
110          
111          if ( debug == 1 ){
112                  std::cout << "Config::loadConfig::Processing chat script\n";
113 <        }
113 >        } // if
114 >        
115          int chat = chatConfig();
116          if ( chat != 0 ){
117                  // and close the connection
118                  destroyConfig();
119 <                // return chat;
113 <        }
119 >        } // if
120          
121          // and close the connection
116        
122          if ( debug == 1 ){
123                  std::cout << "Config::loadConfig::closing config connection\n";
124 <        }
124 >        } // if
125          destroyConfig();
126          
127          // return everything ok
# Line 128 | Line 133 | int Config::establishHeartbeat(){
133          // just an interface onto smallnet
134          if ( debug == 1 ){
135                  std::cout << "Config::establishHeartbeat()\n";
136 <        }
136 >        } // if
137          
138 <        int establish = net->connectHeartBeat(configName, configPort);
139 <        
138 >        int establish =  net->connectHeartBeat(configName, configPort);
139 >            
140          if ( debug == 1 ){
141                  std::cout << "->" << establish << "\n";
142 <        }
142 >        } // if
143          
144          return establish;
145                  
146   } // establishHeartBeat
147  
143
148   int Config::destroyHeartbeat(){
149          // just hooks into the smallnet interface
150          if ( debug == 1 ){
151                  std::cout << "Config::destroyHeartbeat()\n";
152 <        }
152 >        } // if
153          
154          net->closeHeartBeatConnection();
155          
156   } // destroyHeartBeat
157  
158 + int Config::chatHeartBeat(){
159 +        
160 +        string response;
161 +        
162 +        response = net->heartBeatSend("HEARTBEAT");
163 +        if ( response != "OK" ){
164 +                // something went wrong
165 +                if ( debug == 1 ){
166 +                        std::cout << "Config::chatHeartBeat::ERROR in HEARTBEAT\n";
167 +                } // if
168 +                return -1;
169 +        } // if
170 +        
171 +        response = net->heartBeatSend("CONFIG");
172 +        if ( response != "OK" ){
173 +                // something went wrong
174 +                if ( debug == 1 ){
175 +                        std::cout << "Config::chatHeartBeat::ERROR in CONFIG\n";
176 +                } // if
177 +                return -1;
178 +        } // if
179 +        
180 +        response = net->heartBeatSend(fileList);
181 +        if ( response != "OK" ){
182 +                // something went wrong
183 +                if ( debug == 1 ){
184 +                        std::cout << "Config::chatHeartBeat::ERROR in fileList\n";
185 +                } // if
186 +                return -1;
187 +        } // if
188 +        
189 +        response = net->heartBeatSend(lastModified);
190 +        if ( response != "OK" ){
191 +                // something went wrong
192 +                if ( debug == 1 ){
193 +                        std::cout << "Config::chatHeartBeat::ERROR in lastModified\n";
194 +                } // if
195 +                return -1;
196 +        } // if
197 +        
198 +        response = net->heartBeatSend("ENDHEARTBEAT");
199 +        if ( response != "OK" ){
200 +                // something went wrong
201 +                if ( debug == 1 ){
202 +                        std::cout << "Config::chatHeartBeat::ERROR in ENDHEARTBEAT\n";
203 +                } // if
204 +                return -1;
205 +        } // if
206 +        
207 +        // seems ok to me
208 +        return 0;
209 +        
210 + } // chat Heart Beat
211  
212 +
213   int Config::establishConfig(){
214          // ask smallnet to make a connection to the filtermanager so we can get some config
215          // details
# Line 159 | Line 217 | int Config::establishConfig(){
217                  std::cout << "Config::establishConfig()\n";
218          }
219          
162        
163        /* MODIFY THIS */
220          int response = net->connectConfig(configName, configPort);
221          
222          if ( debug == 1 ){
223                  std::cout << "->" << response << "\n";
224 <        }
224 >        } // if
225          
226          return response;
227          
# Line 176 | Line 232 | int Config::chatConfig(){
232          // do some funky jibble.. ;)
233          if ( debug == 1 ){
234                  std::cout << "Config::chatConfig()\n";
235 <        }
235 >        } // if
236          
237          string response;
238 <        
183 <        
238 >
239          // hard coeded for the moment
240          if ( debug == 1 ){
241                  std::cout << "Config::chatConfig::STARTCONFIG\n";
242 <        }
242 >        } // if
243 >        
244          response = net->heartBeatSend("STARTCONFIG");
245          if ( response != "OK" ){
246                  // something went wrong
191                return -1;
247                  if ( debug == 1 ){
248                          std::cout << "Config::chatConfig::ERROR\n";
249 <                }
250 <        }
249 >                } // if
250 >                return -1;      
251 >        } // if
252          
253          if ( debug == 1 ){
254                  std::cout << "Config::chatConfig::LASTMODIFIED\n";
255 <        }
255 >        } // if
256          lastModified = net->heartBeatSend("LASTMODIFIED");
257          if ( debug == 1 ){
258                  std::cout << "Config::chatConfig::FILELIST\n";
259 <        }
259 >        } // if
260          fileList = net->heartBeatSend("FILELIST");
261          
262          fQDN = net->heartBeatSend("FQDN");
# Line 209 | Line 265 | int Config::chatConfig(){
265          
266          if ( debug == 1 ){
267                  std::cout << "Config::chatConfig::requesting properties\n";
268 <        }
268 >        } // if
269          if ( numProperties > 0 ){
270                  // we actually need to look for some properties
271                  for ( int i=0; i < numProperties; i++ ){
272                          // lets hope that this works! ;)
273                          if ( debug == 1 ){
274                                  std::cout << "Config::chatConfig::" << propertyNames[i] << "\n";
275 <                        }
275 >                        } // if
276                          propertyValues[i] = net->heartBeatSend(propertyNames[i]);
277                  } // for        
278          } // if
279          
280          if ( debug == 1 ){
281                  std::cout << "Config::chatConfig::ENDCONFIG\n";
282 <        }
282 >        } // if
283          response = net->heartBeatSend("ENDCONFIG");
284          // doesn't matter what it returns
285          
286          if ( debug == 1 ){
287                  std::cout << "Config::chatConfig::FILTER\n";
288 <        }
288 >        } // if
289 >        
290          response = net->heartBeatSend("FILTER");
291          // now we need to pull repsonse apart to get the filter information out
292          int first = response.find(";",0);
# Line 240 | Line 297 | int Config::chatConfig(){
297          
298          if ( debug == 1 ){
299                  std::cout << "Config::chatConfig::END\n";
300 <        }
300 >        } // if
301          response = net->heartBeatSend("END");
302          
303          return 0;      
# Line 250 | Line 307 | int Config::chatConfig(){
307   int Config::destroyConfig(){
308          if ( debug == 1 ){
309                  std::cout << "Config::destroyConfig()\n";
310 <        }
310 >        } // if
311          
312          net->closeConfigConnection();
313          
# Line 261 | Line 318 | string Config::getStrProperty(string propertyName){
318          
319          if ( debug == 1 ){
320                  std::cout << "Config::getProperty()\n";
321 <        }
321 >        } // if
322          
323          for ( int i=0; i<20; i++ ){
324                  if ( propertyName == propertyNames[i] ){
# Line 280 | Line 337 | int Config::getIntProperty( string propertyName ){
337          
338          if ( debug == 1 ){
339                  std::cout << "Config::getProperty()\n";
340 <        }
340 >        } // if
341          
342          string response = getStrProperty( propertyName );
343          if ( response == "ERROR" ){
# Line 290 | Line 347 | int Config::getIntProperty( string propertyName ){
347          int i = atoi(response.c_str());
348          
349          if ( i > 0 ){
350 +            // valid
351                  return i;
352 <        }
352 >        } // if
353                                          
354          // otherwise return ERROR
355          return -1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines