8 #include "tapi_agent.h"
10 static int tapi_agent_invite(struct agent
*agent
, struct session
*session
)
12 struct tapi_agent
*tagent
= agent_to_tapi_agent(agent
);
17 tagent
->state
= TAPI_AGENT_STATE_RINGING
;
18 tapi_port_set_ring(&tagent
->port
, true);
20 tagent
->session
= session
;
25 static int tapi_agent_accept(struct agent
*agent
, struct session
*session
)
30 static int tapi_agent_hangup(struct agent
*agent
, struct session
*session
)
32 struct tapi_agent
*tagent
= agent_to_tapi_agent(agent
);
34 switch (tagent
->state
) {
35 case TAPI_AGENT_STATE_RINGING
:
36 tapi_port_set_ring(&tagent
->port
, false);
42 tagent
->state
= TAPI_AGENT_STATE_IDLE
;
43 tagent
->session
= NULL
;
48 static int tapi_agent_get_endpoint(struct agent
*agent
, struct session
*session
)
50 struct tapi_agent
*tagent
= agent_to_tapi_agent(agent
);
51 return tapi_port_get_endpoint(&tagent
->port
);
54 static const struct agent_ops tapi_agent_ops
= {
55 .invite
= tapi_agent_invite
,
56 .accept
= tapi_agent_accept
,
57 .hangup
= tapi_agent_hangup
,
58 .get_endpoint
= tapi_agent_get_endpoint
,
61 static void tapi_agent_event(struct tapi_port
*port
, struct tapi_event
*event
,
64 struct tapi_agent
*tagent
= data
;
66 if (event
->type
!= TAPI_EVENT_TYPE_HOOK
)
73 session_hangup(tagent
->session
, &tagent
->agent
);
74 tagent
->state
= TAPI_AGENT_STATE_IDLE
;
75 tagent
->session
= NULL
;
77 session_accept(tagent
->session
, &tagent
->agent
);
78 tagent
->state
= TAPI_AGENT_STATE_ACTIVE
;
82 void tapi_agent_init(struct tapi_device
*tdev
, int port
, struct tapi_agent
*tagent
)
86 tagent
->agent
.ops
= &tapi_agent_ops
;
87 tagent
->state
= TAPI_AGENT_STATE_IDLE
;
88 tagent
->session
= NULL
;
90 ret
= tapi_port_open(tdev
, port
, &tagent
->port
);
92 printf("Failed to open tapi port %d: %d\n", port
, ret
);
96 tagent
->event_listener
.callback
= tapi_agent_event
;
97 tagent
->event_listener
.data
= tagent
;
99 tapi_port_register_event(&tagent
->port
, &tagent
->event_listener
);
102 void tapi_agent_free(struct tapi_agent
*tagent
)
104 tapi_port_unregister_event(&tagent
->port
, &tagent
->event_listener
);
This page took 0.054797 seconds and 5 git commands to generate.