source: verona/phcpp/phapipp.h @ 146:06976d859135

Last change on this file since 146:06976d859135 was 138:efddf6e11c3c, checked in by laurent, 2 years ago

bug fix : media accessors

File size: 11.1 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
27/*
28
29  This module declares:
30   1/  phapi class which can be derived from or
31   used directly by the application.
32
33   2/  phapitp template class which can be used to simplify interface
34   with the code using C++ strings.
35
36
37   example using std::string is provided as a typedef stdphapi
38
39   to use with QString one should do something like:
40
41   struct qtenv {
42      typedef QString string;
43      static const char *cstr(const QString& str) { return str.toLatin(); }
44      };
45
46   typedef verona::phapitp<qtenv> QtPhapi;
47
48 */
49
50namespace verona {
51
52
53class phapi
54{
55
56public:
57
58        phapi();
59        virtual ~phapi();
60
61        virtual int init(bool asyncMode = true);
62        virtual void terminate();
63
64        virtual int addAuthInfo(const char* username, const char* userid,  const char* passwd,
65                        const char *realm, const char* ha1 = 0);
66
67
68        virtual int addVline(const char* displayname, const char* username, const char* host,
69                        const char*  proxy, int regTimeout, int mobility = PH_LINE_MOBILITY_DEFAULT);
70
71        virtual int delVline(int vlid);
72
73        virtual int vlRegister(int vlid);
74
75        virtual int sendOptions(int vlid, const char *to);
76
77        virtual int placeCall(int vlid, const char*  uri, void* userdata =0 , int rcid = 0, int streams = PH_STREAM_AUDIO,
78                        const char* adev = 0, const char* audio_addr = 0, const char* video_addr = 0);
79
80        virtual int acceptCall(int cid, void* userData = 0, int streams = PH_STREAM_AUDIO,
81                        const char* audio_addr = 0, const char* video_addr = 0);
82
83        virtual int rejectCall(int cid, int reason, const char *uri = 0);
84        virtual int ringingCall(int cid);
85        virtual int closeCall(int cid);
86        virtual int messageInCall(int cid, const char *buff, const char *mime);
87        virtual int getSipCallID(int cid, char *idbuf,  int bufsize);
88        virtual int sendDtmf(int cid, int dtmfChar, int mode);
89
90
91        virtual int setFollowMe(int vlid, const char *uri);
92        virtual int setBusy(int vlid, bool busy);
93        virtual int sendMessage(int vlid, const char* to,  const char* buff, const char* mime,
94                        const char* target = 0, const char* sipcid = 0);
95
96        virtual int subscribe(int vlid, const char* to, int winfo, char *data = 0, int use_proxy = 1, int expire = 600);
97        virtual int unsubscribe(int sid, int winfo);
98        virtual int publish(int vlid, const char* to, const char* evt, const char* ctt, const char* content,
99                        int expires = -1);
100        int unpublish(int vlid, const char* to, const char* evt)
101        {
102                return publish(vlid, to, evt, 0, 0, 0);
103        }
104
105        virtual int getLineSipAddress(int vlid, char *buf, int size);
106        virtual int mobility(int vlid);
107
108        int getVersion() { return phGetVersion(); }
109        const char * getRevision() { return phGetRevision(); }
110        struct ph_config_s*  getConfig() { return ph_get_config(); }
111
112        void changeAudioCodecList(const char *audio_codecs);
113        void changeVideoCodecList(const char *video_codecs);
114        void changeLocalIP(const char *local_ip);
115#if defined(_WIN32_WCE)
116        char * getLocalIpFromDescription(const char *description);
117#endif
118        virtual void setUaString(const char *uastr);
119
120        virtual std::map<char*, char*> getAudioCaptureDevices();
121        virtual std::map<char*, char*> getAudioPlaybackDevices();
122        virtual std::map<char*, char*> getVideoWebcamDevices();
123       
124        virtual void changeAudioDevices(const char *devstr);
125        virtual void changeVideoDevices(const char *devstr);
126
127        virtual int setSoftRecvVolumeGain(int cid, float gain);
128        virtual int setSoftSendVolumeGain(int cid, float gain);
129        virtual int setRecvVolumeLevel(int cid, int level);
130        virtual int setSendVolumeLevel(int cid, int level);
131        virtual int mutePlayback(int cid, int val);
132        virtual int muteCapture(int cid, int val);
133
134        virtual int poll();
135        virtual void refresh();
136
137        int getDebugLevel() { return phGetDebugLevel(); }
138        void setDebugLevel(int lvl) { phSetDebugLevel(lvl); }
139
140        virtual void setLogFile(const char* logFile);
141
142
143protected:
144
145        //  user overridable callbacks
146        virtual void onCallProgress(int cid, const phCallStateInfo_t *info);
147        virtual void onTransferProgress(int cid, const phTransferStateInfo_t *info);
148        virtual void onConfProgress(int cfid, const phConfStateInfo_t *info);
149        virtual void onRegProgress(int regid, int status);
150        virtual void onMsgProgress(int mid,  const phMsgStateInfo_t *info);
151        virtual void onMsgProgress2(int mid,  char * type, char * content);
152        virtual void onConnectionLost(const char* host, int port);
153#if defined(_WIN32_WCE)
154        virtual void onNotifyProgress (const char* ev, const char* from, const char *ctt, wchar_t* content);
155#else
156        virtual void onNotifyProgress (const char* ev, const char* from, const char *ctt, const char* content);
157#endif
158        virtual void onSubscriptionProgress(int sid,  const phSubscriptionStateInfo_t *info);
159        virtual void onFrameReady(int cid, phVideoFrameReceivedEvent_t *ev);
160
161#if defined(_WIN32_WCE)
162        virtual void onCallProgress2(int cid, phCallStateEvent status, wchar_t * uri, int error);
163#else
164        virtual void onCallProgress2(int cid, phCallStateEvent status, char * uri, int error);
165#endif
166        virtual void onDtmfProgress(int cid, int dtmf);
167        virtual void onPhLogCsl(const char *msg);
168
169
170private:
171
172        static phCallbacks_t callbacks;
173
174        static void  callProgress(int cid, const phCallStateInfo_t *info);
175        static void  transferProgress(int cid, const phTransferStateInfo_t *info);
176        static void  confProgress(int cfid, const phConfStateInfo_t *info);
177        static void  regProgress(int regid, int status);
178        static void  msgProgress(int mid,  const phMsgStateInfo_t *info);
179        static void  connectionLost(const char* host, int port);
180        static void  notifyProgress(const char* ev, const char* from, const char *ctt, const char* content);
181        static void  subscriptionProgress(int sid,  const phSubscriptionStateInfo_t *info);
182        static void  frameReady(int cid, phVideoFrameReceivedEvent_t *ev);
183        static void  phLogCsl(const char *msg);
184
185};
186
187
188//#define phthis ((phapi *) this)
189template<class Env>
190class phapitp: public phapi
191{
192public:
193
194        typedef typename Env::string string;
195
196        static inline const char *cstr(const string& s) { return Env::cstr(s); }
197
198        virtual ~phapitp(){};
199
200        int addAuthInfo(const string &username, const string& userid, const string& passwd, const char* realm)
201        {
202                return phapi::addAuthInfo(cstr(username), cstr(userid), cstr(passwd), realm);
203        }
204
205        int addAuthInfo(const string &username, const string& userid, const string&passwd, const char* realm,
206                        const string& ha1)
207        {
208                return  phapi::addAuthInfo(cstr(username), cstr(userid), cstr(passwd), realm, cstr(ha1));
209        }
210
211
212        int addVline(const string& displayname, const string& username, const string& host,
213                        const string&  proxy, int regTimeout, int mobility = PH_LINE_MOBILITY_DEFAULT)
214        {
215                return  phapi::addVline(cstr(displayname), cstr(username), cstr(host), cstr(proxy), regTimeout, mobility);
216        }
217
218        int vlRegister(int vlid)
219        {
220                return phvlRegister(vlid);
221        }
222
223        int  sendOptions(int vlid, const string& to)
224        {
225                return phapi::sendOptions(vlid, cstr(to));
226        }
227
228
229        int placeCall(int vlid, const string& uri, void* userdata = 0, int rcid =0 , int streams = PH_STREAM_AUDIO,
230                        const char* adev = 0, const char* audio_addr = 0, const char* video_addr = 0)
231        {
232                return  phapi::placeCall(vlid, cstr(uri), userdata, rcid, streams, adev, audio_addr, video_addr);
233        }
234
235
236
237        int rejectCall(int cid, int reason, const string& uri)
238        {
239                return  phapi::rejectCall(cid, reason, cstr(uri));
240        }
241
242
243
244        int messageInCall(int cid, const string& mime, const string& buf)
245        {
246                return  phapi::messageInCall(cid, cstr(mime), cstr(buf));
247        }
248
249
250
251
252        int setFollowMe(int vlid, const string& uri)
253        {
254                return  phapi::setFollowMe(vlid, cstr(uri));
255        }
256
257
258
259        string getSipCallID(int cid)
260        {
261                char buf[256];
262
263                phapi::getSipCallID(cid, buf, sizeof(buf));
264
265                return buf;
266        }
267
268
269        string getSipAddress(int vlid)
270        {
271                char buf[256];
272
273                phapi::getLineSipAddress(vlid, buf, sizeof(buf));
274
275                return buf;
276        }
277
278
279
280        int sendMessage(int vlid, const string& to, const string& buff,
281                        const string& mime,
282                        const string& target, const string& sipcid)
283        {
284                return  phapi::sendMessage(vlid, cstr(to), cstr(buff), cstr(mime), cstr(target), cstr(sipcid));
285        }
286
287
288        int sendMessage(int vlid, const string& to, const string& buff,
289                        const string& mime, const string& target)
290        {
291                return  phapi::sendMessage(vlid, cstr(to), cstr(buff), cstr(mime), cstr(target), 0);
292        }
293
294
295
296        int sendMessage(int vlid, const string& to, const string& buff, const string& mime)
297        {
298                return  phapi::sendMessage(vlid, cstr(to), cstr(buff), cstr(mime), 0, 0);
299        }
300
301
302
303        int subscribe(int vlid, const string& to, int winfo, char *data = 0, int use_proxy = 1, int expire = 600)
304        {
305                return  phapi::subscribe(vlid, cstr(to), winfo, data, use_proxy, expire);
306        }
307
308        int unsubscribe(int sid, int winfo)
309        {
310                return  phapi::unsubscribe(sid, winfo);
311        }
312
313        int publish(int vlid, const string& to, const string& evt, const string& ctt,
314                        const string& content, int expires = -1)
315        {
316                return  phapi::publish(vlid, cstr(to), cstr(evt), cstr(ctt), cstr(content), expires);
317        }
318
319        int unpublish(int vlid, const string& to, const string& evt)
320        {
321                return  phapi::unpublish(vlid, cstr(to), cstr(evt));
322        }
323
324        std::map<char*, char*> getAudioCaptureDevices()
325    {
326                return phapi::getAudioCaptureDevices();
327    }
328
329        std::map<char*, char*> getAudioPlaybackDevices()
330    {
331                return phapi::getAudioPlaybackDevices();
332    }
333
334        int setSoftRecvVolumeGain(int cid, float gain)
335        {
336                return phapi::setSoftRecvVolumeGain(cid, gain);
337        }
338
339        int setSoftSendVolumeGain(int cid, float gain)
340        {
341                return phapi::setSoftSendVolumeGain(cid, gain);
342        }
343
344        int setRecvVolumeLevel(int cid, int level)
345        {
346                return phapi::setRecvVolumeLevel(cid, level);
347        }
348
349        int setSendVolumeLevel(int cid, int level)
350        {
351                return phapi::setSendVolumeLevel(cid, level);
352        }
353
354        int mutePlayback(int cid, int val)
355        {
356                return phapi::mutePlayback(cid, val);
357        }
358
359        int muteCapture(int cid, int val)
360        {
361                return phapi::muteCapture(cid, val);
362        }
363
364
365        void setUaString(const string& ua) {  phapi::setUaString(cstr(ua)); }
366        void changeAudioDevices(const string& devstr) {  phapi::changeAudioDevices(cstr(devstr)); }
367        void changeAudioCodecList(const string& audio_codecs)
368        {
369                phapi::changeAudioCodecList(cstr(audio_codecs));
370        }
371        void changeLocalIP(const string& local_ip)
372        {
373                phapi::changeLocalIP(cstr(local_ip));
374        }
375
376        void setLogFile(const string& logfile) {  phapi::setLogFile(cstr(logfile)); }
377
378
379protected:
380
381};
382
383//#undef phthis
384
385class stdenv
386{
387public:
388        typedef std::string string;
389        static const char *cstr(const string& s) {  if (&s != NULL) return s.c_str(); else return NULL; }
390
391
392};
393
394
395// decalare a wrapper using std::string
396typedef phapitp<stdenv> stdphapi;
397
398}
399
400#endif /* __PHAPIPP_H__ */
Note: See TracBrowser for help on using the repository browser.