0 | 10 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,81 @@ |
1 |
+/* sapd: main.c */ |
|
2 |
+ |
|
3 |
+#include <stdio.h> |
|
4 |
+#include <stdlib.h> |
|
5 |
+#include <unistd.h> |
|
6 |
+#include <string.h> |
|
7 |
+#include <signal.h> |
|
8 |
+#include "sapmanager.h" |
|
9 |
+#include "sapbtlistener.h" |
|
10 |
+ |
|
11 |
+#include "capabilityagent.h" |
|
12 |
+#include "hostmanageragent.h" |
|
13 |
+ |
|
14 |
+static int signal_init(int signum, void (*fn)(int)); |
|
15 |
+static void sigint(int signum); |
|
16 |
+volatile int sigint_flag=0; |
|
17 |
+ |
|
18 |
+int main(int argc, char *argv[]) |
|
19 |
+{ |
|
20 |
+ sap_manager *manager; |
|
21 |
+ sap_listener *listener; |
|
22 |
+ capability_agent *agent; |
|
23 |
+ char *bt_address; |
|
24 |
+ |
|
25 |
+ if(argc!=2 || strcmp(argv[argc-1],"--help")==0) { |
|
26 |
+ printf("Syntax: %s bt_address\n",argv[0]); |
|
27 |
+ return(1); |
|
28 |
+ } |
|
29 |
+ |
|
30 |
+ if((manager=sap_manager_new())==NULL) { |
|
31 |
+ printf("ERROR: Couldn't initialize sap manager\n"); |
|
32 |
+ return(2); |
|
33 |
+ } |
|
34 |
+ |
|
35 |
+ if((agent=capability_agent_new(manager))==NULL) { |
|
36 |
+ printf("ERROR: Couldn't initialize sap capability agent\n"); |
|
37 |
+ sap_manager_free(manager),manager=NULL; |
|
38 |
+ return(3); |
|
39 |
+ } |
|
40 |
+ host_manager_agent_register_services(manager); |
|
41 |
+ |
|
42 |
+ if((listener=sap_listener_new())==NULL) { |
|
43 |
+ printf("ERROR: Couldn't initialize sap listener\n"); |
|
44 |
+ capability_agent_free(agent),agent=NULL; |
|
45 |
+ sap_manager_free(manager),manager=NULL; |
|
46 |
+ return(4); |
|
47 |
+ } |
|
48 |
+ |
|
49 |
+ bt_address=argv[1]; |
|
50 |
+ |
|
51 |
+ sap_listener_start(listener); |
|
52 |
+ sap_listener_nudge(listener,bt_address); |
|
53 |
+ |
|
54 |
+ sigint_flag=0; |
|
55 |
+ signal_init(SIGINT,sigint); |
|
56 |
+ while(!sigint_flag) { |
|
57 |
+ sap_manager_loop(manager,0); |
|
58 |
+ sap_listener_loop(listener,100); |
|
59 |
+ } |
|
60 |
+ sap_listener_free(listener),listener=NULL; |
|
61 |
+ capability_agent_free(agent),agent=NULL; |
|
62 |
+ sap_manager_free(manager),manager=NULL; |
|
63 |
+ return(0); |
|
64 |
+} |
|
65 |
+ |
|
66 |
+static int |
|
67 |
+signal_init(int signum, void (*fn)(int)) |
|
68 |
+{ |
|
69 |
+ struct sigaction sa; |
|
70 |
+ sa.sa_handler=fn; |
|
71 |
+ sigemptyset(&sa.sa_mask); |
|
72 |
+ sa.sa_flags=0; |
|
73 |
+ return(sigaction(signum,&sa,0)); |
|
74 |
+} |
|
75 |
+ |
|
76 |
+static void |
|
77 |
+sigint(int signum) |
|
78 |
+{ |
|
79 |
+ sigint_flag=1; |
|
80 |
+} |
|
81 |
+ |
0 | 82 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,23 @@ |
1 |
+#include <stdlib.h> |
|
2 |
+#include <string.h> |
|
3 |
+ |
|
4 |
+#include "sapchannelinfo.h" |
|
5 |
+ |
|
6 |
+sap_channelinfo * |
|
7 |
+sap_channelinfo_new() |
|
8 |
+{ |
|
9 |
+ sap_channelinfo *ci; |
|
10 |
+ if((ci=malloc(sizeof(sap_channelinfo)))==NULL) |
|
11 |
+ return(NULL); |
|
12 |
+ memset(ci,0,sizeof(sap_channelinfo)); |
|
13 |
+ return(ci); |
|
14 |
+} |
|
15 |
+ |
|
16 |
+void |
|
17 |
+sap_channelinfo_free(sap_channelinfo *ci) |
|
18 |
+{ |
|
19 |
+ if(ci==NULL) |
|
20 |
+ return; |
|
21 |
+ free(ci),ci=NULL; |
|
22 |
+} |
|
23 |
+ |
0 | 24 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,42 @@ |
1 |
+#ifndef SAPCHANNELINFO_H |
|
2 |
+#define SAPCHANNELINFO_H |
|
3 |
+ |
|
4 |
+typedef enum epayload_type { |
|
5 |
+ payload_none=0, |
|
6 |
+ payload_binary = 1, |
|
7 |
+ payload_json = 2, |
|
8 |
+ payload_all = 0xFF |
|
9 |
+} epayload_type; |
|
10 |
+ |
|
11 |
+typedef enum eqos_type { |
|
12 |
+ qos_unrestricted_in_order = 0, |
|
13 |
+ qos_unrestricted = 1, |
|
14 |
+ qos_restricted_in_order = 2, |
|
15 |
+ qos_restricted = 3, |
|
16 |
+ qos_reliability_disable = 4, |
|
17 |
+ qos_reliability_enable = 5 |
|
18 |
+} eqos_type; |
|
19 |
+ |
|
20 |
+typedef enum eqos_priority { |
|
21 |
+ qos_priority_low = 0, |
|
22 |
+ qos_priority_medium, |
|
23 |
+ qos_priority_high |
|
24 |
+} eqos_priority; |
|
25 |
+ |
|
26 |
+typedef enum eqos_data_rate { |
|
27 |
+ qos_data_rate_low = 0, |
|
28 |
+ qos_data_rate_high |
|
29 |
+} eqos_data_rate; |
|
30 |
+ |
|
31 |
+typedef struct sap_channelinfo { |
|
32 |
+ unsigned short id; |
|
33 |
+ epayload_type payload_type; |
|
34 |
+ eqos_type qos_type; |
|
35 |
+ eqos_priority qos_priority; |
|
36 |
+ eqos_data_rate qos_data_rate; |
|
37 |
+} sap_channelinfo; |
|
38 |
+ |
|
39 |
+sap_channelinfo *sap_channelinfo_new(); |
|
40 |
+void sap_channelinfo_free(sap_channelinfo *ci); |
|
41 |
+ |
|
42 |
+#endif |