-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathswm_zyre.c
93 lines (74 loc) · 2.49 KB
/
swm_zyre.c
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
/**
* Example on how the send RSG-JSON messages via zyre.
* It uses the swmzyre library as helper.
*/
#include <zyre.h>
#include <jansson.h>
#include <uuid/uuid.h>
#include <string.h>
#include "swmzyre.h"
int main(int argc, char *argv[]) {
/* Load configuration file for communication setup */
char config_folder[255] = { SWM_ZYRE_CONFIG_DIR };
char config_name[] = "swm_zyre_config.json";
char config_file[512] = {0};
snprintf(config_file, sizeof(config_file), "%s/%s", config_folder, config_name);
if (argc == 1) {
printf("To few argumnets. Pleas use swm_zyre ./swm_zyre <path_to_json_file> [<path_to_config_file>]\n");
return -1;
} else if (argc == 3) { // override default config
snprintf(config_file, sizeof(config_file), "%s", argv[2]);
}
json_t * config = load_config_file(&config_file);//"swm_zyre_config.json");
if (config == NULL) {
return -1;
}
/* Spawn new communication component */
component_t *self = new_component(config);
if (self == NULL) {
return -1;
}
printf("[%s] component initialized!\n", self->name);
/* Query as specified by a file */
printf("\n");
printf("#########################################\n");
printf("[%s] Sending Generic Query\n",self->name);
printf("#########################################\n");
printf("\n");
char *msg;
msg = encode_json_message_from_file(self, argv[1]);
// if (argc == 2) {
//
// /* Query as specified by a file */
// printf("\n");
// printf("#########################################\n");
// printf("[%s] Sending Generic Query\n",self->name);
// printf("#########################################\n");
// printf("\n");
//
// msg = encode_json_message_from_file(self, argv[1]);
//
// } else {
//
// /* Query for root node */
// printf("\n");
// printf("#########################################\n");
// printf("[%s] Sending Query for RSG Root Node\n",self->name);
// printf("#########################################\n");
// printf("\n");
//
// json_t* query_params = NULL;
// msg = send_query(self,"GET_ROOT_NODE",query_params);
// }
/* Send the message */
shout_message(self, msg);
/* Wait for a reply */
char* reply = wait_for_reply(self, msg, self->timeout);
/* Print reply */
printf("#########################################\n");
printf("[%s] Got reply: %s \n", self->name, reply);
/* Clean up */
destroy_component(&self);
printf ("SHUTDOWN\n");
return 0;
}