summaryrefslogtreecommitdiffstats
path: root/tinySIP/src/tsip_event.c
blob: 83cc165e384d689c061f1136732acd0d2688665f (plain)
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
*	
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*	
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*	
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
*/

/**@file tsip_event.c
 * @brief SIP event.
 *
 * @author Mamadou Diop <diopmamadou(at)doubango[dot]org>
 *

 */
#include "tinysip/tsip_event.h"

#include "tsip.h"

#include "tinysip/tsip_message.h"

#include "tsk_string.h"
#include "tsk_memory.h"
#include "tsk_debug.h"

/* internal function used to create base SIP event */
tsip_event_t* tsip_event_create(tsip_ssession_t* ss, short code, const char* phrase, const tsip_message_t* sipmessage, tsip_event_type_t type)
{
	tsip_event_t* e;
	if((e = tsk_object_new(tsip_event_def_t, ss, code, phrase, sipmessage, type))){
		tsip_event_init(e, ss, code, phrase, sipmessage, type);
	}
	return e;
}

/* initialize a sip sevent */
int tsip_event_init(tsip_event_t* self, tsip_ssession_t *ss, short code, const char *phrase, const tsip_message_t* sipmessage, tsip_event_type_t type)
{
	if(!self){
		TSK_DEBUG_ERROR("Invalid parameter");
		return -1;
	}

	self->ss = tsk_object_ref(ss);
	self->code = code;
	tsk_strupdate(&(self->phrase), phrase);
	self->type = type;
	if(sipmessage){
		self->sipmessage = tsk_object_ref((void*)sipmessage);
	}
	return 0;
}

/* signal new event (enqueue) */
int tsip_event_signal(tsip_event_type_t type, tsip_ssession_t* ss, short code, const char *phrase)
{
	return tsip_event_signal_2(type, ss, code, phrase, tsk_null);
}

int tsip_event_signal_2(tsip_event_type_t type, tsip_ssession_t* ss, short code, const char *phrase, const struct tsip_message_s* sipmessage)
{
	tsip_event_t* e;
	if((e = tsip_event_create(ss, code, phrase, sipmessage, type))){
		TSK_RUNNABLE_ENQUEUE_OBJECT_SAFE(TSK_RUNNABLE(ss->stack), e);
		return 0;
	}
	return -1;
}

int tsip_event_deinit(tsip_event_t* self)
{
	if(self){
		TSK_OBJECT_SAFE_FREE(self->ss);

		TSK_FREE(self->phrase);
		TSK_OBJECT_SAFE_FREE(self->sipmessage);
		
		return 0;
	}
	return -1;
}














//========================================================
//	SIP event object definition
//
static tsk_object_t* tsip_event_ctor(tsk_object_t * self, va_list * app)
{
	tsip_event_t *sipevent = self;
	if(sipevent){
//		const tsip_message_t* sipmessage;
//		tsip_stack_t *stack;
//		tsip_ssession_handle_t *SSESSION;
//		short code;
//		const char *phrase;
//		tsip_event_type_t type;
//		
//		stack = va_arg(*app, tsip_stack_handle_t *);
//		SSESSION = va_arg(*app, tsip_ssession_handle_t*);
//
//#if defined(__GNUC__)
//		code = (short)va_arg(*app, int);
//#else
//		code = va_arg(*app, short);
//#endif
//		phrase = va_arg(*app, const char *);
//		
//		sipmessage = va_arg(*app, const tsip_message_t*);
//		type = va_arg(*app, tsip_event_type_t);
//		
//		tsip_event_init(self, stack, SSESSION, code, phrase, sipmessage, type);
	}
	return self;
}

static tsk_object_t* tsip_event_dtor(tsk_object_t * self)
{ 
	tsip_event_t *sipevent = self;
	if(sipevent){
		tsip_event_deinit(sipevent);
	}
	return self;
}

static int tsip_event_cmp(const tsk_object_t *obj1, const tsk_object_t *obj2)
{
	return -1;
}

static const tsk_object_def_t tsip_event_def_s = 
{
	sizeof(tsip_event_t),
	tsip_event_ctor, 
	tsip_event_dtor,
	tsip_event_cmp, 
};
const tsk_object_def_t *tsip_event_def_t = &tsip_event_def_s;
OpenPOWER on IntegriCloud