-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
160 lines (135 loc) · 4.02 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include <Wt/WBootstrapTheme.h>
#include "waverider.h"
#include "wradio-controller.h"
#include "radio-server.h"
#include "cstreamingserver.h"
#include "string.h"
#include "tool.h"
using namespace std;
using namespace Wt;
typedef struct
{
string type;
string message;
} start_logger;
unique_ptr<WApplication> createApplication(const WEnvironment& env, CRadioServer& server)
{
auto app = make_unique<WaveriderApplication>(env, server);
auto theme = std::make_shared<Wt::WBootstrapTheme>();
theme->setVersion(Wt::BootstrapVersion::v3);
app->setTheme(theme);
//cout << "Approot: " << WApplication::appRoot() << endl;
//app->messageResourceBundle().use(WApplication::appRoot()+"/forms/settings");
return app;
}
void logging(string type, string message, list<start_logger*>& logger)
{
start_logger *newlog_entry = new start_logger;
newlog_entry->type = type;
newlog_entry->message = message;
logger.push_back(newlog_entry);
}
int main(int argc, char **argv)
{
// Standard Wt Application
/* return Wt::WRun(argc, argv, [](const Wt::WEnvironment& env) {
return std::make_unique<WaveriderApplication>(env);
}); */
list<start_logger*> logger;
// Levinstein, Russian Language Tools and so on ...
init_tools();
// Parse argv for http-listen
// --approot=../approot --docroot=../docroot --http-listen 0.0.0.0:9090
// Find out the port for http-listen
char new_argv[255][255];
int new_argc = 0;
for (int i=0; i < argc; i++)
{
logging("notice", "[main] Starting Server with arguments: " + string(argv[i]), logger);
if (strcmp("--http-listen", argv[i]) == 0)
{
strcpy(new_argv[new_argc], argv[i]);
new_argc++;
// read IP and Port
char address[255];
char ip_address[255];
char port[255];
strcpy(address, argv[i+1]);
int init_size = strlen(address);
char delim[] = ":";
char *ptr = strtok(address, delim);
int count = 0;
while(ptr != NULL)
{
if (count == 0)
{
strcpy(ip_address, ptr);
count++;
}
else if (count == 1)
{
strcpy(port, ptr);
count++;
}
//printf("'%s'\n", ptr);
ptr = strtok(NULL, delim);
}
//cout << "IP-Address Server:" << ip_address << endl;
//cout << "Port Server:" << port << endl;
//Port for Streamingserver is always webservice port + 1
int new_port = atoi(port)+1;
char new_port_str[255];
sprintf(new_port_str, "%d", new_port);
strcpy(address, ip_address);
strcat(address, ":");
strcat(address, new_port_str);
strcpy(new_argv[new_argc], address);
new_argc++;
break;
}
else
{
strcpy(new_argv[i],argv[i]);
new_argc++;
}
}
// Test for additional settings
char *n_argv[new_argc];
for (int i=0; i<new_argc; i++)
{
n_argv[i] = new_argv[i];
}
/** for (int i=0; i<new_argc; i++)
{
cout << "New Argumente: " << n_argv[i] << endl;
} */
// Internet Radio Server
CStreamingServer streamingServer(new_argc, n_argv, WTHTTP_CONFIGURATION);
// DAB+ Radio Server
CRadioServer radioServer(argc, argv, WTHTTP_CONFIGURATION, &streamingServer);
for (list<start_logger*>::iterator it = logger.begin(); it != logger.end(); ++it)
{
start_logger* s = *it;
radioServer.log(s->type, s->message);
}
radioServer.addEntryPoint(EntryPointType::Application, bind(createApplication, placeholders::_1, ref(radioServer)));
// auch der Streaming-Server schickt die dekodierten Frames an den RadioController (onNewAudio)
streamingServer.setRadioController(radioServer.getRadioController());
streamingServer.setLogger(radioServer.logger());
streamingServer.start();
if (radioServer.start())
{
//int sig = WServer::waitForShutdown();
try
{
int sig = radioServer.waitForShutdown();
cerr << "sig" << " : Signal returned" << endl;
}
catch (WServer::Exception e)
{
cerr << e.what() << endl;
}
//streamingServer.stop();
//radioServer.stop();
}
}