source: verona/phcpp/phapipp.h @ 451:98d5d2016443

Last change on this file since 451:98d5d2016443 was 451:98d5d2016443, checked in by Vadim Lebedev <vadim@…>, 14 months ago

implement sendMessage3 api

File size: 13.4 KB
Line 
1#ifndef __PHAPIPP_H__
2#define __PHAPIPP_H__ 1
3
4/*
5  The phapipp module implements thin C++ wrapper around phapi
6  Copyright (C) 2007  Vadim Lebedev  <vadim@mbdsys.com>
7
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Lesser General Public
10  License as published by the Free Software Foundation; either
11  version 2.1 of the License, or (at your option) any later version.
12
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  Lesser General Public License for more details.
17
18  You should have received a copy of the GNU Lesser General Public
19  License along with this library; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21 */
22
23#include <phapi.h>
24#include <string>
25#include <map>
26#include <vector>
27
28/*
29
30  This module declares:
31   1/  phapi class which can be derived from or
32   used directly by the application.
33
34   2/  phapitp template class which can be used to simplify interface
35   with the code using C++ strings.
36
37
38   example using std::string is provided as a typedef stdphapi
39
40   to use with QString one should do something like:
41
42   struct qtenv {
43      typedef QString string;
44      static const char *cstr(const QString& str) { return str.toLatin(); }
45      };
46
47   typedef verona::phapitp<qtenv> QtPhapi;
48
49 */
50
51namespace verona {
52
53
54class phapi
55{
56
57public:
58
59        phapi();
60        virtual ~phapi();
61
62        virtual int init(bool asyncMode = true);
63        virtual void terminate();
64
65        virtual int addAuthInfo(const char* username, const char* userid,  const char* passwd,
66                        const char *realm, const char* ha1 = 0);
67
68        virtual int listenAddr(int local_sip_port);
69
70        virtual int addVline(const char* displayname, const char* username, const char* host,
71                        const char*  proxy, int regTimeout, int mobility = PH_LINE_MOBILITY_DEFAULT);
72
73        virtual int delVline(int vlid);
74
75        virtual int vlRegister(int vlid);
76
77        virtual int sendOptions(int vlid, const char *to);
78
79        virtual int placeCall(int vlid, const char*  uri, void* userdata =0 , int rcid = 0, int streams = PH_STREAM_AUDIO,
80                        const char* adev = 0, const char* audio_addr = 0, const char* video_addr = 0);
81
82        virtual int acceptCall(int cid, void* userData = 0, int streams = PH_STREAM_AUDIO,
83                        const char* audio_addr = 0, const char* video_addr = 0);
84
85        virtual int rejectCall(int cid, int reason, const char *uri = 0);
86        virtual int ringingCall(int cid);
87        virtual int closeCall(int cid);
88        virtual int holdCall(int cid);
89        virtual int resumeCall(int cid);
90        virtual int blindTransferCall(int cid, const char *uri);
91
92        virtual int messageInCall(int cid, const char *buff, const char *mime);
93        virtual int getSipCallID(int cid, char *idbuf,  int bufsize);
94        virtual int sendDtmf(int cid, int dtmfChar, int mode);
95
96
97        virtual int setFollowMe(int vlid, const char *uri);
98        virtual int setBusy(int vlid, bool busy);
99        virtual int sendMessage(int vlid, const char* to,  const char* buff, const char* mime,
100                        const char* target = 0, const char* sipcid = 0);
101        virtual int sendMessage3(int vlid, const char* to,  const char* buff, const char* mime,
102                        const std::vector<std::pair<const char*, const char* > >& hdrs, const char* target = 0);
103
104        virtual int subscribe(int vlid, const char* to, int winfo, char *data = 0, int use_proxy = 1, int expire = 600);
105        virtual int unsubscribe(int sid, int winfo);
106        virtual int publish(int vlid, const char* to, const char* evt, const char* ctt, const char* content,
107                        int expires = -1);
108        int unpublish(int vlid, const char* to, const char* evt)
109        {
110                return publish(vlid, to, evt, 0, 0, 0);
111        }
112
113        virtual int getLineSipAddress(int vlid, char *buf, int size);
114        virtual int mobility(int vlid);
115        virtual int setUsername2(int vlid, const char* username);
116
117        int getVersion() { return phGetVersion(); }
118        const char * getRevision() { return phGetRevision(); }
119        struct ph_config_s*  getConfig() { return ph_get_config(); }
120
121        void changeAudioCodecList(const char *audio_codecs);
122        void changeVideoCodecList(const char *video_codecs);
123        void changeLocalIP(const char *local_ip);
124
125        int addCustomHeader(const char *reqnames, const char *hdrname,  const char *hdrval)
126        {
127                return phAddCustomization(reqnames, hdrname, hdrval);
128        }
129
130        int enableCustomization(int ruleId, int enable)
131        {
132                return phEnableCustomization(ruleId, enable);
133        }
134
135        int monitorHeader(const char *reqnames, const char *hdrname)
136        {
137                return phMonitorHeader(reqnames, hdrname);
138        }
139
140
141        int enableMonitor(int ruleID, int enable) { return phEnableMonitor(ruleID, enable); }
142
143        void resetMonitoring() { phResetMonitoring(); }
144
145
146#if defined(_WIN32_WCE)
147#ifdef SWIG
148%newobject getLocalIpFromDescription;
149#endif
150        char * getLocalIpFromDescription(const char *description);
151#endif
152        virtual void setUaString(const char *uastr);
153
154#ifdef SWIG
155%newobject getAudioCaptureDevices;
156%newobject getAudioPlaybackDevices;
157%newobject getVideoWebcamDevices;
158#endif
159
160        virtual std::map<char*, char*> getAudioCaptureDevices();
161        virtual std::map<char*, char*> getAudioPlaybackDevices();
162        virtual std::map<char*, char*> getVideoWebcamDevices();
163       
164        virtual void changeAudioDeviceIn(const char *devstr);
165        virtual void changeAudioDeviceOut(const char *devstr);
166        virtual void changeVideoDevices(const char *devstr);
167
168        virtual int setSoftRecvVolumeGain(int cid, float gain);
169        virtual int setSoftSendVolumeGain(int cid, float gain);
170        virtual int setRecvVolumeLevel(int cid, int level);
171        virtual int setSendVolumeLevel(int cid, int level);
172        virtual int mutePlayback(int cid, int val);
173        virtual int muteCapture(int cid, int val);
174       
175        virtual int setSoundFileGain(phStream* phstream,float gain);
176        virtual phStream * playSoundFile(const char * filename, int interval, const char* deviceid);
177        virtual int stopSoundFile(phStream * phstream);
178        virtual phStream * videoStartPreview(const char* deviceid);
179        virtual int videoStopPreview(phStream * phstream);
180        virtual int videoSetDefaultImage(const char* path);
181
182        virtual int poll();
183        virtual void refresh();
184
185        int getDebugLevel() { return phGetDebugLevel(); }
186        void setDebugLevel(int lvl) { phSetDebugLevel(lvl); }
187
188        virtual void setLogFile(const char* logFile);
189
190
191protected:
192
193        //  user overridable callbacks
194        virtual void onCallProgress(int cid, const phCallStateInfo_t *info);
195        virtual void onTransferProgress(int cid, const phTransferStateInfo_t *info);
196        virtual void onConfProgress(int cfid, const phConfStateInfo_t *info);
197        virtual void onRegProgress(int regid, int status);
198        virtual void onMsgProgress(int mid,  const phMsgStateInfo_t *info);
199        virtual void onMsgProgress2(int mid,  char * type, char * content);
200        virtual void onConnectionLost(const char* host, int port);
201#if defined(_WIN32_WCE)
202        virtual void onNotifyProgress (const char* ev, const char* from, const char *ctt, wchar_t* content);
203#else
204        virtual void onNotifyProgress (const char* ev, const char* from, const char *ctt, const char* content);
205#endif
206        virtual void onSubscriptionProgress(int sid,  const phSubscriptionStateInfo_t *info);
207        virtual void onFrameReady(int cid, phVideoFrameReceivedEvent_t *ev);
208
209#if defined(_WIN32_WCE)
210        virtual void onCallProgress2(int cid, phCallStateEvent status, wchar_t * uri, int error);
211#else
212        virtual void onCallProgress2(int cid, phCallStateEvent status, char * uri, int error);
213#endif
214        virtual void onDtmfProgress(int cid, int dtmf);
215        virtual void onPhLogCsl(const char *msg);
216        virtual void onSoundFileStopped(void *userdata , unsigned int _id, void *arg);
217        virtual void onQosEvent(int cid, const phQosInfo_t * info);
218
219
220private:
221
222#ifndef SWIG
223        static phCallbacks_t callbacks;
224
225        static void  callProgress(int cid, const phCallStateInfo_t *info);
226        static void  transferProgress(int cid, const phTransferStateInfo_t *info);
227        static void  confProgress(int cfid, const phConfStateInfo_t *info);
228        static void  regProgress(int regid, int status);
229        static void  msgProgress(int mid,  const phMsgStateInfo_t *info);
230        static void  connectionLost(const char* host, int port);
231        static void  notifyProgress(const char* ev, const char* from, const char *ctt, const char* content);
232        static void  subscriptionProgress(int sid,  const phSubscriptionStateInfo_t *info);
233        static void  frameReady(int cid, phVideoFrameReceivedEvent_t *ev);
234        static void  phLogCsl(const char *msg);
235        static void  soundFileStopped(void *userdata , unsigned int _id, void *arg);
236        static void  qosEvent(int cid, const phQosInfo_t * info);
237#endif
238
239};
240
241#ifndef SWIG
242//#define phthis ((phapi *) this)
243template<class Env>
244class phapitp: public phapi
245{
246public:
247
248        typedef typename Env::string string;
249
250        static inline const char *cstr(const string& s) { return Env::cstr(s); }
251
252        virtual ~phapitp(){};
253
254        int addAuthInfo(const string &username, const string& userid, const string& passwd, const char* realm)
255        {
256                return phapi::addAuthInfo(cstr(username), cstr(userid), cstr(passwd), realm);
257        }
258
259        int addAuthInfo(const string &username, const string& userid, const string&passwd, const char* realm,
260                        const string& ha1)
261        {
262                return phapi::addAuthInfo(cstr(username), cstr(userid), cstr(passwd), realm, cstr(ha1));
263        }
264        int listenAddr(int local_sip_port)
265        {
266                return phapi::listenAddr(local_sip_port);
267        }
268
269        int addVline(const string& displayname, const string& username, const string& host,
270                        const string&  proxy, int regTimeout, int mobility = PH_LINE_MOBILITY_DEFAULT)
271        {
272                return phapi::addVline(cstr(displayname), cstr(username), cstr(host), cstr(proxy), regTimeout, mobility);
273        }
274
275        int vlRegister(int vlid)
276        {
277                return phvlRegister(vlid);
278        }
279
280        int  sendOptions(int vlid, const string& to)
281        {
282                return phapi::sendOptions(vlid, cstr(to));
283        }
284
285
286        int placeCall(int vlid, const string& uri, void* userdata = 0, int rcid =0 , int streams = PH_STREAM_AUDIO,
287                        const char* adev = 0, const char* audio_addr = 0, const char* video_addr = 0)
288        {
289                return phapi::placeCall(vlid, cstr(uri), userdata, rcid, streams, adev, audio_addr, video_addr);
290        }
291
292
293
294        int rejectCall(int cid, int reason, const string& uri)
295        {
296                return phapi::rejectCall(cid, reason, cstr(uri));
297        }
298
299
300
301        int messageInCall(int cid, const string& mime, const string& buf)
302        {
303                return phapi::messageInCall(cid, cstr(mime), cstr(buf));
304        }
305
306
307
308
309        int setFollowMe(int vlid, const string& uri)
310        {
311                return phapi::setFollowMe(vlid, cstr(uri));
312        }
313
314
315
316        string getSipCallID(int cid)
317        {
318                char buf[256];
319
320                phapi::getSipCallID(cid, buf, sizeof(buf));
321
322                return buf;
323        }
324
325
326        string getSipAddress(int vlid)
327        {
328                char buf[256];
329
330                phapi::getLineSipAddress(vlid, buf, sizeof(buf));
331
332                return buf;
333        }
334
335
336
337        int sendMessage(int vlid, const string& to, const string& buff,
338                        const string& mime,
339                        const string& target, const string& sipcid)
340        {
341                return  phapi::sendMessage(vlid, cstr(to), cstr(buff), cstr(mime), cstr(target), cstr(sipcid));
342        }
343
344
345        int sendMessage(int vlid, const string& to, const string& buff,
346                        const string& mime, const string& target)
347        {
348                return phapi::sendMessage(vlid, cstr(to), cstr(buff), cstr(mime), cstr(target), 0);
349        }
350
351
352
353        int sendMessage(int vlid, const string& to, const string& buff, const string& mime)
354        {
355                return phapi::sendMessage(vlid, cstr(to), cstr(buff), cstr(mime), 0, 0);
356        }
357
358
359
360        int subscribe(int vlid, const string& to, int winfo, char *data = 0, int use_proxy = 1, int expire = 600)
361        {
362                return phapi::subscribe(vlid, cstr(to), winfo, data, use_proxy, expire);
363        }
364
365        int unsubscribe(int sid, int winfo)
366        {
367                return phapi::unsubscribe(sid, winfo);
368        }
369
370        int publish(int vlid, const string& to, const string& evt, const string& ctt,
371                        const string& content, int expires = -1)
372        {
373                return phapi::publish(vlid, cstr(to), cstr(evt), cstr(ctt), cstr(content), expires);
374        }
375
376        int unpublish(int vlid, const string& to, const string& evt)
377        {
378                return phapi::unpublish(vlid, cstr(to), cstr(evt));
379        }
380
381        std::map<char*, char*> getAudioCaptureDevices()
382    {
383                return phapi::getAudioCaptureDevices();
384    }
385
386        std::map<char*, char*> getAudioPlaybackDevices()
387    {
388                return phapi::getAudioPlaybackDevices();
389    }
390
391        int setSoftRecvVolumeGain(int cid, float gain)
392        {
393                return phapi::setSoftRecvVolumeGain(cid, gain);
394        }
395
396        int setSoftSendVolumeGain(int cid, float gain)
397        {
398                return phapi::setSoftSendVolumeGain(cid, gain);
399        }
400
401        int setRecvVolumeLevel(int cid, int level)
402        {
403                return phapi::setRecvVolumeLevel(cid, level);
404        }
405
406        int setSendVolumeLevel(int cid, int level)
407        {
408                return phapi::setSendVolumeLevel(cid, level);
409        }
410
411        int mutePlayback(int cid, int val)
412        {
413                return phapi::mutePlayback(cid, val);
414        }
415
416        int muteCapture(int cid, int val)
417        {
418                return phapi::muteCapture(cid, val);
419        }
420
421        int addCustomHeader(const string& reqnames, const string& hdrname,  const string& hdrval)
422        {
423                return phapi::addCustomHeader(cstr(reqnames), cstr(hdrname), cstr(hdrval));
424        }
425
426        int monitorHeader(const string& reqnames, const string& hdrname)
427        {
428                return phapi::monitorHeader(cstr(reqnames), cstr(hdrname));
429        }
430
431
432
433        void setUaString(const string& ua) {  phapi::setUaString(cstr(ua)); }
434        void changeAudioDeviceIn(const string& devstr) {  phapi::changeAudioDeviceIn(cstr(devstr)); }
435        void changeAudioDeviceOut(const string& devstr) {  phapi::changeAudioDeviceOut(cstr(devstr)); }
436        void changeAudioCodecList(const string& audio_codecs)
437        {
438                phapi::changeAudioCodecList(cstr(audio_codecs));
439        }
440        void changeLocalIP(const string& local_ip)
441        {
442                phapi::changeLocalIP(cstr(local_ip));
443        }
444
445        void setLogFile(const string& logfile) {  phapi::setLogFile(cstr(logfile)); }
446
447
448protected:
449
450};
451
452//#undef phthis
453
454class stdenv
455{
456public:
457        typedef std::string string;
458        static const char *cstr(const string& s) {  if (&s != NULL) return s.c_str(); else return NULL; }
459
460
461};
462
463
464// decalare a wrapper using std::string
465typedef phapitp<stdenv> stdphapi;
466#endif
467
468}
469
470#endif /* __PHAPIPP_H__ */
Note: See TracBrowser for help on using the repository browser.