|
36e5dcd7
»
|
dieb |
2009-05-06 |
Initial commit for the proj... |
1 |
#include <errno.h> |
| |
2 |
#include <signal.h> |
| |
3 |
#include <sys/types.h> |
| |
4 |
|
| |
5 |
#include <Eina.h> |
| |
6 |
#include <eupnp.h> |
|
351f02d6
»
|
dieb |
2009-06-01 |
Implemented Event Bus modul... |
7 |
#include <eupnp_error.h> |
|
36e5dcd7
»
|
dieb |
2009-05-06 |
Initial commit for the proj... |
8 |
#include <eupnp_ssdp.h> |
| |
9 |
#include <eupnp_control_point.h> |
|
351f02d6
»
|
dieb |
2009-06-01 |
Implemented Event Bus modul... |
10 |
#include <eupnp_event_bus.h> |
|
36e5dcd7
»
|
dieb |
2009-05-06 |
Initial commit for the proj... |
11 |
|
| |
12 |
int sock; |
| |
13 |
int exit_req = 0; |
| |
14 |
|
| |
15 |
void terminate(int p) |
| |
16 |
{ |
| |
17 |
exit_req = 1; |
| |
18 |
} |
| |
19 |
|
|
351f02d6
»
|
dieb |
2009-06-01 |
Implemented Event Bus modul... |
20 |
Eina_Bool on_device_found(Eupnp_Event *e) |
| |
21 |
{ |
| |
22 |
INFO("Received event type %d\n", e->type); |
| |
23 |
return EINA_TRUE; |
| |
24 |
} |
| |
25 |
|
| |
26 |
Eina_Bool on_device_gone_singleshot(Eupnp_Event *e) |
| |
27 |
{ |
| |
28 |
INFO("Received event type %d\n", e->type); |
| |
29 |
INFO("Returning FALSE to remove the subscription..\n"); |
| |
30 |
return EINA_FALSE; |
| |
31 |
} |
| |
32 |
|
|
36e5dcd7
»
|
dieb |
2009-05-06 |
Initial commit for the proj... |
33 |
/* |
| |
34 |
* Sends a test search and listens for datagrams. Tests MSearch and SSDP |
| |
35 |
* server. |
| |
36 |
* |
| |
37 |
* Run with "EINA_ERROR_LEVEL=3 ./eupnp_basic_control_point" for watching debug |
| |
38 |
* messages. |
| |
39 |
*/ |
| |
40 |
int main(void) |
| |
41 |
{ |
| |
42 |
signal(SIGTERM, terminate); |
| |
43 |
signal(SIGINT, terminate); |
| |
44 |
eupnp_init(); |
| |
45 |
|
| |
46 |
int ret; |
| |
47 |
fd_set r, w, ex; |
| |
48 |
Eupnp_Control_Point *c; |
| |
49 |
|
| |
50 |
c = eupnp_control_point_new(); |
| |
51 |
|
| |
52 |
if (!c) |
| |
53 |
{ |
| |
54 |
eupnp_shutdown(); |
| |
55 |
return -1; |
| |
56 |
} |
| |
57 |
|
|
351f02d6
»
|
dieb |
2009-06-01 |
Implemented Event Bus modul... |
58 |
eupnp_event_bus_subscribe(EUPNP_EVENT_DEVICE_FOUND, |
| |
59 |
EUPNP_CALLBACK(on_device_found)); |
| |
60 |
eupnp_event_bus_subscribe(EUPNP_EVENT_DEVICE_GONE, |
| |
61 |
EUPNP_CALLBACK(on_device_gone_singleshot)); |
| |
62 |
|
|
36e5dcd7
»
|
dieb |
2009-05-06 |
Initial commit for the proj... |
63 |
/* Send a test search */ |
| |
64 |
if (!eupnp_control_point_discovery_request_send(c, 5, "ssdp:all")) |
| |
65 |
{ |
| |
66 |
EINA_ERROR_PWARN("Failed to perform MSearch.\n"); |
| |
67 |
} |
| |
68 |
else |
| |
69 |
EINA_ERROR_PDBG("MSearch sent sucessfully.\n"); |
| |
70 |
|
|
4e4faa62
»
|
dieb |
2009-05-31 |
Fixed composition attribute... |
71 |
sock = eupnp_control_point_ssdp_socket_get(c); |
|
36e5dcd7
»
|
dieb |
2009-05-06 |
Initial commit for the proj... |
72 |
|
| |
73 |
while (!exit_req) |
| |
74 |
{ |
| |
75 |
FD_ZERO(&r); |
| |
76 |
FD_ZERO(&w); |
| |
77 |
FD_ZERO(&ex); |
| |
78 |
FD_SET(sock, &r); |
| |
79 |
ret = select(sock+1, &r, NULL, NULL, NULL); |
| |
80 |
|
| |
81 |
if (ret < 0) |
| |
82 |
{ |
| |
83 |
perror("Select error"); |
| |
84 |
break; |
| |
85 |
} |
| |
86 |
|
| |
87 |
if (exit_req) |
| |
88 |
break; |
| |
89 |
|
| |
90 |
if (FD_ISSET(sock, &r)) |
| |
91 |
{ |
| |
92 |
/* This is the event handler that will be added to the event loop. |
| |
93 |
* For example, when integrating eupnp+ecore, this socket will |
| |
94 |
* internally be added with ecore_fd_handler_add and the handler |
| |
95 |
* passed will be a wrapper of _eupnp_ssdp_on_datagram_available. |
| |
96 |
*/ |
| |
97 |
_eupnp_ssdp_on_datagram_available(c->ssdp_server); |
| |
98 |
} |
| |
99 |
} |
| |
100 |
|
| |
101 |
eupnp_control_point_free(c); |
| |
102 |
eupnp_shutdown(); |
| |
103 |
return 0; |
| |
104 |
} |