summaryrefslogtreecommitdiff
path: root/pjsip-apps/src/pjsua/winrt/gui/uwp/VoipBackEnd/MyApp.h
blob: 9f60680cfbf7bf442a85a7dca7c5699c6c5894fd (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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/* $Id*/
/*
* Copyright (C) 2016 Teluu Inc. (http://www.teluu.com)
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#pragma once
#include <pjsua2.hpp>
#include <collection.h>

namespace VoipBackEnd
{
    typedef int TransportId;

    typedef Platform::Collections::Vector<Platform::String^> StringVector;
    typedef Windows::Foundation::Collections::IVector<Platform::String^> 
	IStringVector;

    typedef public enum class INV_STATE
    {
	PJSIP_INV_STATE_NULL,	      /**< Before INVITE is sent or received */
	PJSIP_INV_STATE_CALLING,      /**< After INVITE is sent		     */
	PJSIP_INV_STATE_INCOMING,     /**< After INVITE is received.	     */
	PJSIP_INV_STATE_EARLY,	      /**< After response with To tag.	     */
	PJSIP_INV_STATE_CONNECTING,   /**< After 2xx is sent/received.	     */
	PJSIP_INV_STATE_CONFIRMED,    /**< After ACK is sent/received.	     */
	PJSIP_INV_STATE_DISCONNECTED, /**< Session is terminated.	     */
    } INV_STATE;

    class ImpLogWriter : public pj::LogWriter
    {
    public:
	virtual void write(const pj::LogEntry &entry);
    };

    /* Account related data type. */
    public ref struct OnRegStateParamRT sealed
    {
	OnRegStateParamRT();

	property pj_status_t status
	{
	    pj_status_t get();
	};

	property unsigned code 
	{
	    unsigned get();
	};

	property Platform::String^ reason
	{
	    Platform::String^ get();
	};

	property int expiration
	{
	    int get();
	};

    internal:
	OnRegStateParamRT(const pj::OnRegStateParam& param);

    private:
	pj::OnRegStateParam* inPtr;	    

	~OnRegStateParamRT();
    };

    public ref struct CallInfoRT sealed
    {	
	property Platform::String^ localUri
	{
	    Platform::String^ get();
	}

	property Platform::String^ localContact
	{
	    Platform::String^ get();	    
	}

	property Platform::String^ remoteUri
	{
	    Platform::String^ get();
	}

	property Platform::String^ remoteContact
	{
	    Platform::String^ get();
	}

	property INV_STATE state
	{
	    INV_STATE get();
	};

    internal:
	CallInfoRT(const pj::CallInfo& info);

    private:
	pj::CallInfo* inPtr;

	~CallInfoRT();

    };

    public interface class IntAccount
    {
    public:
	virtual void onRegState(OnRegStateParamRT^ prm);
	virtual void onIncomingCall(CallInfoRT^ info);
    };

    class ImpAccount : public pj::Account
    {
    public:
	void setCallback(IntAccount^ callback);

	virtual void onIncomingCall(pj::OnIncomingCallParam& prm);
	virtual void onRegState(pj::OnRegStateParam& prm);

	~ImpAccount() {};

    private:
	IntAccount^ cb;
    };

    /* Call related data type. */
    public ref class CallOpParamRT sealed
    {
    public:
	CallOpParamRT();

	property unsigned statusCode
	{
	    unsigned get();
	    void set(unsigned val);
	}

	property Platform::String^ reason {
	    Platform::String^ get();
	    void set(Platform::String^ val);
	}

    internal:
	pj::CallOpParam* getPtr();

    private:
	pj::CallOpParam* inPtr;

	~CallOpParamRT();
    };

    public interface class IntCall
    {

    public:
	virtual void onCallState(CallInfoRT^ info);	    
    };

    class ImpCall : public pj::Call
    {	    
    public:	    	    
	ImpCall(pj::Account& account, int call_id);
	virtual ~ImpCall() {};

	void setCallback(IntCall^ callback);

	virtual void onCallState(pj::OnCallStateParam& prm);
	virtual void onCallMediaState(pj::OnCallMediaStateParam& prm);	    

    private:
	IntCall^ cb;
    };

    public ref class AccountInfo sealed
    {
    public:
	property Platform::String^ id {
	    Platform::String^ get();
	}
	property Platform::String^ registrar {
	    Platform::String^ get();
	}
	property Platform::String^ proxy {
	    Platform::String^ get();
	}
	property Platform::String^ username {
	    Platform::String^ get();
	}
	property Platform::String^ password {
	    Platform::String^ get();
	}
    internal:
	AccountInfo(pj::AccountConfig* accConfig);
    private:
	pj::AccountConfig* cfg;
    };

    /* App class. */
    public ref class MyAppRT sealed
    {
    public:
	static property MyAppRT^ Instance {
	    MyAppRT^ get();
	}

	void init(IntAccount^ iAcc, IntCall^ iCall);
	void deInit();

	/* Util */
	void writeLog(int level, Platform::String^ message);

	/* Call handling. */
	void hangupCall();
	void answerCall(CallOpParamRT^ prm);
	void makeCall(Platform::String^ dst_uri);	
	CallInfoRT^ getCallInfo();

	/* Thread handling. */
	void registerThread(Platform::String^ name);
	bool isThreadRegistered();

	/* Account handling. */
	AccountInfo^ getAccountInfo();

	void modifyAccount(Platform::String^ id, Platform::String^ registrar, 
			   Platform::String^ proxy, Platform::String^ username, 
			   Platform::String^ password);

    internal:
	pj_bool_t handleIncomingCall(int callId);

    private:
	MyAppRT();
	~MyAppRT();

	void loadConfig();
	void saveConfig();

	static MyAppRT^ singleton;

	ImpLogWriter* logWriter;
	pj::Endpoint ep;

	/* Configs */
	pj::EpConfig* epConfig;
	pj::AccountConfig* accConfig;
	pj::TransportConfig* sipTpConfig;

	std::string appDir;
	ImpAccount* account;
	ImpCall* activeCall;

	IntAccount^ intAcc;
	IntCall^ intCall;
    };
}