comparison sources/core.cpp @ 2:19227b0b7cc1

.h => .hpp for the headers added year 2008 to copyright notes renamed some functions for better meaning prepared parser module for rewriting added showHelp() function some code clean up
author Vlad Glagolev <enqlave@gmail.com>
date Mon, 21 Jan 2008 01:14:10 +0300
parents bafff9de2a76
children a7051ac7118b
comparison
equal deleted inserted replaced
1:08d8cdf4fe7f 2:19227b0b7cc1
1 /** core.cpp (2007-03-04) 1 /** core.cpp (2007-03-04)
2 * 2 *
3 * -- CABAL -- core module 3 * -- CABAL -- core module
4 * 4 *
5 * Copyright (c) 2007 Vlad Glagolev <enqlave@gmail.com> 5 * Copyright (c) 2007-2008 Vlad Glagolev <enqlave@gmail.com>
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Permission to use, copy, modify, and distribute this software for any 8 * Permission to use, copy, modify, and distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above 9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies. 10 * copyright notice and this permission notice appear in all copies.
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 */ 19 */
20 20
21 #include "core.h" 21 #include "core.hpp"
22 22
23 Connection *C; 23 Connection *C;
24 24
25 Core::Core() 25 Core::Core():
26 :
27 pid(PID),
28 commander(COMMANDER) 26 commander(COMMANDER)
29 { 27 {
28 pid = PID;
29
30 cout << "CORE: initializing...\n"; 30 cout << "CORE: initializing...\n";
31 31
32 debug = true; 32 debug = true;
33 33
34 now = gettime(); 34 now = gettime();
44 for (int e = 0; e < servers; e++) 44 for (int e = 0; e < servers; e++)
45 delete connections[e]; 45 delete connections[e];
46 46
47 servers = 0; 47 servers = 0;
48 48
49 remove (pid); 49 remove(pid);
50 50
51 cout << "CORE: shutdown complete\n"; 51 cout << "CORE: shutdown complete\n";
52 } 52 }
53 53
54 void Core::commandParse(int argc, char *argv[]) 54 void Core::parseCommandLine(int argc, char **argv)
55 { 55 {
56 for (int e = 1; e < argc; e++) { 56 for (int e = 1; e < argc; e++) {
57 while (1) { 57 while (1) {
58 if (!strcmp(argv[e], "-c") || !strcmp(argv[e], "--config")) { 58 if (!strcmp(argv[e], "-c") || !strcmp(argv[e], "--config")) {
59 if (!argv[++e]) 59 if (!argv[++e])
60 shut ("missing configuration file"); 60 shut ("missing configuration file");
61 61
62 cfg = argv[e]; 62 config = argv[e];
63 break; 63 break;
64 } else if (!strcmp(argv[e], "-h") || !strcmp(argv[e], "--help")) {
65 showHelp();
64 } else if (!strcmp(argv[e], "-d") || !strcmp(argv[e], "--daemon")) { 66 } else if (!strcmp(argv[e], "-d") || !strcmp(argv[e], "--daemon")) {
65 debug = false; 67 debug = false;
66 break; 68 break;
67 } else 69 } else
68 shut ("unknown option detected: " + (string)argv[e]); 70 shut ("unknown option detected: " + (string)argv[e]);
69 } 71 }
70 } 72 }
71 } 73 }
72 74
73 void Core::configParse() 75 void Core::parseConfig()
74 { 76 {
75 servers = -1; 77 servers = -1;
76 78
77 C = 0; 79 C = false;
78 80
79 ifstream config(cfg, ios::in); 81 ifstream sysconfig(config, ios::in);
80 82
81 if (!config) 83 if (!sysconfig)
82 shut ("unable to open configuration file"); 84 shut ("unable to open configuration file");
83 else { 85 else {
84 cout << "CORE: parsing configuration file: " << cfg << endl; 86 cout << "CORE: parsing configuration file: " << config << endl;
85 87
86 if (servers + 1 < MAX_SERVERS) { 88 if (servers + 1 < MAX_SERVERS) {
87 connections[++servers] = new Connection(); 89 connections[++servers] = new Connection();
88 C = connections[servers]; 90 C = connections[servers];
89 } 91 }
90 else 92 else
91 cout << "Error: maximum connections exceed\n"; 93 cout << "Error: maximum connections exceed\n";
92 // TEST 94 // TEST
93 C->hosts = C->hostAdd (C->hosts, "irc.enqlave.net", 6667, 0); 95 C->hosts = C->addHost(C->hosts, "irc.enqlave.net", 6667, 0);
94 // TEST 96 // TEST
95 } 97 }
96 98
97 servers++; 99 servers++;
98 100
99 config.close(); 101 sysconfig.close();
100 } 102 }
101 103
102 void Core::pidCheck() 104 void Core::checkPID()
103 { 105 {
104 ifstream procid(pid, ios::in); 106 ifstream procid(pid, ios::in);
105 107
106 if (procid) { 108 if (procid) {
107 pid_t pids; 109 pid_t pids;
113 } 115 }
114 116
115 procid.close(); 117 procid.close();
116 } 118 }
117 119
118 void Core::pidWrite() 120 void Core::writePID()
119 { 121 {
120 ofstream procid(pid, ios::out); 122 ofstream procid(pid, ios::out);
121 123
122 if (procid) 124 if (procid)
123 procid << getpid() << endl; 125 procid << getpid() << endl;