comparison sources/core.cpp @ 5:0faceb076254

code clean up added PID to the default Core argument bool => true|false
author Vlad Glagolev <enqlave@gmail.com>
date Thu, 24 Jan 2008 21:00:52 +0300
parents a7051ac7118b
children 8d54d9fdeca3
comparison
equal deleted inserted replaced
4:a7051ac7118b 5:0faceb076254
21 #include "core.hpp" 21 #include "core.hpp"
22 22
23 Connection *C; 23 Connection *C;
24 24
25 Core::Core(): 25 Core::Core():
26 pid(PID),
26 commander(COMMANDER) 27 commander(COMMANDER)
27 { 28 {
28 pid = PID;
29
30 cout << "CORE: initializing...\n"; 29 cout << "CORE: initializing...\n";
31 30
32 debug = true; 31 debug = true;
33 32
34 now = gettime(); 33 now = gettime();
55 { 54 {
56 for (int e = 1; e < argc; e++) { 55 for (int e = 1; e < argc; e++) {
57 while (1) { 56 while (1) {
58 if (!strcmp(argv[e], "-c") || !strcmp(argv[e], "--config")) { 57 if (!strcmp(argv[e], "-c") || !strcmp(argv[e], "--config")) {
59 if (!argv[++e]) 58 if (!argv[++e])
60 shut ("missing configuration file"); 59 shut("missing configuration file");
61 60
62 config = argv[e]; 61 config = argv[e];
63 break; 62 break;
64 } else if (!strcmp(argv[e], "-h") || !strcmp(argv[e], "--help")) { 63 } else if (!strcmp(argv[e], "-h") || !strcmp(argv[e], "--help")) {
65 showHelp(); 64 showHelp();
66 } else if (!strcmp(argv[e], "-d") || !strcmp(argv[e], "--daemon")) { 65 } else if (!strcmp(argv[e], "-d") || !strcmp(argv[e], "--daemon")) {
67 debug = false; 66 debug = false;
68 break; 67 break;
69 } else 68 } else
70 shut ("unknown option detected: " + (string)argv[e]); 69 shut("unknown option detected: " + (string)argv[e]);
71 } 70 }
72 } 71 }
73 } 72 }
74 73
75 void Core::parseConfig() 74 void Core::parseConfig()
79 C = NULL; 78 C = NULL;
80 79
81 ifstream sysconfig(config, ios::in); 80 ifstream sysconfig(config, ios::in);
82 81
83 if (!sysconfig) 82 if (!sysconfig)
84 shut ("unable to open configuration file"); 83 shut("unable to open configuration file");
85 else { 84 else {
86 cout << "CORE: parsing configuration file: " << config << endl; 85 cout << "CORE: parsing configuration file: " << config << endl;
87 86
88 if (servers + 1 < MAX_SERVERS) { 87 if (servers + 1 < MAX_SERVERS) {
89 connections[++servers] = new Connection(); 88 connections[++servers] = new Connection();
134 void Core::work() 133 void Core::work()
135 { 134 {
136 while (1) { 135 while (1) {
137 now = gettime(); 136 now = gettime();
138 137
139 usleep (100); 138 usleep(100);
140 139
141 for (int e = 0; e < servers; e++) 140 for (int e = 0; e < servers; e++)
142 connections[e]->establish(); 141 connections[e]->establish();
143 } 142 }
144 } 143 }