]> git.stg.codes - stg.git/blob - projects/sgauthstress/main.cpp
Compilation issues fixed
[stg.git] / projects / sgauthstress / main.cpp
1 /*
2  *    This program is free software; you can redistribute it and/or modify
3  *    it under the terms of the GNU General Public License as published by
4  *    the Free Software Foundation; either version 2 of the License, or
5  *    (at your option) any later version.
6  *
7  *    This program is distributed in the hope that it will be useful,
8  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
9  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  *    GNU General Public License for more details.
11  *
12  *    You should have received a copy of the GNU General Public License
13  *    along with this program; if not, write to the Free Software
14  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15  */
16
17 /*
18  *    Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
19  */
20
21  /*
22  $Revision: 1.13 $
23  $Date: 2010/04/14 09:01:29 $
24  $Author: faust $
25  */
26
27 #include <unistd.h>
28
29 #include <csignal>
30 #include <iostream>
31
32 #include "stg/ia.h"
33 #include "stg/common.h"
34
35 #include "settings.h"
36
37 time_t stgTime;
38 bool running;
39
40 //-----------------------------------------------------------------------------
41 //-----------------------------------------------------------------------------
42 //-----------------------------------------------------------------------------
43 void Usage()
44 {
45 std::cout << "sgauth <path_to_config>" << std::endl;
46 }
47 //-----------------------------------------------------------------------------
48 void StatUpdate(const LOADSTAT &, void *)
49 {
50 }
51 //-----------------------------------------------------------------------------
52 void StatusChanged(int, void *)
53 {
54 }
55 //-----------------------------------------------------------------------------
56 void ShowMessage(const string &, int, int, int, void *)
57 {
58 }
59 //-----------------------------------------------------------------------------
60 void ShowError(const string &, int, void *)
61 {
62 }
63 //-----------------------------------------------------------------------------
64 void CatchTERM(int)
65 {
66 running = false;
67 }
68 //-----------------------------------------------------------------------------
69 static void SetSignalHandlers()
70 {
71 struct sigaction newsa, oldsa;
72 sigset_t sigmask;
73
74 sigemptyset(&sigmask);
75 sigaddset(&sigmask, SIGTERM);
76 newsa.sa_handler = CatchTERM;
77 newsa.sa_mask = sigmask;
78 newsa.sa_flags = 0;
79 sigaction(SIGTERM, &newsa, &oldsa);
80
81 sigemptyset(&sigmask);
82 sigaddset(&sigmask, SIGINT);
83 newsa.sa_handler = CatchTERM;
84 newsa.sa_mask = sigmask;
85 newsa.sa_flags = 0;
86 sigaction(SIGINT, &newsa, &oldsa);
87
88 return;
89 }
90 //-----------------------------------------------------------------------------
91 int main(int argc, char *argv[])
92 {
93 SETTINGS settings;
94
95 if (argc == 2)
96     {
97     settings.SetConfFile(argv[1]);
98     }
99
100 if (settings.ReadSettings())
101     {
102     std::cerr << "Failed to read settings\n"
103               << settings.GetStrError() << std::endl;
104     Usage();
105     return -1;
106     }
107
108 SetSignalHandlers();
109
110 IA_CLIENT_PROT proto(settings.GetServerName(), settings.GetServerPort(), settings.GetLocalPort());
111
112 proto.SetLogin(settings.GetLogin());
113 proto.SetPassword(settings.GetPassword());
114
115 proto.SetStatusChangedCb(StatusChanged, NULL);
116 proto.SetInfoCb(ShowMessage, NULL);
117 proto.SetErrorCb(ShowError, NULL);
118 proto.SetStatChangedCb(StatUpdate, NULL);
119
120 proto.Start();
121
122 proto.Connect();
123
124 running = true;
125 while (running)
126     {
127     usleep(200000);
128     }
129
130 proto.Disconnect();
131
132 proto.Stop();
133
134 return 0;
135 }
136 //-----------------------------------------------------------------------------