fix a compile error with uclibc 0.9.32 and newer kernels
[openwrt.git] / package / tapi_sip / src / session.c
1 #include <stdlib.h>
2 #include <stdio.h>
3
4 #include "agent.h"
5 #include "session.h"
6
7 #include <tapi-device.h>
8
9
10 struct session
11 {
12 struct agent *agents[2];
13
14 struct tapi_device *tdev;
15
16 void (*release)(struct session *);
17
18 int link;
19 };
20
21 struct session *session_alloc(struct tapi_device *dev, struct agent *caller,
22 struct agent *callee, void (*release)(struct session *))
23 {
24 struct session *session;
25 int ret;
26
27 session = malloc(sizeof(*session));
28
29 session->tdev = dev;
30
31 session->agents[0] = caller;
32 session->agents[1] = callee;
33
34 ret = agent_invite(callee, session);
35 if (ret < 0) {
36 session_hangup(session, callee);
37 free(session);
38 return NULL;
39 }
40
41 session->release = release;
42
43 return session;
44 }
45
46 void session_accept(struct session *session, struct agent *agent)
47 {
48 int ep[2];
49
50 printf("session_accept: %p %p\n", session, agent);
51 printf("session agents: %p %p\n", session->agents[0], session->agents[1]);
52 printf("session tdev: %p\n", session->tdev);
53
54 agent_accept(session->agents[0], session);
55
56 ep[0] = agent_get_endpoint(session->agents[0], session);
57 ep[1] = agent_get_endpoint(session->agents[1], session);
58 session->link = tapi_link_alloc(session->tdev, ep[0], ep[1]);
59
60 printf("eps: %d %d\n", ep[0], ep[1]);
61
62 tapi_link_enable(session->tdev, session->link);
63
64 tapi_sync(session->tdev);
65 }
66
67 void session_hangup(struct session *session, struct agent *agent)
68 {
69 struct agent *other_agent;
70
71 if (session->agents[0] == agent)
72 other_agent = session->agents[1];
73 else
74 other_agent = session->agents[0];
75
76 agent_hangup(other_agent, session);
77
78 tapi_link_disable(session->tdev, session->link);
79 tapi_link_free(session->tdev, session->link);
80 tapi_sync(session->tdev);
81
82 if (session->release)
83 session->release(session);
84 }
This page took 0.071036 seconds and 5 git commands to generate.