-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsteam_interface.c
104 lines (79 loc) · 2.62 KB
/
steam_interface.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
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "steam_interface.h"
void my_adapt(proximity* changed_prox){
printf("Adaptation receieved at Local app\n");
}
void receive_my_event(event* ev){
gettimeofday(&tv, 0);
fprintf(recv_logger, "%s => %d.%d\n", ev->cont, tv.tv_sec, tv.tv_usec);
printf("CALLBACK AT LOCAL APP received event \n\tsubject - %s\n\t content %s\n", ev->sub, ev->cont);
}
int setup_steam(){
send_logger = fopen("send-times", "w+");
recv_logger = fopen("recv-times", "w+");
my_location.lat = LOCATION_X;
my_location.lon = LOCATION_Y;
if(init_rte_subscribe()<0){
printf("init subscribe failed.. you probably need to change the default address in dummy-sear-impl.h \n");
exit(0);
return -1;
}
if(init_rte_publish() <0){
printf("init-rte failed. we are doomed\n");
exit(0);
return -1;
}
printf("init_rte.. done\n");
}
/* returns a channel id for the channel we've announced to */
int setup_event(char* steam_subject,prox_type proximity,event* my_ev ){
channel_id c_id;
// square
my_proximity = alloc_proximity();
my_proximity->proximity_hull.type = proximity;
// non-rt latency
lat.min = 0; lat.max = 0;
//period is in milliseconds
per = 1000;
//my_event_subject = alloc_subject(100);
my_ev -> sub = alloc_subject(100);
strcpy(my_ev->sub, steam_subject);
printf("calling announce.. %s\n", my_ev->sub);
if((c_id= announce(my_ev->sub, my_proximity, lat, per, my_adapt)) == 0){
printf("Announcement went arse ways\n");
free(my_proximity);
return -1;
}
printf("announce.. done\n");
printf("steam init done \n");
free(my_proximity);
return c_id;
}
/* returns a subscription_id for the channel we've subscribed to.
takes a pointer to an event that we want to initalise. We'll use it later to send to
*/
int subscribe_to_event(char* sub, event* ev,void (*rt)(event*)){
char* my_event_subject = malloc(100);
subscription_id sub_id;
strcpy(my_event_subject,sub);
ev->sub = my_event_subject;
printf("init rte ... done\n");
if((sub_id = subscribe(my_event_subject, rt)) == 0){
printf("subscription failed\n");
return -1;
}
printf("init subscribe ... done\n");
free(my_event_subject);
return sub_id;
}
void send_my_event(char* content,channel_id my_channel,event* my_ev){
//fill in event
my_ev->cont = (char*)alloc_content(200);
strcpy(my_ev->cont, content);
// gettimeofday(&tv, 0);
// fprintf(send_logger, "%s => %d.%d\n", my_ev->cont, tv.tv_sec, tv.tv_usec);
if(send_event(my_channel, my_ev) <0){
printf("send failed \n");
exit(1);
}
free(my_ev->cont); // probably should be freeing this up
}