-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathSipClientAgentManager.cpp
126 lines (109 loc) · 3.21 KB
/
SipClientAgentManager.cpp
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
#include "SipClientAgentManager.h"
CSipClientAgentManager *CSipClientAgentManager::sipagent_manager_instance_ = NULL;
CSipClientAgentManager::CSipClientAgentManager(void)
{
}
CSipClientAgentManager::~CSipClientAgentManager(void)
{
}
CSipClientAgentManager* CSipClientAgentManager::getinstance()
{
if(sipagent_manager_instance_ == NULL)
{
sipagent_manager_instance_ = new CSipClientAgentManager();
}
return sipagent_manager_instance_;
}
void CSipClientAgentManager::set_sipproxy(string &id)
{
sipproxyid_ = id;
}
void CSipClientAgentManager::set_sipsms(string &id)
{
sipsmsid_ = id;
}
string CSipClientAgentManager::sipproxyid()
{
return sipproxyid_;
}
string CSipClientAgentManager::sipsmsid()
{
return sipsmsid_;
}
int CSipClientAgentManager::bind_sipagent(string id,CSipClientApent *agent,int issms)
{
ACE_Guard<ACE_Recursive_Thread_Mutex> locker(sipagent_lock_);
if(issms)
{
map<string,CSipClientApent*>::iterator iter = sipagent_sms_map_.find(id);
if( iter != sipagent_sms_map_.end() )
{
APTS_LOGMSG((LM_INFO,"(%t)%D [GB28181ServerTask] Á÷ýÌå×¢²áusrname³åÍ»:%s\n",id.c_str()));
delete agent;
agent = NULL;
return -1;
}
sipagent_sms_map_.insert(pair<string,CSipClientApent*>(id,agent));
APTS_LOGMSG((LM_INFO,"(%t)%D [GB28181ServerTask] Á÷ýÌå×¢²áfrom:%s@%s:%d,%s\n",agent->id().c_str(),agent->ip().c_str(),agent->port(),agent->name().c_str()));
}
else
{
map<string,CSipClientApent*>::iterator iter = sipagent_map_.find(id);
if( iter != sipagent_map_.end() )
{
APTS_LOGMSG((LM_INFO,"(%t)%D [GB28181ServerTask] ×¢²áusrname³åÍ»:%s\n",id.c_str()));
delete agent;
agent = NULL;
return -1;
}
sipagent_map_.insert(pair<string,CSipClientApent*>(id,agent));
APTS_LOGMSG((LM_INFO,"(%t)%D [GB28181ServerTask] ×¢²áfrom:%s@%s:%d,%s\n",agent->id().c_str(),agent->ip().c_str(),agent->port(),agent->name().c_str()));
}
return 0;
}
int CSipClientAgentManager::unbind_sipagnet(string id)
{
ACE_Guard<ACE_Recursive_Thread_Mutex> locker(sipagent_lock_);
map<string,CSipClientApent*>::iterator iter = sipagent_map_.find(id);
if( iter != sipagent_map_.end() )
{
delete iter->second;
iter->second = NULL;
sipagent_map_.erase(iter);
}
else
{
//return -1;
map<string,CSipClientApent*>::iterator itersms = sipagent_sms_map_.find(id);
if(itersms!=sipagent_sms_map_.end())
{
delete itersms->second;
itersms->second = NULL;
sipagent_sms_map_.erase(itersms);
}
}
return 0;
}
CSipClientApent * CSipClientAgentManager::get_sipagent(string id,int issms)
{
ACE_Guard<ACE_Recursive_Thread_Mutex> locker(sipagent_lock_);
map<string,CSipClientApent*>::iterator iter = sipagent_sms_map_.find(id);
if( iter != sipagent_sms_map_.end() )
{
return iter->second;
}
else
{
map<string,CSipClientApent*>::iterator iter2 = sipagent_map_.find(id);
if( iter2 != sipagent_map_.end() )
{
return iter2->second;
}
}
return NULL;
}
void CSipClientAgentManager::get_sipagent(map<string,CSipClientApent*> &sipagentmap)
{
ACE_Guard<ACE_Recursive_Thread_Mutex> locker(sipagent_lock_);
sipagentmap.insert(sipagent_map_.begin(),sipagent_map_.end());
}