- Timestamp:
- Oct 25, 2013 10:34:38 AM (11 years ago)
- Location:
- pjproject/branches/projects/pjsua2
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/pjsua2/build.mak.in
r4631 r4638 145 145 $(APP_THIRD_PARTY_EXT)\ 146 146 -lpj-$(TARGET_NAME)\ 147 @LIBS@ 147 @LIBS@ \ 148 -lstdc++ 148 149 # x x x x x x x x x x x x x x x x x x x x x x x x 149 150 # -
pjproject/branches/projects/pjsua2/pjsip-apps/src/samples/pjsua2_demo.cpp
r4631 r4638 23 23 using namespace pj; 24 24 25 class MyAccount Callback : public AccountCallback25 class MyAccount : public Account 26 26 { 27 27 public: 28 MyAccountCallback() 29 : AccountCallback() 28 MyAccount() 30 29 {} 31 30 32 31 virtual void onRegState(OnRegStateParam &prm) 33 32 { 34 AccountInfo ai = account()->getInfo();33 AccountInfo ai = getInfo(); 35 34 std::cout << (ai.regIsActive? "*** Register: code=" : "*** Unregister: code=") 36 35 << prm.code << std::endl; … … 40 39 static void mainProg() throw(Error) 41 40 { 42 Endpoint & ep = Endpoint::instance();41 Endpoint ep; 43 42 44 43 // Create library … … 46 45 47 46 // Init library 48 ep.libInit( EpConfig() ); 47 EpConfig ep_cfg; 48 ep_cfg.logConfig.level = 4; 49 ep.libInit( ep_cfg ); 49 50 50 51 // Transport … … 63 64 acc_cfg.sipConfig.authCreds.push_back( AuthCredInfo("digest", "*", 64 65 "test1", 0, "test1") ); 65 std::auto_ptr<Account> acc(new Account(new MyAccountCallback, NULL));66 std::auto_ptr<Account> acc(new MyAccount); 66 67 acc->create(acc_cfg); 67 68 … … 70 71 // Destroy library 71 72 std::cout << "*** PJSUA2 SHUTTING DOWN ***" << std::endl; 72 ep.libDestroy();73 73 } 74 74 … … 84 84 } 85 85 86 Endpoint::instance().libDestroy();87 88 86 return ret; 89 87 } -
pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/java/Makefile
r4619 r4638 43 43 MY_LDFLAGS = $(PJ_LDFLAGS) -lpjsua2-$(TARGET_NAME) $(PJ_LDLIBS) $(MY_JNI_LDFLAGS) -static-libstdc++ 44 44 45 .PHONY: all java 46 45 47 all: $(LIBPJSUA2_SO) java 46 48 … … 57 59 rm -rf $(OUT_DIR)/pjsua2_wrap.cpp $(OUT_DIR)/pjsua2_wrap.o $(LIBPJSUA2_SO) $(OUT_DIR)/*.java $(OUT_DIR)/*.class 58 60 59 java: 61 java: output/Error.class output/test.class 62 63 output/Error.class: output/Error.java 60 64 $(MY_JAVAC) -d $(OUT_DIR) $(OUT_DIR)/*.java 65 66 output/test.class: test.java 61 67 $(MY_JAVAC) -d $(OUT_DIR) -classpath "$(OUT_DIR)" test.java 62 68 -
pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/pjsua2.i
r4608 r4638 10 10 // 11 11 %{ 12 #include "pjsua2 /endpoint.hpp"12 #include "pjsua2.hpp" 13 13 using namespace std; 14 14 using namespace pj; … … 167 167 %rename("%s", regexmatch$name="PJSUA_CALL_HOLD_TYPE_.*") "";// Unignore this 168 168 %rename("%s") pjsua_acc_id; // Unignore this 169 %rename("%s") pjsua_destroy_flag; // Unignore this 170 %rename("%s", regexmatch$name="PJSUA_DESTROY_.*") ""; // Unignore this 169 171 %include "pjsua-lib/pjsua.h" 170 172 … … 175 177 176 178 // 179 // Ignore stuffs in pjsua2 itself 180 // 181 %ignore fromPj; 182 %ignore toPj; 183 184 // 177 185 // Now include the API itself. 178 186 // 179 187 %include "pjsua2/types.hpp" 180 188 %include "pjsua2/endpoint.hpp" 189 #include "pjsua2/account.hpp" 181 190 -
pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/python/helper.mak
r4619 r4638 17 17 18 18 target_name: 19 $(TARGET_NAME)19 @echo $(TARGET_NAME) 20 20 -
pjproject/branches/projects/pjsua2/pjsip/include/pjsua2/account.hpp
r4631 r4638 878 878 { 879 879 /** 880 * The library call indexallocated for the new call.881 */ 882 int callI ndex;880 * The library call ID allocated for the new call. 881 */ 882 int callId; 883 883 884 884 /** … … 917 917 * SIP reason phrase received. 918 918 */ 919 pj_str_treason;919 string reason; 920 920 921 921 /** … … 1085 1085 }; 1086 1086 1087 /** 1088 * Account callback 1089 */ 1090 class AccountCallback 1087 1088 /** 1089 * @} // PJSUA2_Acc_Data_Structure 1090 */ 1091 1092 /** 1093 * @addtogroup PJSUA2_ACC 1094 * @{ 1095 */ 1096 1097 1098 /** 1099 * Account. 1100 */ 1101 class Account 1091 1102 { 1092 1103 public: 1093 /** Virtual destructor */ 1094 virtual ~AccountCallback() {} 1095 1096 /** 1097 * Get the account associated with this callback. 1098 */ 1099 Account *account() 1100 { return acc; } 1101 1104 /** 1105 * Constructor. 1106 */ 1107 Account(); 1108 1109 /** 1110 * Destructor. Note that if the account is deleted, it will also delete 1111 * the corresponding account in the PJSUA-LIB. 1112 */ 1113 virtual ~Account(); 1114 1115 /** 1116 * Create the account. 1117 * 1118 * @param cfg The account config. 1119 * @param make_default Make this the default account. 1120 */ 1121 void create(const AccountConfig &cfg, 1122 bool make_default=false) throw(Error); 1123 1124 /** 1125 * Modify the account to use the specified account configuration. 1126 * Depending on the changes, this may cause unregistration or 1127 * reregistration on the account. 1128 * 1129 * @param cfg New account config to be applied to the account. 1130 */ 1131 void modify(const AccountConfig &acc) throw(Error); 1132 1133 /** 1134 * Check if this account is still valid. 1135 * 1136 * @return True if it is. 1137 */ 1138 bool isValid() const; 1139 1140 /** 1141 * Set this as default account to be used when incoming and outgoing 1142 * requests don't match any accounts. 1143 * 1144 * @return PJ_SUCCESS on success. 1145 */ 1146 void setDefault() throw(Error); 1147 1148 /** 1149 * Check if this account is the default account. Default account will be 1150 * used for incoming and outgoing requests that don't match any other 1151 * accounts. 1152 * 1153 * @return True if this is the default account. 1154 */ 1155 bool isDefault() const; 1156 1157 /** 1158 * Get PJSUA-LIB account ID or index associated with this account. 1159 * 1160 * @return Integer greater than or equal to zero. 1161 */ 1162 int getId() const; 1163 1164 /** 1165 * Get the Account class for the specified account Id. 1166 * 1167 * @param acc_id The account ID to lookup 1168 * 1169 * @return The Account instance or NULL if not found. 1170 */ 1171 static Account *lookup(int acc_id); 1172 1173 /** 1174 * Get account info. 1175 * 1176 * @return Account info. 1177 */ 1178 AccountInfo getInfo() const throw(Error); 1179 1180 /** 1181 * Update registration or perform unregistration. Application normally 1182 * only needs to call this function if it wants to manually update the 1183 * registration or to unregister from the server. 1184 * 1185 * @param renew If False, this will start unregistration 1186 * process. 1187 */ 1188 void setRegistration(bool renew) throw(Error); 1189 1190 /** 1191 * Set or modify account's presence online status to be advertised to 1192 * remote/presence subscribers. This would trigger the sending of 1193 * outgoing NOTIFY request if there are server side presence subscription 1194 * for this account, and/or outgoing PUBLISH if presence publication is 1195 * enabled for this account. 1196 * 1197 * @param pres_st Presence online status. 1198 */ 1199 void setOnlineStatus(const AccountPresenceStatus &pres_st) throw(Error); 1200 1201 /** 1202 * Lock/bind this account to a specific transport/listener. Normally 1203 * application shouldn't need to do this, as transports will be selected 1204 * automatically by the library according to the destination. 1205 * 1206 * When account is locked/bound to a specific transport, all outgoing 1207 * requests from this account will use the specified transport (this 1208 * includes SIP registration, dialog (call and event subscription), and 1209 * out-of-dialog requests such as MESSAGE). 1210 * 1211 * Note that transport id may be specified in AccountConfig too. 1212 * 1213 * @param tp_id The transport ID. 1214 */ 1215 void setTransport(TransportId tp_id) throw(Error); 1216 1217 public: 1218 /* 1219 * Callbacks 1220 */ 1102 1221 /** 1103 1222 * Notify application on incoming call. … … 1202 1321 1203 1322 protected: 1204 AccountCallback()1205 : acc(NULL)1206 {}1207 1208 private:1209 Account *acc;1210 1211 /** Set the account. Must only be called by Account class */1212 void setAccount(Account *the_acc)1213 { acc = the_acc; }1214 1215 friend class Account;1216 };1217 1218 1219 /**1220 * @} // PJSUA2_Acc_Data_Structure1221 */1222 1223 /**1224 * @addtogroup PJSUA2_ACC1225 * @{1226 */1227 1228 1229 /**1230 * Account.1231 */1232 class Account1233 {1234 public:1235 /**1236 * Constructor.1237 */1238 Account(AccountCallback *cb, Token user_data);1239 1240 /**1241 * Destructor.1242 */1243 ~Account();1244 1245 /**1246 * Create the account.1247 *1248 * @param cfg The account config.1249 * @param make_default Make this the default account.1250 */1251 void create(const AccountConfig &cfg,1252 bool make_default=false) throw(Error);1253 1254 /**1255 * Modify the account to use the specified account configuration.1256 * Depending on the changes, this may cause unregistration or1257 * reregistration on the account.1258 *1259 * @param cfg New account config to be applied to the account.1260 */1261 void modify(const AccountConfig &acc) throw(Error);1262 1263 /**1264 * Check if this account is still valid.1265 *1266 * @return True if it is.1267 */1268 bool isValid() const;1269 1270 /**1271 * Set this as default account to be used when incoming and outgoing1272 * requests don't match any accounts.1273 *1274 * @return PJ_SUCCESS on success.1275 */1276 void setDefault() throw(Error);1277 1278 /**1279 * Check if this account is the default account. Default account will be1280 * used for incoming and outgoing requests that don't match any other1281 * accounts.1282 *1283 * @return True if this is the default account.1284 */1285 bool isDefault() const;1286 1287 /**1288 * Get PJSUA-LIB account ID or index associated with this account.1289 *1290 * @return Integer greater than or equal to zero.1291 */1292 int getIndex() const;1293 1294 /**1295 * Set arbitrary data to be associated with the account.1296 *1297 * @param user_data User/application data.1298 */1299 void setUserData(Token user_data);1300 1301 /**1302 * Get the user data that was associated with the account.1303 *1304 * @return The user data.1305 */1306 Token getUserData() const;1307 1308 /**1309 * Get account info.1310 *1311 * @return Account info.1312 */1313 AccountInfo getInfo() const throw(Error);1314 1315 /**1316 * Update registration or perform unregistration. Application normally1317 * only needs to call this function if it wants to manually update the1318 * registration or to unregister from the server.1319 *1320 * @param renew If False, this will start unregistration1321 * process.1322 */1323 void setRegistration(bool renew) throw(Error);1324 1325 /**1326 * Set or modify account's presence online status to be advertised to1327 * remote/presence subscribers. This would trigger the sending of1328 * outgoing NOTIFY request if there are server side presence subscription1329 * for this account, and/or outgoing PUBLISH if presence publication is1330 * enabled for this account.1331 *1332 * @param pres_st Presence online status.1333 */1334 void setOnlineStatus(const AccountPresenceStatus &pres_st) throw(Error);1335 1336 /**1337 * Lock/bind this account to a specific transport/listener. Normally1338 * application shouldn't need to do this, as transports will be selected1339 * automatically by the library according to the destination.1340 *1341 * When account is locked/bound to a specific transport, all outgoing1342 * requests from this account will use the specified transport (this1343 * includes SIP registration, dialog (call and event subscription), and1344 * out-of-dialog requests such as MESSAGE).1345 *1346 * Note that transport id may be specified in AccountConfig too.1347 *1348 * @param tp_id The transport ID.1349 */1350 void setTransport(TransportId tp_id) throw(Error);1351 1352 protected:1353 1323 friend class Endpoint; 1354 1324 1355 1325 private: 1356 1326 pjsua_acc_id id; 1357 AccountCallback *cb; 1358 Token userData; 1327 string tmpReason; // for saving response's reason 1359 1328 }; 1360 1329 -
pjproject/branches/projects/pjsua2/pjsip/include/pjsua2/endpoint.hpp
r4608 r4638 43 43 44 44 /** 45 * Argument to E pCallback::onNatDetectionComplete() callback.45 * Argument to Endpoint::onNatDetectionComplete() callback. 46 46 */ 47 47 struct OnNatDetectionCompleteParam … … 73 73 74 74 /** 75 * Argument to E pCallback::onNatCheckStunServersComplete() callback.75 * Argument to Endpoint::onNatCheckStunServersComplete() callback. 76 76 */ 77 77 struct OnNatCheckStunServersCompleteParam … … 104 104 105 105 /** 106 * Parameter of E pCallback::OnTimer() callback.106 * Parameter of Endpoint::onTimer() callback. 107 107 */ 108 108 struct OnTimerParam … … 121 121 122 122 /** 123 * Parameter of E pCallback::onTransportState() callback.123 * Parameter of Endpoint::onTransportState() callback. 124 124 */ 125 125 struct OnTransportStateParam … … 142 142 143 143 /** 144 * Parameter of E pCallback::onSelectAccount() callback.144 * Parameter of Endpoint::onSelectAccount() callback. 145 145 */ 146 146 struct OnSelectAccountParam … … 159 159 int accountIndex; 160 160 }; 161 162 //////////////////////////////////////////////////////////////////////////////163 164 /**165 * Interface for receiving callbacks from the library. Application inherits166 * this class and specify the instance when calling Endpoint::libInit().167 */168 class EpCallback169 {170 public:171 /** Virtual destructor */172 virtual ~EpCallback() {}173 174 /**175 * Callback when the Endpoint has finished performing NAT type176 * detection that is initiated with Endpoint::natDetectType().177 *178 * @param prm Callback parameters containing the detection179 * result.180 */181 virtual void onNatDetectionComplete(182 const OnNatDetectionCompleteParam &prm)183 {}184 185 /**186 * Callback when the Endpoint has finished performing STUN server187 * checking that is initiated with Endpoint::natCheckStunServers().188 *189 * @param prm Callback parameters.190 */191 virtual void onNatCheckStunServersComplete(192 const OnNatCheckStunServersCompleteParam &prm)193 {}194 195 /**196 * This callback is called when transport state has changed.197 *198 * @param prm Callback parameters.199 */200 virtual void onTransportState(201 const OnTransportStateParam &prm)202 {}203 204 /**205 * Callback when a timer has fired. The timer was scheduled by206 * Endpoint::utilTimerSchedule().207 *208 * @param prm Callback parameters.209 */210 virtual void onTimer(const OnTimerParam &prm)211 {}212 213 /**214 * This callback can be used by application to override the account215 * to be used to handle an incoming message. Initially, the account to216 * be used will be calculated automatically by the library. This initial217 * account will be used if application does not implement this callback,218 * or application sets an invalid account upon returning from this219 * callback.220 *221 * Note that currently the incoming messages requiring account assignment222 * are INVITE, MESSAGE, SUBSCRIBE, and unsolicited NOTIFY. This callback223 * may be called before the callback of the SIP event itself, i.e:224 * incoming call, pager, subscription, or unsolicited-event.225 *226 * @param prm Callback parameters.227 */228 virtual void onSelectAccount(OnSelectAccountParam &prm)229 {}230 };231 232 161 233 162 ////////////////////////////////////////////////////////////////////////////// … … 313 242 * 314 243 * If this is enabled, the library will respond 200/OK to the NOTIFY 315 * request and forward the request to E pCallback.onMwiInfo() callback.244 * request and forward the request to Endpoint::onMwiInfo() callback. 316 245 * 317 246 * See also AccountMwiConfig.enabled. … … 407 336 408 337 /** 409 * Custom log writer, if required. If specified, the instance of LogWriter410 * must be kept alive througout the duration of the application.338 * Custom log writer, if required. This instance will be destroyed 339 * by the endpoint when the endpoint is destroyed. 411 340 */ 412 341 LogWriter *writer; … … 655 584 public: 656 585 /** Retrieve the singleton instance of the endpoint */ 657 static Endpoint &instance(); 658 659 /* For testing */ 660 void testException() throw(Error); 586 static Endpoint &instance() throw(Error); 587 588 /** Default constructor */ 589 Endpoint(); 590 591 /** Virtual destructor */ 592 virtual ~Endpoint(); 661 593 662 594 … … 688 620 * 689 621 * @param prmEpConfig Endpoint configurations 690 * @param prmCb Optional callback to receive events from the 691 * library. If specified, this instance must be 692 * kept alive throughout the lifetime of the 693 * library. 694 */ 695 void libInit( const EpConfig &prmEpConfig, 696 EpCallback *prmCb = NULL) throw(Error); 622 */ 623 void libInit( const EpConfig &prmEpConfig) throw(Error); 697 624 698 625 /** … … 770 697 /** 771 698 * Schedule a timer with the specified interval and user data. When the 772 * interval elapsed, E pCallback::OnTimer() callback will be699 * interval elapsed, Endpoint::onTimer() callback will be 773 700 * called. Note that the callback may be executed by different thread, 774 701 * depending on whether worker thread is enabled or not. … … 803 730 * This is a utility function to detect NAT type in front of this endpoint. 804 731 * Once invoked successfully, this function will complete asynchronously 805 * and report the result in E pCallback::onNatDetectionComplete().732 * and report the result in Endpoint::onNatDetectionComplete(). 806 733 * 807 734 * After NAT has been detected and the callback is called, application can … … 817 744 * Get the NAT type as detected by #natDetectType() function. This 818 745 * function will only return useful NAT type after #natDetectType() 819 * has completed successfully and E pCallback::onNatDetectionComplete()746 * has completed successfully and Endpoint::onNatDetectionComplete() 820 747 * callback has been called. 821 748 * … … 926 853 void transportClose(TransportId id) throw(Error); 927 854 855 public: 856 /* 857 * Overrideables callbacks 858 */ 859 860 /** 861 * Callback when the Endpoint has finished performing NAT type 862 * detection that is initiated with Endpoint::natDetectType(). 863 * 864 * @param prm Callback parameters containing the detection 865 * result. 866 */ 867 virtual void onNatDetectionComplete( 868 const OnNatDetectionCompleteParam &prm) 869 {} 870 871 /** 872 * Callback when the Endpoint has finished performing STUN server 873 * checking that is initiated with Endpoint::natCheckStunServers(). 874 * 875 * @param prm Callback parameters. 876 */ 877 virtual void onNatCheckStunServersComplete( 878 const OnNatCheckStunServersCompleteParam &prm) 879 {} 880 881 /** 882 * This callback is called when transport state has changed. 883 * 884 * @param prm Callback parameters. 885 */ 886 virtual void onTransportState( 887 const OnTransportStateParam &prm) 888 {} 889 890 /** 891 * Callback when a timer has fired. The timer was scheduled by 892 * Endpoint::utilTimerSchedule(). 893 * 894 * @param prm Callback parameters. 895 */ 896 virtual void onTimer(const OnTimerParam &prm) 897 {} 898 899 /** 900 * This callback can be used by application to override the account 901 * to be used to handle an incoming message. Initially, the account to 902 * be used will be calculated automatically by the library. This initial 903 * account will be used if application does not implement this callback, 904 * or application sets an invalid account upon returning from this 905 * callback. 906 * 907 * Note that currently the incoming messages requiring account assignment 908 * are INVITE, MESSAGE, SUBSCRIBE, and unsolicited NOTIFY. This callback 909 * may be called before the callback of the SIP event itself, i.e: 910 * incoming call, pager, subscription, or unsolicited-event. 911 * 912 * @param prm Callback parameters. 913 */ 914 virtual void onSelectAccount(OnSelectAccountParam &prm) 915 {} 916 928 917 929 918 private: 930 /* Anybody else can't instantiate Endpoint */ 931 Endpoint(); 932 933 private: 934 /* Custom writer, if any */ 935 LogWriter *writer; 936 EpCallback *epCallback; 937 938 /* 939 * Callbacks (static) 940 */ 919 static Endpoint *instance_; // static instance 920 LogWriter *writer; // Custom writer, if any 921 922 /* Endpoint static callbacks */ 941 923 static void logFunc(int level, const char *data, int len); 942 924 static void stun_resolve_cb(const pj_stun_resolve_result *result); … … 947 929 pjsip_transport_state state, 948 930 const pjsip_transport_state_info *info); 931 932 private: 933 /* 934 * Account 935 */ 936 static Account *lookupAcc(int acc_id, const char *op); 937 938 /* static callbacks */ 939 static void on_incoming_call(pjsua_acc_id acc_id, 940 pjsua_call_id call_id, 941 pjsip_rx_data *rdata); 942 static void on_reg_started(pjsua_acc_id acc_id, 943 pj_bool_t renew); 944 static void on_reg_state2(pjsua_acc_id acc_id, 945 pjsua_reg_info *info); 946 static void on_incoming_subscribe(pjsua_acc_id acc_id, 947 pjsua_srv_pres *srv_pres, 948 pjsua_buddy_id buddy_id, 949 const pj_str_t *from, 950 pjsip_rx_data *rdata, 951 pjsip_status_code *code, 952 pj_str_t *reason, 953 pjsua_msg_data *msg_data); 954 static void on_pager2(pjsua_call_id call_id, 955 const pj_str_t *from, 956 const pj_str_t *to, 957 const pj_str_t *contact, 958 const pj_str_t *mime_type, 959 const pj_str_t *body, 960 pjsip_rx_data *rdata, 961 pjsua_acc_id acc_id); 962 static void on_pager_status2(pjsua_call_id call_id, 963 const pj_str_t *to, 964 const pj_str_t *body, 965 void *user_data, 966 pjsip_status_code status, 967 const pj_str_t *reason, 968 pjsip_tx_data *tdata, 969 pjsip_rx_data *rdata, 970 pjsua_acc_id acc_id); 971 static void on_typing2(pjsua_call_id call_id, 972 const pj_str_t *from, 973 const pj_str_t *to, 974 const pj_str_t *contact, 975 pj_bool_t is_typing, 976 pjsip_rx_data *rdata, 977 pjsua_acc_id acc_id); 978 static void on_mwi_info(pjsua_acc_id acc_id, 979 pjsua_mwi_info *mwi_info); 949 980 }; 950 981 -
pjproject/branches/projects/pjsua2/pjsip/include/pjsua2/types.hpp
r4631 r4638 71 71 72 72 /* 73 * Forward declaration of Account, AccountC allback, AccountConfig, to be used73 * Forward declaration of Account, AccountConfig, to be used 74 74 * by Endpoint. 75 75 */ 76 76 class Account; 77 class AccountCallback;78 77 class AccountConfig; 79 78 … … 522 521 */ 523 522 unsigned srcPort; 523 524 /** 525 * Construct from PJSIP's pjsip_rx_data 526 */ 527 void fromPj(pjsip_rx_data &rdata); 524 528 }; 525 529 -
pjproject/branches/projects/pjsua2/pjsip/src/pjsua2/account.cpp
r4631 r4638 351 351 /////////////////////////////////////////////////////////////////////////////// 352 352 353 Account::Account(AccountCallback *param_cb, Token user_data) 354 : id(PJSUA_INVALID_ID), cb(param_cb), userData(user_data) 355 { 356 cb->setAccount(this); 353 Account::Account() 354 : id(PJSUA_INVALID_ID) 355 { 357 356 } 358 357 359 358 Account::~Account() 360 359 { 361 delete cb; 360 /* If this instance is deleted, also delete the corresponding account in 361 * PJSUA library. 362 */ 363 if (isValid() && pjsua_get_state() < PJSUA_STATE_CLOSING) { 364 PJSUA2_CHECK_EXPR( pjsua_acc_set_user_data(id, NULL) ); 365 PJSUA2_CHECK_EXPR( pjsua_acc_del(id) ); 366 } 362 367 } 363 368 … … 367 372 pjsua_acc_config pj_acc_cfg = acc_cfg.toPj(); 368 373 374 pj_acc_cfg.user_data = (void*)this; 369 375 PJSUA2_CHECK_EXPR( pjsua_acc_add(&pj_acc_cfg, make_default, &id) ); 370 376 } … … 392 398 } 393 399 394 int Account::getI ndex() const400 int Account::getId() const 395 401 { 396 402 return id; 397 403 } 398 404 399 void Account::setUserData(Token user_data) 400 { 401 userData = user_data; 402 } 403 404 Token Account::getUserData() const 405 { 406 return userData; 405 Account *Account::lookup(int acc_id) 406 { 407 return (Account*)pjsua_acc_get_user_data(acc_id); 407 408 } 408 409 -
pjproject/branches/projects/pjsua2/pjsip/src/pjsua2/endpoint.cpp
r4631 r4638 18 18 */ 19 19 #include <pjsua2/endpoint.hpp> 20 #include <pjsua2/account.hpp> 20 21 #include "util.hpp" 21 22 … … 34 35 }; 35 36 37 Endpoint *Endpoint::instance_; 36 38 37 39 /////////////////////////////////////////////////////////////////////////////// … … 210 212 */ 211 213 Endpoint::Endpoint() 212 : writer(NULL), epCallback(NULL) 213 { 214 } 215 216 Endpoint& Endpoint::instance() 217 { 218 static Endpoint lib_; 219 return lib_; 220 } 221 222 void Endpoint::testException() throw(Error) 223 { 224 PJSUA2_CHECK_RAISE_ERROR(PJ_EINVALIDOP); 225 } 226 214 : writer(NULL) 215 { 216 if (instance_) { 217 PJSUA2_RAISE_ERROR(PJ_EEXISTS); 218 } 219 220 instance_ = this; 221 } 222 223 Endpoint& Endpoint::instance() throw(Error) 224 { 225 if (!instance_) { 226 PJSUA2_RAISE_ERROR(PJ_ENOTFOUND); 227 } 228 return *instance_; 229 } 230 231 Endpoint::~Endpoint() 232 { 233 try { 234 libDestroy(); 235 } catch (Error &err) { 236 // Ignore 237 } 238 delete writer; 239 instance_ = NULL; 240 } 227 241 228 242 /////////////////////////////////////////////////////////////////////////////// … … 250 264 Endpoint &ep = Endpoint::instance(); 251 265 252 if (! ep.epCallback || !res)266 if (!res) 253 267 return; 254 268 … … 265 279 } 266 280 267 ep. epCallback->onNatCheckStunServersComplete(prm);281 ep.onNatCheckStunServersComplete(prm); 268 282 } 269 283 … … 274 288 UserTimer *ut = (UserTimer*) entry->user_data; 275 289 276 if ( !ep.epCallback ||ut->signature != TIMER_SIGNATURE)277 return; 278 279 ep. epCallback->onTimer(ut->prm);290 if (ut->signature != TIMER_SIGNATURE) 291 return; 292 293 ep.onTimer(ut->prm); 280 294 } 281 295 … … 284 298 Endpoint &ep = Endpoint::instance(); 285 299 286 if (! ep.epCallback || !res)300 if (!res) 287 301 return; 288 302 … … 294 308 prm.natTypeName = res->nat_type_name; 295 309 296 ep. epCallback->onNatDetectionComplete(prm);310 ep.onNatDetectionComplete(prm); 297 311 } 298 312 … … 303 317 Endpoint &ep = Endpoint::instance(); 304 318 305 if (!ep.epCallback)306 return;307 308 319 OnTransportStateParam prm; 309 320 … … 312 323 prm.lastError = info ? info->status : PJ_SUCCESS; 313 324 314 ep.epCallback->onTransportState(prm); 315 } 325 ep.onTransportState(prm); 326 } 327 328 /////////////////////////////////////////////////////////////////////////////// 329 /* 330 * Account static callbacks 331 */ 332 333 Account *Endpoint::lookupAcc(int acc_id, const char *op) 334 { 335 Account *acc = Account::lookup(acc_id); 336 if (!acc) { 337 PJ_LOG(1,(THIS_FILE, 338 "Error: cannot find Account instance for account id %d in " 339 "%s", acc_id, op)); 340 } 341 342 return acc; 343 } 344 345 void Endpoint::on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id, 346 pjsip_rx_data *rdata) 347 { 348 Account *acc = lookupAcc(acc_id, "on_incoming_call()"); 349 if (!acc) { 350 pjsua_call_hangup(call_id, PJSIP_SC_INTERNAL_SERVER_ERROR, NULL, NULL); 351 return; 352 } 353 354 /* call callback */ 355 OnIncomingCallParam prm; 356 prm.callId = call_id; 357 prm.rdata.fromPj(*rdata); 358 359 acc->onIncomingCall(prm); 360 361 /* disconnect if callback doesn't handle the call */ 362 pjsua_call_info ci; 363 364 pjsua_call_get_info(call_id, &ci); 365 if (!pjsua_call_get_user_data(call_id) && 366 ci.state != PJSIP_INV_STATE_DISCONNECTED) 367 { 368 pjsua_call_hangup(call_id, PJSIP_SC_INTERNAL_SERVER_ERROR, NULL, NULL); 369 } 370 } 371 372 void Endpoint::on_reg_started(pjsua_acc_id acc_id, pj_bool_t renew) 373 { 374 Account *acc = lookupAcc(acc_id, "on_reg_started()"); 375 if (!acc) { 376 return; 377 } 378 379 OnRegStartedParam prm; 380 prm.renew = renew; 381 acc->onRegStarted(prm); 382 } 383 384 void Endpoint::on_reg_state2(pjsua_acc_id acc_id, pjsua_reg_info *info) 385 { 386 Account *acc = lookupAcc(acc_id, "on_reg_state2()"); 387 if (!acc) { 388 return; 389 } 390 391 OnRegStateParam prm; 392 prm.status = info->cbparam->status; 393 prm.code = (pjsip_status_code) info->cbparam->code; 394 prm.reason = pj2Str(info->cbparam->reason); 395 if (info->cbparam->rdata) 396 prm.rdata.fromPj(*info->cbparam->rdata); 397 prm.expiration = info->cbparam->expiration; 398 399 acc->onRegState(prm); 400 } 401 402 void Endpoint::on_incoming_subscribe(pjsua_acc_id acc_id, 403 pjsua_srv_pres *srv_pres, 404 pjsua_buddy_id buddy_id, 405 const pj_str_t *from, 406 pjsip_rx_data *rdata, 407 pjsip_status_code *code, 408 pj_str_t *reason, 409 pjsua_msg_data *msg_data) 410 { 411 Account *acc = lookupAcc(acc_id, "on_incoming_subscribe()"); 412 if (!acc) { 413 /* default behavior should apply */ 414 return; 415 } 416 417 OnIncomingSubscribeParam prm; 418 prm.fromUri = pj2Str(*from); 419 prm.rdata.fromPj(*rdata); 420 prm.code = *code; 421 prm.reason = pj2Str(*reason); 422 423 acc->onIncomingSubscribe(prm); 424 425 *code = prm.code; 426 acc->tmpReason = prm.reason; 427 *reason = str2Pj(acc->tmpReason); 428 // TODO: 429 // apply msg_data 430 } 431 432 void Endpoint::on_pager2(pjsua_call_id call_id, 433 const pj_str_t *from, 434 const pj_str_t *to, 435 const pj_str_t *contact, 436 const pj_str_t *mime_type, 437 const pj_str_t *body, 438 pjsip_rx_data *rdata, 439 pjsua_acc_id acc_id) 440 { 441 OnInstantMessageParam prm; 442 prm.fromUri = pj2Str(*from); 443 prm.toUri = pj2Str(*to); 444 prm.contactUri = pj2Str(*contact); 445 prm.contentType = pj2Str(*mime_type); 446 prm.msgBody = pj2Str(*body); 447 prm.rdata.fromPj(*rdata); 448 449 if (call_id != PJSUA_INVALID_ID) { 450 // TODO: 451 // handle call pager 452 return; 453 } else { 454 Account *acc = lookupAcc(acc_id, "on_pager2()"); 455 if (!acc) { 456 /* Ignored */ 457 return; 458 } 459 460 acc->onInstantMessage(prm); 461 } 462 } 463 464 void Endpoint::on_pager_status2( pjsua_call_id call_id, 465 const pj_str_t *to, 466 const pj_str_t *body, 467 void *user_data, 468 pjsip_status_code status, 469 const pj_str_t *reason, 470 pjsip_tx_data *tdata, 471 pjsip_rx_data *rdata, 472 pjsua_acc_id acc_id) 473 { 474 OnInstantMessageStatusParam prm; 475 prm.userData = user_data; 476 prm.toUri = pj2Str(*to); 477 prm.msgBody = pj2Str(*body); 478 prm.status = status; 479 prm.reason = pj2Str(*reason); 480 if (rdata) 481 prm.rdata.fromPj(*rdata); 482 483 if (call_id != PJSUA_INVALID_ID) { 484 // TODO: 485 // handle call pager 486 } else { 487 Account *acc = lookupAcc(acc_id, "on_pager_status2()"); 488 if (!acc) { 489 /* Ignored */ 490 return; 491 } 492 493 acc->onInstantMessageStatus(prm); 494 } 495 } 496 497 void Endpoint::on_typing2( pjsua_call_id call_id, 498 const pj_str_t *from, 499 const pj_str_t *to, 500 const pj_str_t *contact, 501 pj_bool_t is_typing, 502 pjsip_rx_data *rdata, 503 pjsua_acc_id acc_id) 504 { 505 OnTypingIndicationParam prm; 506 prm.fromUri = pj2Str(*from); 507 prm.toUri = pj2Str(*to); 508 prm.contactUri = pj2Str(*contact); 509 prm.isTyping = is_typing != 0; 510 prm.rdata.fromPj(*rdata); 511 512 if (call_id != PJSUA_INVALID_ID) { 513 // TODO: 514 // handle call indication 515 } else { 516 Account *acc = lookupAcc(acc_id, "on_typing2()"); 517 if (!acc) { 518 /* Ignored */ 519 return; 520 } 521 522 acc->onTypingIndication(prm); 523 } 524 } 525 526 void Endpoint::on_mwi_info(pjsua_acc_id acc_id, 527 pjsua_mwi_info *mwi_info) 528 { 529 OnMwiInfoParam prm; 530 prm.state = pjsip_evsub_get_state(mwi_info->evsub); 531 prm.rdata.fromPj(*mwi_info->rdata); 532 533 Account *acc = lookupAcc(acc_id, "on_mwi_info()"); 534 if (!acc) { 535 /* Ignored */ 536 return; 537 } 538 539 acc->onMwiInfo(prm); 540 } 541 316 542 317 543 /////////////////////////////////////////////////////////////////////////////// … … 321 547 void Endpoint::libCreate() throw(Error) 322 548 { 323 pj_status_t status; 324 325 status = pjsua_create(); 326 PJSUA2_CHECK_RAISE_ERROR(status); 549 PJSUA2_CHECK_EXPR( pjsua_create() ); 327 550 } 328 551 … … 332 555 } 333 556 334 void Endpoint::libInit( const EpConfig &prmEpConfig, 335 EpCallback *prmCb) throw(Error) 557 void Endpoint::libInit(const EpConfig &prmEpConfig) throw(Error) 336 558 { 337 559 pjsua_config ua_cfg; 338 560 pjsua_logging_config log_cfg; 339 561 pjsua_media_config med_cfg; 340 pj_status_t status;341 562 342 563 ua_cfg = prmEpConfig.uaConfig.toPj(); … … 352 573 /* Setup UA callbacks */ 353 574 pj_bzero(&ua_cfg.cb, sizeof(ua_cfg.cb)); 354 ua_cfg.cb.on_nat_detect = &Endpoint::on_nat_detect;575 ua_cfg.cb.on_nat_detect = &Endpoint::on_nat_detect; 355 576 ua_cfg.cb.on_transport_state = &Endpoint::on_transport_state; 356 577 578 ua_cfg.cb.on_incoming_call = &Endpoint::on_incoming_call; 579 ua_cfg.cb.on_reg_started = &Endpoint::on_reg_started; 580 ua_cfg.cb.on_reg_state2 = &Endpoint::on_reg_state2; 581 ua_cfg.cb.on_incoming_subscribe = &Endpoint::on_incoming_subscribe; 582 ua_cfg.cb.on_pager2 = &Endpoint::on_pager2; 583 ua_cfg.cb.on_pager_status2 = &Endpoint::on_pager_status2; 584 ua_cfg.cb.on_typing2 = &Endpoint::on_typing2; 585 ua_cfg.cb.on_mwi_info = &Endpoint::on_mwi_info; 586 357 587 /* Init! */ 358 status = pjsua_init(&ua_cfg, &log_cfg, &med_cfg); 359 PJSUA2_CHECK_RAISE_ERROR(status); 588 PJSUA2_CHECK_EXPR( pjsua_init(&ua_cfg, &log_cfg, &med_cfg) ); 360 589 } 361 590 362 591 void Endpoint::libStart() throw(Error) 363 592 { 593 PJSUA2_CHECK_EXPR(pjsua_start()); 594 } 595 596 void Endpoint::libDestroy(unsigned flags) throw(Error) 597 { 364 598 pj_status_t status; 365 599 366 status = pjsua_start();367 PJSUA2_CHECK_RAISE_ERROR(status);368 }369 370 void Endpoint::libDestroy(unsigned flags) throw(Error)371 {372 pj_status_t status;373 374 600 status = pjsua_destroy2(flags); 375 601 602 delete this->writer; 376 603 this->writer = NULL; 377 this->epCallback = NULL;378 604 379 605 if (pj_log_get_log_func() == &Endpoint::logFunc) { … … 469 695 pj_ssl_cipher ciphers[64]; 470 696 unsigned count = PJ_ARRAY_SIZE(ciphers); 471 pj_status_t status; 472 473 status = pj_ssl_cipher_get_availables(ciphers, &count); 474 PJSUA2_CHECK_RAISE_ERROR(status); 697 698 PJSUA2_CHECK_EXPR( pj_ssl_cipher_get_availables(ciphers, &count) ); 475 699 476 700 return IntVector(ciphers, ciphers + count); … … 486 710 void Endpoint::natDetectType(void) throw(Error) 487 711 { 488 pj_status_t status; 489 490 status = pjsua_detect_nat_type(); 491 PJSUA2_CHECK_RAISE_ERROR(status); 712 PJSUA2_CHECK_EXPR( pjsua_detect_nat_type() ); 492 713 } 493 714 … … 495 716 { 496 717 pj_stun_nat_type type; 497 pj_status_t status; 498 499 status = pjsua_get_nat_type(&type); 500 PJSUA2_CHECK_RAISE_ERROR(status); 718 719 PJSUA2_CHECK_EXPR( pjsua_get_nat_type(&type) ); 501 720 502 721 return type; … … 509 728 pj_str_t srv[MAX_STUN_SERVERS]; 510 729 unsigned i, count = 0; 511 pj_status_t status;512 730 513 731 for (i=0; i<servers.size() && i<MAX_STUN_SERVERS; ++i) { … … 517 735 } 518 736 519 status = pjsua_resolve_stun_servers(count, srv, wait, token, 520 &Endpoint::stun_resolve_cb); 521 PJSUA2_CHECK_RAISE_ERROR(status); 737 PJSUA2_CHECK_EXPR(pjsua_resolve_stun_servers(count, srv, wait, token, 738 &Endpoint::stun_resolve_cb) ); 522 739 } 523 740 … … 525 742 bool notify_cb) throw(Error) 526 743 { 527 pj_status_t status; 528 529 status = pjsua_cancel_stun_resolution(token, notify_cb); 530 PJSUA2_CHECK_RAISE_ERROR(status); 744 PJSUA2_CHECK_EXPR( pjsua_cancel_stun_resolution(token, notify_cb) ); 531 745 } 532 746 … … 540 754 pjsua_transport_config tcfg; 541 755 pjsua_transport_id tid; 542 pj_status_t status;543 756 544 757 tcfg = cfg.toPj(); 545 status = pjsua_transport_create(type, &tcfg, &tid); 546 PJSUA2_CHECK_RAISE_ERROR(status); 758 PJSUA2_CHECK_EXPR( pjsua_transport_create(type, &tcfg, &tid) ); 547 759 548 760 return tid; … … 553 765 pjsua_transport_id tids[32]; 554 766 unsigned count = PJ_ARRAY_SIZE(tids); 555 pj_status_t status; 556 557 status = pjsua_enum_transports(tids, &count); 558 PJSUA2_CHECK_RAISE_ERROR(status); 767 768 PJSUA2_CHECK_EXPR( pjsua_enum_transports(tids, &count) ); 559 769 560 770 return IntVector(tids, tids+count); … … 564 774 { 565 775 pjsua_transport_info tinfo; 566 pj_status_t status; 567 568 status = pjsua_transport_get_info(id, &tinfo); 569 PJSUA2_CHECK_RAISE_ERROR(status); 776 777 PJSUA2_CHECK_EXPR( pjsua_transport_get_info(id, &tinfo) ); 570 778 571 779 return TransportInfo(tinfo); … … 574 782 void Endpoint::transportSetEnable(TransportId id, bool enabled) throw(Error) 575 783 { 576 pj_status_t status; 577 578 status = pjsua_transport_set_enable(id, enabled); 579 PJSUA2_CHECK_RAISE_ERROR(status); 784 PJSUA2_CHECK_EXPR( pjsua_transport_set_enable(id, enabled) ); 580 785 } 581 786 582 787 void Endpoint::transportClose(TransportId id) throw(Error) 583 788 { 584 pj_status_t status; 585 586 status = pjsua_transport_close(id, PJ_FALSE); 587 PJSUA2_CHECK_RAISE_ERROR(status); 588 } 589 590 /////////////////////////////////////////////////////////////////////////////// 591 789 PJSUA2_CHECK_EXPR( pjsua_transport_close(id, PJ_FALSE) ); 790 } 791 792 /////////////////////////////////////////////////////////////////////////////// 793 -
pjproject/branches/projects/pjsua2/pjsip/src/pjsua2/types.cpp
r4631 r4638 214 214 /////////////////////////////////////////////////////////////////////////////// 215 215 216 void SipRxData::fromPj(pjsip_rx_data &rdata) 217 { 218 info = pjsip_rx_data_get_info(&rdata); 219 wholeMsg = string(rdata.msg_info.msg_buf, rdata.msg_info.len); 220 srcIp = rdata.pkt_info.src_name; 221 srcPort = rdata.pkt_info.src_port; 222 } 223 224 /////////////////////////////////////////////////////////////////////////////// 225 216 226 void SipHeader::fromPj(const pjsip_hdr *hdr) throw(Error) 217 227 {
Note: See TracChangeset
for help on using the changeset viewer.