OPAL  Version 3.14.3
opal.h
Go to the documentation of this file.
1 /*
2  * opal.h
3  *
4  * "C" language interface for OPAL
5  *
6  * Open Phone Abstraction Library (OPAL)
7  *
8  * Copyright (c) 2008 Vox Lucida
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Open Phone Abstraction Library.
21  *
22  * The Initial Developer of the Original Code is Vox Lucida (Robert Jongbloed)
23  *
24  * This code was initially written with the assisance of funding from
25  * Stonevoice. http://www.stonevoice.com.
26  *
27  * Contributor(s): ______________________________________.
28  *
29  * $Revision: 32502 $
30  * $Author: rjongbloed $
31  * $Date: 2014-08-12 16:58:01 +1000 (Tue, 12 Aug 2014) $
32  */
33 
34 #ifndef OPAL_OPAL_H
35 #define OPAL_OPAL_H
36 
37 #include <stdlib.h>
38 
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
70 #ifdef _WIN32
71  #define OPAL_EXPORT __stdcall
72 #else
73  #define OPAL_EXPORT
74 #endif
75 
77 typedef struct OpalHandleStruct * OpalHandle;
78 
79 
80 typedef struct OpalMessage OpalMessage;
81 
83 #define OPAL_C_API_VERSION 30
84 
85 
87 
147 extern OpalHandle OPAL_EXPORT OpalInitialise(unsigned * version, const char * options);
148 
152 #if _WIN32
153  #define OPAL_INITIALISE_FUNCTION MAKEINTRESOURCE(1)
154 #else
155  #define OPAL_INITIALISE_FUNCTION "OpalInitialise"
156 #endif
157 
158 
162 typedef OpalHandle (OPAL_EXPORT *OpalInitialiseFunction)(unsigned * version, const char * options);
163 
164 
166 
175 extern void OPAL_EXPORT OpalShutDown(OpalHandle opal);
176 
180 #if _WIN32
181  #define OPAL_SHUTDOWN_FUNCTION MAKEINTRESOURCE(2)
182 #else
183  #define OPAL_SHUTDOWN_FUNCTION "OpalShutDown"
184 #endif
185 
189 typedef void (OPAL_EXPORT *OpalShutDownFunction)(OpalHandle opal);
190 
191 
193 
230 extern OpalMessage * OPAL_EXPORT OpalGetMessage(OpalHandle opal, unsigned timeout);
231 
235 #if _WIN32
236  #define OPAL_GET_MESSAGE_FUNCTION MAKEINTRESOURCE(3)
237 #else
238  #define OPAL_GET_MESSAGE_FUNCTION "OpalGetMessage"
239 #endif
240 
244 typedef OpalMessage * (OPAL_EXPORT *OpalGetMessageFunction)(OpalHandle opal, unsigned timeout);
245 
246 
248 
289 extern OpalMessage * OPAL_EXPORT OpalSendMessage(OpalHandle opal, const OpalMessage * message);
290 
294 typedef OpalMessage * (OPAL_EXPORT *OpalSendMessageFunction)(OpalHandle opal, const OpalMessage * message);
295 
299 #if _WIN32
300  #define OPAL_SEND_MESSAGE_FUNCTION MAKEINTRESOURCE(4)
301 #else
302  #define OPAL_SEND_MESSAGE_FUNCTION "OpalSendMessage"
303 #endif
304 
305 
307 
311 extern void OPAL_EXPORT OpalFreeMessage(OpalMessage * message);
312 
316 #if _WIN32
317  #define OPAL_FREE_MESSAGE_FUNCTION MAKEINTRESOURCE(5)
318 #else
319  #define OPAL_FREE_MESSAGE_FUNCTION "OpalFreeMessage"
320 #endif
321 
326 
327 
329 
330 #define OPAL_PREFIX_H323 "h323"
331 #define OPAL_PREFIX_SIP "sip"
332 #define OPAL_PREFIX_IAX2 "iax2"
333 #define OPAL_PREFIX_PCSS "pc"
334 #define OPAL_PREFIX_LOCAL "local"
335 #define OPAL_PREFIX_POTS "pots"
336 #define OPAL_PREFIX_PSTN "pstn"
337 #define OPAL_PREFIX_CAPI "isdn"
338 #define OPAL_PREFIX_FAX "fax"
339 #define OPAL_PREFIX_T38 "t38"
340 #define OPAL_PREFIX_IVR "ivr"
341 #define OPAL_PREFIX_MIXER "mcu"
342 #define OPAL_PREFIX_IM "im"
343 #define OPAL_PREFIX_GST "gst"
344 #define OPAL_PREFIX_SKINNY "sccp"
345 
346 #define OPAL_PREFIX_ALL OPAL_PREFIX_SIP " " \
347  OPAL_PREFIX_H323 " " \
348  OPAL_PREFIX_IAX2 " " \
349  OPAL_PREFIX_PCSS " " \
350  OPAL_PREFIX_LOCAL " " \
351  OPAL_PREFIX_POTS " " \
352  OPAL_PREFIX_PSTN " " \
353  OPAL_PREFIX_FAX " " \
354  OPAL_PREFIX_T38 " " \
355  OPAL_PREFIX_IVR " " \
356  OPAL_PREFIX_MIXER " " \
357  OPAL_PREFIX_IM
358 
359 
362 typedef enum OpalMessageType {
474 // Always add new messages to ethe end to maintain backward compatibility
477 
478 
482 typedef enum OpalSilenceDetectMode {
488 
489 
493 typedef enum OpalEchoCancelMode {
498 
499 
533 typedef int (*OpalMediaDataFunction)(
534  const char * token,
536  const char * stream,
540  const char * format,
541  void * userData,
542  void * data,
543  int size
544 );
545 
546 
564  const OpalMessage * message
565 );
566 
567 
577 typedef enum OpalMediaDataType {
584 
585 
603 typedef enum OpalMediaTiming {
613 
614 
647 typedef struct OpalParamGeneral {
648  const char * m_audioRecordDevice;
652  const char * m_audioPlayerDevice;
656  const char * m_videoInputDevice;
661  const char * m_videoOutputDevice;
666  const char * m_videoPreviewDevice;
670  const char * m_mediaOrder;
673  const char * m_mediaMask;
676  const char * m_autoRxMedia;
680  const char * m_autoTxMedia;
684  const char * m_natMethod;
689  const char * m_natServer;
693  unsigned m_tcpPortBase;
695  unsigned m_tcpPortMax;
697  unsigned m_udpPortBase;
699  unsigned m_udpPortMax;
701  unsigned m_rtpPortBase;
703  unsigned m_rtpPortMax;
709  unsigned m_minAudioJitter;
713  unsigned m_maxAudioJitter;
722  unsigned m_signalDeadband;
724  unsigned m_silenceDeadband;
731  unsigned m_audioBuffers;
745  const char * m_mediaOptions;
754  unsigned m_audioBufferTime;
757  unsigned m_manualAlerting;
770  const char * m_pcssMediaOverride;
781 
782 
785 typedef struct OpalProductDescription {
786  const char * m_vendor;
789  const char * m_name;
792  const char * m_version;
795  unsigned m_t35CountryCode;
800  unsigned m_t35Extension;
812 
813 
817 typedef enum OpalUserInputModes {
825 
826 
843 typedef struct OpalParamProtocol {
844  const char * m_prefix;
847  const char * m_userName;
850  const char * m_displayName;
853  const char * m_interfaceAddresses;
878  const char * m_defaultOptions;
881 
882 
884 #define OPAL_MWI_EVENT_PACKAGE "message-summary"
885 
887 #define OPAL_LINE_APPEARANCE_EVENT_PACKAGE "dialog;sla;ma"
888 
961 typedef struct OpalParamRegistration {
962  const char * m_protocol;
964  const char * m_identifier;
970  const char * m_hostName;
974  const char * m_authUserName;
975  const char * m_password;
976  const char * m_adminEntity;
979  unsigned m_timeToLive;
981  unsigned m_restoreTime;
984  const char * m_eventPackage;
992  const char * m_attributes;
997 
998 
1014 
1015 
1019 typedef struct OpalStatusRegistration {
1020  const char * m_protocol;
1022  const char * m_serverName;
1025  const char * m_error;
1032 
1033 
1070 typedef struct OpalParamSetUpCall {
1071  const char * m_partyA;
1085  const char * m_partyB;
1097  const char * m_callToken;
1102  const char * m_alertingType;
1121  const char * m_protocolCallId;
1127 
1128 
1132 typedef struct OpalStatusIncomingCall {
1133  const char * m_callToken;
1134  const char * m_localAddress;
1135  const char * m_remoteAddress;
1136  const char * m_remotePartyNumber;
1137  const char * m_remoteDisplayName;
1138  const char * m_calledAddress;
1139  const char * m_calledPartyNumber;
1141  const char * m_alertingType;
1153  const char * m_protocolCallId;
1155  const char * m_referredByAddress;
1156  const char * m_redirectingNumber;
1158 
1159 
1168 typedef struct OpalParamAnswerCall {
1169  const char * m_callToken;
1173  unsigned m_withMedia;
1176 
1181 typedef enum OpalMediaStates {
1191 } OpalMediaStates;
1192 
1193 
1200 typedef struct OpalStatusMediaStream {
1201  const char * m_callToken;
1202  const char * m_identifier;
1205  const char * m_type;
1210  const char * m_format;
1217  int m_volume;
1222 
1223 
1226 typedef struct OpalParamSetUserData {
1227  const char * m_callToken;
1228  void * m_userData;
1230 
1231 
1237 typedef struct OpalStatusUserInput {
1238  const char * m_callToken;
1239  const char * m_userInput;
1240  unsigned m_duration;
1245 } OpalStatusUserInput, OpalParamUserInput;
1246 
1247 
1252  const char * m_party;
1253  const char * m_type;
1254  const char * m_extraInfo;
1258 
1259 
1273  OpalLineIdle = OpalLineTerminated // Kept for backward compatibility
1275 
1276 
1281  const char * m_line;
1286  const char * m_callId;
1290  const char * m_partyA;
1291  const char * m_partyB;
1293 
1294 
1298 typedef enum OpalPresenceStates {
1308 
1309 
1338 typedef struct OpalPresenceStatus {
1339  const char * m_entity;
1342  const char * m_target;
1344  const char * m_service;
1346  const char * m_contact;
1347  const char * m_capabilities;
1350  const char * m_activities;
1354  const char * m_note;
1358  const char * m_infoType;
1359  const char * m_infoData;
1361 
1362 
1371 typedef struct OpalInstantMessage {
1372  const char * m_from;
1373  const char * m_to;
1374  const char * m_host;
1376  const char * m_conversationId;
1380  const char * m_textBody;
1382  unsigned m_bodyCount;
1383  const char ** m_mimeType;
1384  const char ** m_bodies;
1385  unsigned m_messageId;
1390 
1391 
1413 
1414 
1417 typedef struct OpalParamRecording {
1418  const char * m_callToken;
1419  const char * m_file;
1421  unsigned m_channels;
1424  const char * m_audioFormat;
1428  const char * m_videoFormat;
1432  unsigned m_videoWidth;
1433  unsigned m_videoHeight;
1434  unsigned m_videoRate;
1437 
1438 
1442 typedef struct OpalStatusTransferCall {
1443  const char * m_callToken;
1444  const char * m_protocolCallId;
1446  const char * m_result;
1461  const char * m_info;
1466 
1467 
1471 typedef struct OpalStatusIVR {
1472  const char * m_callToken;
1473  const char * m_variables;
1478 } OpalStatusIVR;
1479 
1480 
1484 typedef struct OpalStatusCallCleared {
1485  const char * m_callToken;
1486  const char * m_reason;
1492 
1493 
1498 typedef enum OpalCallEndReason {
1531 
1532 
1535 typedef struct OpalParamCallCleared {
1536  const char * m_callToken;
1540 
1541 
1543  const char * m_commandError;
1549  const char * m_callToken;
1552  OpalStatusUserInput m_userInput;
1564 };
1565 
1566 
1570 struct OpalMessage {
1573 };
1574 
1575 
1576 #define OPALMSG_INIT(msg,type,field) (memset(&(msg), 0, sizeof(msg)),(msg).m_type=type,&(msg).m_param.field)
1577 
1579 #define OPALMSG_GENERAL_PARAM(msg) OPALMSG_INIT(msg,OpalCmdSetGeneralParameters,m_general)
1580 
1582 #define OPALMSG_PROTO_PARAM(msg) OPALMSG_INIT(msg,OpalCmdSetProtocolParameters,m_protocol)
1583 
1585 #define OPALMSG_REGISTRATION(msg) OPALMSG_INIT(msg,OpalCmdRegistration,m_registrationInfo)
1586 
1588 #define OPALMSG_SETUP_CALL(msg) OPALMSG_INIT(msg,OpalCmdSetUpCall,m_callSetUp)
1589 
1591 #define OPALMSG_TRANSFER(msg) OPALMSG_INIT(msg,OpalCmdTransferCall,m_callSetUp)
1592 
1594 #define OPALMSG_ANSWER_CALL(msg) OPALMSG_INIT(msg,OpalCmdAnswerCall,m_answerCall)
1595 
1597 #define OPALMSG_CLEAR_CALL(msg) OPALMSG_INIT(msg,OpalCmdClearCall,m_clearCall)
1598 
1600 #define OPALMSG_SET_USER_DATA(msg) OPALMSG_INIT(msg,OpalCmdSetUserData,m_setUserData)
1601 
1603 #define OPALMSG_START_RECORDING(msg) OPALMSG_INIT(msg,OpalCmdStartRecording,m_recording)
1604 
1605 
1606 #ifdef __cplusplus
1607 };
1608 #endif
1609 
1610 #if defined(__cplusplus) || defined(DOC_PLUS_PLUS)
1611 
1614 {
1615  public:
1617  ~OpalMessagePtr();
1618 
1619  OpalMessageType GetType() const;
1621 
1622  const char * GetCallToken() const;
1623  void SetCallToken(const char * token);
1624 
1625  const char * GetCommandError() const;
1626 
1631  OpalParamSetUpCall * GetCallSetUp() const;
1634  OpalStatusUserInput * GetUserInput() const;
1641  OpalParamRecording * GetRecording() const;
1645 
1646 #ifndef SWIG
1647  operator OpalParamGeneral *() const { return GetGeneralParams(); }
1648  operator OpalParamProtocol *() const { return GetProtocolParams(); }
1649  operator OpalParamRegistration *() const { return GetRegistrationParams(); }
1650  operator OpalStatusRegistration *() const { return GetRegistrationStatus(); }
1651  operator OpalParamSetUpCall *() const { return GetCallSetUp(); }
1652  operator OpalStatusIncomingCall *() const { return GetIncomingCall(); }
1653  operator OpalParamAnswerCall *() const { return GetAnswerCall(); }
1654  operator OpalStatusUserInput *() const { return GetUserInput(); }
1655  operator OpalStatusMessageWaiting *() const { return GetMessageWaiting(); }
1656  operator OpalStatusLineAppearance *() const { return GetLineAppearance(); }
1657  operator OpalStatusCallCleared *() const { return GetCallCleared(); }
1658  operator OpalParamCallCleared *() const { return GetClearCall(); }
1659  operator OpalStatusMediaStream *() const { return GetMediaStream(); }
1660  operator OpalParamSetUserData *() const { return GetSetUserData(); }
1661  operator OpalParamRecording *() const { return GetRecording(); }
1662  operator OpalStatusTransferCall *() const { return GetTransferStatus(); }
1663  operator OpalPresenceStatus *() const { return GetPresenceStatus(); }
1664  operator OpalInstantMessage *() const { return GetInstantMessage(); }
1665 #endif // SWIG
1666 
1667  protected:
1669 
1670  private:
1671  OpalMessagePtr(const OpalMessagePtr &) { }
1672  void operator=(const OpalMessagePtr &) { }
1673 
1674  friend class OpalContext;
1675 };
1676 
1677 
1678 #ifdef GetMessage
1679 #undef GetMessage
1680 #endif
1681 #ifdef SendMessage
1682 #undef SendMessage
1683 #endif
1684 
1685 
1694 {
1695  public:
1697  OpalContext();
1698 
1700  virtual ~OpalContext();
1701 
1704  unsigned Initialise(
1705  const char * options,
1706  unsigned version = OPAL_C_API_VERSION
1707  );
1708 
1710  bool IsInitialised() const { return m_handle != NULL; }
1711 
1713  void ShutDown();
1714 
1716  bool GetMessage(
1717  OpalMessagePtr & message,
1718  unsigned timeout = 0
1719  );
1720 
1722  bool SendMessage(
1723  const OpalMessagePtr & message
1724  );
1725  bool SendMessage(
1726  const OpalMessagePtr & message,
1727  OpalMessagePtr & response
1728  );
1729 
1730 
1732  bool SetUpCall(
1733  OpalMessagePtr & response,
1734  const char * partyB,
1735  const char * partyA = NULL,
1736  const char * alertingType = NULL
1737  );
1738 
1740  bool AnswerCall(
1741  const char * callToken
1742  );
1743 
1745  bool ClearCall(
1746  const char * callToken,
1748  );
1749 
1751  bool SendUserInput(
1752  const char * callToken,
1753  const char * userInput,
1754  unsigned duration = 0
1755  );
1756 
1757 #ifndef SWIG
1758  // Windows API compatibility
1759  __inline bool GetMessageA(
1760  OpalMessagePtr & message,
1761  unsigned timeout = 0
1762  ) { return GetMessage(message, timeout); }
1763  __inline bool GetMessageW(
1764  OpalMessagePtr & message,
1765  unsigned timeout = 0
1766  ) { return GetMessage(message, timeout); }
1767  __inline bool SendMessageA(
1768  const OpalMessagePtr & message
1769  ) { return SendMessage(message); }
1770  __inline bool SendMessageA(
1771  const OpalMessagePtr & message,
1772  OpalMessagePtr & response
1773  ) { return SendMessage(message, response); }
1774  __inline bool SendMessageW(
1775  const OpalMessagePtr & message
1776  ) { return SendMessage(message); }
1777  __inline bool SendMessageW(
1778  const OpalMessagePtr & message,
1779  OpalMessagePtr & response
1780  ) { return SendMessage(message, response); }
1781 #endif // SWIG
1782 
1783  protected:
1785 };
1786 
1787 #endif // defined(__cplusplus)
1788 
1789 #endif // OPAL_OPAL_H
1790 
1791