-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_main.cpp
118 lines (95 loc) · 2.61 KB
/
server_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
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <getopt.h>
#include "producer.hpp"
#include "consumer.hpp"
#include "controller.hpp"
#include "dolphin-server.hpp"
#include "FileWriter.hpp"
#define NO_FLAGS 0
#define ADAPTER_NUM 0
DolphinServer *s;
FileWriter *f;
void shutdown(int i) {
s->shutdown();
delete s;
delete f;
exit(EXIT_SUCCESS);
}
int main(int argc, char **argv) {
int remote_node = -1;
char *output = NULL;
int opt = 0;
static struct option long_options[] = {
{"output", required_argument, 0, 'o' },
{"remote", required_argument, 0, 'r' },
{0, 0, 0, 0 }
};
int long_index =0;
while ((opt = getopt_long(argc, argv,"i:r:",
long_options, &long_index )) != -1) {
switch (opt) {
case 'o' : output = optarg;
break;
case 'r' : remote_node = atoi(optarg);
break;
default : fprintf(stderr, "Error parsing arguments!\n");
exit(EXIT_FAILURE);
}
}
if (remote_node == -1) {
fprintf(stderr, "You must specify a remote node!\n");
return EXIT_FAILURE;
}
if (output == NULL) {
fprintf(stderr, "You must specify an output file!\n");
return EXIT_FAILURE;
}
sci_error_t error;
uint32_t node_id;
/*
* Handle interrupts
*/
struct sigaction sigIntHandler;
sigIntHandler.sa_handler = shutdown;
sigemptyset(&sigIntHandler.sa_mask);
sigIntHandler.sa_flags = 0;
sigaction(SIGINT, &sigIntHandler, NULL);
// Open the file
FILE *out = fopen(output, "w");
// Check that the file is indeed open
if (out == NULL) {
fprintf(stderr, "Output is NULL\n");
return EXIT_FAILURE;
}
// TODO Remove
fclose(out);
/*
* Initialize dolphin
*/
// Initialize the dolphin library
SCIInitialize(NO_FLAGS, &error);
if (error != SCI_ERR_OK) {
fprintf(stderr,"SCIInitialize failed - Error code 0x%x\n",error);
return EXIT_FAILURE;
}
/* Get local nodeId */
SCIGetLocalNodeId(ADAPTER_NUM, &node_id, NO_FLAGS, &error);
if (error != SCI_ERR_OK) {
fprintf(stderr,"Could not find the local adapter %d\n", ADAPTER_NUM);
return EXIT_FAILURE;
}
fprintf(stderr, "Node_id: %d\n", node_id);
/*
* Run dolphin
*/
s = new DolphinServer(node_id, remote_node, BUFSIZE);
s->setup();
s->connect();
f = new FileWriter(output, s);
f->run();
delete f;
delete s;
return EXIT_FAILURE;
}