Blame view

sip/SipServer.h 3.5 KB
c887a0f0   Hu Chunming   提交初成版代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  #ifndef __SIPSERVER_H__

  #define __SIPSERVER_H__

  

  extern "C" {

  #include <osip2/osip_mt.h>

  #include <eXosip2/eXosip.h>

  }

  

  #include <map>

  #include <string>

  #include <thread>

  #include <chrono>

  #include <mutex>

  #include <tuple>

  

  #include "./Message/CatalogParser.h"

  #include "sip_header.h"

  

  using namespace std;

  

  class Client {

  public:

      Client(string ip, int port, string device) :

e918c2a7   Hu Chunming   call release 自动重新...
24
25
26
27
              mIp(ip), mPort(port),  mDevice(device) 

      {

          mRtpPort = 0;

          mIsReg = false;

c887a0f0   Hu Chunming   提交初成版代码
28
      }

e918c2a7   Hu Chunming   call release 自动重新...
29
  

c887a0f0   Hu Chunming   提交初成版代码
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
      ~Client() = default;

  public:

  

      void setRtpPort(int rtpPort) {

          mRtpPort = rtpPort;

      }

  

      void setReg(bool isReg) {

          mIsReg = isReg;

      }

      string  getDevice() const{

          return mDevice;

      }

      string  getIp() const{

          return mIp;

      }

      int getPort() const{

          return mPort;

      }

  

      unsigned long getHeartBeat() {

          return mHeartBeatTime;

      }

  

      void updateHeartBeat(unsigned long ts) {

          mHeartBeatTime = ts;

      }

  

10821ac3   Hu Chunming   1.定时刷新设备目录;
58
59
60
61
62
63
64
65
      long getExpiry() {

          return mExipry;

      }

  

      void setExpiry(long expiry) {

          mExipry = expiry;

      }

  

c887a0f0   Hu Chunming   提交初成版代码
66
67
68
69
70
71
72
  private:

      string mIp; // client ip

      int mPort; // client port

      string mDevice;// 340200000013200000024

      bool mIsReg;

      int mRtpPort;

      unsigned long mHeartBeatTime{0};

10821ac3   Hu Chunming   1.定时刷新设备目录;
73
      long mExipry{0};

c887a0f0   Hu Chunming   提交初成版代码
74
75
76
  };

  

  

e918c2a7   Hu Chunming   call release 自动重新...
77
78
  class WebSocketServer;

  

c887a0f0   Hu Chunming   提交初成版代码
79
80
81
82
83
  class SipServer {

  public:

      SipServer();

      ~SipServer();

  

e918c2a7   Hu Chunming   call release 自动重新...
84
      bool Init(ServerInfo* pInfo, WebSocketServer* pServer);

c887a0f0   Hu Chunming   提交初成版代码
85
86
87
  

      int RequestInvite_UDP(const char* dst_channel, const char* rtpIp, int rtpPort);

  

e918c2a7   Hu Chunming   call release 自动重新...
88
      int RequestInvite_TCP_a(const char* dst_channel, const char* rtpIp, int rtpPort);

c887a0f0   Hu Chunming   提交初成版代码
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
  

      int ByeInvite(std::string channel_id, string ip, int rtpPort);

  

      void Close();

  

  public:

      void event_loop();

      void timing_getcatlog();

  

  private:

      int init_sip_server();

      int sip_event_handle(eXosip_event_t *evtp);

  

      void RequestCatalog(Client* client);

      void cacheCatalog();

  

10821ac3   Hu Chunming   1.定时刷新设备目录;
105
      void cacheClient(osip_uri_t *url, int expiry);

73ef4ff3   Hu Chunming   提交三方库
106
  

c887a0f0   Hu Chunming   提交初成版代码
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
      void response_message_answer(eXosip_event_t *evtp,int code);

      void response_register(eXosip_event_t *evtp);

      void response_register_401unauthorized(eXosip_event_t *evt);

      void response_message(eXosip_event_t *evtp);

      void response_invite_ack(eXosip_event_t *evtp);

      int request_bye(eXosip_event_t* evtp);// 通知相机停止推流

      int parse_xml(const char* data, const char* s_mark, bool with_s_make, const char* e_mark, bool with_e_make, char* dest);

      void dump_request(eXosip_event_t *evtp);

      void dump_response(eXosip_event_t *evtp);

  

      int clearClientMap();

      void deleteClientByDevice(string device);

  

      Client* get_parent_by_id(string id);

      bool check_device_status(string id);

  

      void cache_invite_callinfo(eXosip_event_t *evtp);

  

e918c2a7   Hu Chunming   call release 自动重新...
125
126
127
128
      int reInvite(int cid);

  

      int inviteFailedResponse(int cid);

  

c887a0f0   Hu Chunming   提交初成版代码
129
130
131
132
133
134
135
136
137
138
139
140
  private:

      bool mQuit{ false };

      eXosip_t *mSipCtx;

      ServerInfo mInfo;

  

      std::map<std::string, Client *> mClientMap;// <DeviceID,SipClient>

      mutex m_client_map_mtx;

      std::map<std::string, DeviceInfo> m_device_map;

      mutex m_device_map_mtx;

  

      thread* m_event_loop_thread{nullptr};

  

e918c2a7   Hu Chunming   call release 自动重新...
141
      mutex m_invite_callinfo_map_mtx;

c887a0f0   Hu Chunming   提交初成版代码
142
      std::map< tuple<std::string, std::string, int>, CallInfo> m_invite_callinfo_map;

e918c2a7   Hu Chunming   call release 自动重新...
143
144
145
146
      mutex m_invite_cmd_map_mtx;

      std::map< tuple<std::string, std::string, int>, string> m_invite_cmd_map;

  

      WebSocketServer* m_pWsServer;

c887a0f0   Hu Chunming   提交初成版代码
147
148
149
150
  };

  

  

  #endif //__SIPSERVER_H__