Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: WIFI_API_32kRAM mbed
MXmppClient.hpp
00001 /* Copyright (c) Cyntec Inc. All Rights Reserved.*/ 00002 00003 #ifndef XMPPCLIENT_H 00004 #define XMPPCLIENT_H 00005 00006 #include <string> 00007 #include "EthernetInterface.h" 00008 00009 /** XMPPClient class. 00010 used for linking XMPP server(above Openfire3.9.3). 00011 00012 Example: 00013 @code 00014 00015 WIFIDevice wifi; 00016 XMPPClient xmppClient("delta_nnn40_mod1","85.93.10.5","lester",5222); 00017 void on_get_mesage(const char*); 00018 DigitalOut led1(p0); 00019 00020 int main(void) 00021 { 00022 wifi.setNetwork("delta_ap", "password", 0); // set given SSID and PW as the highest priority 00023 xmppClient.login(); 00024 while(true) { 00025 xmppClient.set_message_tracker(on_get_mesage); 00026 } 00027 } 00028 00029 void on_get_mesage(const char *msg) 00030 { 00031 if(strcmp(msg,"turn on")==0) { 00032 xmppClient.send_message_to_client("delta_nnn40_android1","the led1 is already turned on"); 00033 led1=1; 00034 } else if(strcmp(msg,"turn off")==0) { 00035 xmppClient.send_message_to_client("delta_nnn40_android1","the led1 is already turned off"); 00036 led1=0; 00037 } 00038 } 00039 00040 @endcode 00041 */ 00042 00043 class MxmppClient 00044 { 00045 00046 private: 00047 00048 EthernetInterface eth; 00049 TCPSocketConnection socket; 00050 00051 char *userName; 00052 char *domain; 00053 char *resource; 00054 char *password; 00055 int port; 00056 char serverName[128]; 00057 00058 bool bLogin; 00059 00060 public: 00061 00062 /** Create XMPPClient instance*/ 00063 00064 MxmppClient(); 00065 00066 /** Create XMPPClient instance 00067 * @param user_name The username is for login XMPP server. 00068 * @param domain The domain is for server domain. 00069 * @param pwd The password is for login XMPP server. 00070 * @param port The port is XMPP server listen port. 00071 */ 00072 00073 MxmppClient(const char *userName,const char *domain,const char *pwd,const int port=5222); 00074 00075 /** Set user name which is for login XMPP server. 00076 * @param name The name is XMPP server account name. 00077 */ 00078 00079 void setUserName(const char *name); 00080 00081 /** Set domain which is server domain. 00082 * @param domain The domain is XMPP server domain. 00083 */ 00084 00085 void setDomain(const char *domain); 00086 00087 /** Set password which is for XMPP server login. 00088 * @param pwd The password is for XMPP server account. 00089 */ 00090 00091 void setPassword(const char *pwd); 00092 00093 /** Set port which is for server connection. 00094 * @param port The port is XMPP server listen port. 00095 */ 00096 00097 void setPort(const int num); 00098 00099 /** Get user name. 00100 * @returns 00101 * user name 00102 */ 00103 00104 const char *getUserName(); 00105 00106 /** Get domain. 00107 * @returns 00108 * domain 00109 */ 00110 00111 const char *getDomain(); 00112 00113 /** Get password. 00114 * @returns 00115 * password 00116 */ 00117 00118 const char *getPassword(); 00119 00120 /** Get port. 00121 * @returns 00122 * connection port 00123 */ 00124 00125 const int getPort(); 00126 00127 /** have fill user name? 00128 * @returns 00129 * true, have use name, 00130 * false, no use name 00131 */ 00132 00133 bool haveUserName(); 00134 00135 /** have fill domain? 00136 * @returns 00137 * true, have domain; 00138 * false, no domain 00139 */ 00140 00141 bool haveDomain(); 00142 00143 /** have fill password? 00144 * @returns 00145 * true, have password; 00146 * false, no password 00147 */ 00148 00149 bool havePassword(); 00150 00151 /** have fill port? 00152 * @returns 00153 * true, have connection port; 00154 * false, no connection port 00155 */ 00156 00157 bool havePort(); 00158 00159 /** have connect data which include username, domain, password and connect port? 00160 * @returns 00161 * true, have connection data; 00162 * false, no connection data 00163 */ 00164 00165 bool haveConnectData(); 00166 00167 /** Is login to XMPP server? 00168 * @returns 00169 * true, is already logged XMPP server; 00170 * false, is not yet logged XMPP server. 00171 */ 00172 00173 bool isLogin(); 00174 00175 /** login XMPP server, module will connect to XMPP server and execute login processes.*/ 00176 00177 void login(); 00178 00179 /** logout XMPP server, module will connect to XMPP server and execute logout processes.*/ 00180 00181 void logout(); 00182 00183 /** send message to other client 00184 * @param client client name, 00185 * @param chat_msg the sent message. 00186 */ 00187 00188 void sendMessageToClient(char *client,char* chatMsg); 00189 00190 /** set chat message listener 00191 * @param on_get_mesage callback function. 00192 */ 00193 00194 void setMessageTracker(void (*onGetMessage)(const char *msg)); 00195 00196 }; 00197 00198 #endif // XMPPCLIENT_H
Generated on Tue Jul 12 2022 22:56:04 by
1.7.2