引言:
目前还不清楚多线程如何操作。单线程基本清楚。libjingle软件比较稳定,开发中没遇到崩溃情况。
类定义
1. 线程操作
两类线程:
signaling thread
worker thread
(或
channel thread
)
2. 函数和方法
void OnStatusUpdate()
void OnSessionState()
3. 描述class
3.1.PresencePushTask类
描述:
接收好友状态信息
3.2.PresenceOutTask类
描述:
发送自己状态信息
XmppClientSettings
用户信息设置
3.3.Buzz::Status类
描述:
在线状态
状态类型如下:
enum Show {
SHOW_NONE = 0, // 离线
SHOW_NONE = 0, // 离线
SHOW_OFFLINE
= 1, //
离线
SHOW_XA
= 2,
SHOW_AWAY
= 3, //
空闲
SHOW_DND = 4, // 忙碌
SHOW_DND = 4, // 忙碌
SHOW_ONLINE
= 5, //
在线
SHOW_CHAT
= 6
}
}
方法:
Name
|
Description
|
String ShowStatus()
|
返回当前状态
(string)
|
Show show()
|
返回当前状态(
enum
)
|
jid()
|
返回
buzz::jid
类索引
|
3.4.Buzz::jid类
描述:
好友信息
方法:
Name
|
Description
|
node()
|
返回好友名
(string)
|
domain()
|
返回域名
(string) (
例如:
gmail.com)
|
resource()
|
返回资源
(string) (
例如:
Talk.v93E7FF603E)
|
3.5.buzz::XmppEngine 类
描述:
XMPP底层类。This class is a pure virtual class run and managed by XmppClient.
Sign in状态见下表(
buzz::XmppEngine::State
)
Value
|
Description
|
TATE_NONE
|
An error has occurred and the underlying engine could not be created.
|
STATE_START
|
Initial state: sign in has not yet begun.
|
TATE_OPENING
|
Sign in is proceding but not yet complete.
|
TATE_OPEN
|
Signed in to the server.
|
TATE_CLOSED
|
The sign in session has closed.
|
Socket错误状态:
Value
|
Description
|
ERROR_NONE
|
No error (OK).
|
ERROR_XML
|
Malformed XML error.
|
ERROR_STREAM
|
An XMPP stream error.
|
ERROR_VERSION
|
The XMPP version was incorrect.
|
ERROR_UNAUTHORIZED
|
The user's credentials have been rejected.
|
ERROR_TLS
|
A TLS connection could not be established.
|
ERROR_AUTH
|
Authentication could not be negotiated.
|
ERROR_BIND
|
The resource or session could not be bound.
|
ERROR_CONNECTION_CLOSED
|
The connection was closed unexpectedly (not by calling Disconnect).
|
ERROR_DOCUMENT_CLOSED
|
Connection colsed by </stream:stream>. Call GetStreamError for details.
|
ERROR_SOCKET
|
Unspecified socket error.
|
buzz::XmppEngine::HandlerLevel
状态值:
HL_NONE
|
|
HL_PEEK
|
Sees messages before all other processing; cannot abort.
|
HL_SINGLE
|
Watches for a single message, e.g., by id and sender.
|
HL_SENDER
|
Watches for a type of message from a specific sender.
|
HL_TYPE
|
Watches a type of message, e.g., all groupchat msgs.
|
HL_ALL
|
Watches all messages - gets last shot.
|
HL_COUNT
|
Count of handler levels.
|
3.6.Buzz:: XmlElement类
常量定义:
Name
|
Description
|
QN_MESSAGE
|
|
QN_TYPE
|
|
QN_FROM
|
|
QN_MSG
|
|
|
|
常用方法如下:
Name
|
Description
|
Name
|
|
Attr
|
|
|
|
3.7. XmppPump类
描述:
该类创建XmppClient和处理Sign in事务。
主要方法见下表:
Name
|
Description
|
XmppPump
(XmppPumpNotify * notify)
|
Constructor.
·
notify
Pointer to an object that will receive progress notifications in its OnStateChange method.
|
buzz::XmppClient *client()
|
Returns the internal XmppClient member.
|
void DoLogin(const buzz::XmppClientSettings & xcs, buzz::AsyncSocket* socket, buzz::PreXmppAuth* auth);
|
Starts asynchronous sign in to the server specified. You must catch the XmppClient::SignalStateChange signal to track progress.
·
xcs
Settings for the connection, including host name, password, and sign-in name.
·
socket
A socket to handle the connection. For signing on to a XMPP server, create a new XmppSocket object.
auth
Optional authorization information for signing in, such as captcha informatin, authorization cookies, and so on. If not using, specify 0 (zero).
Gtalk
登录
|
void DoDisconnect();
|
Disconnects from the server and sends notifications on the progress, similar to DoLogin.
Gtalk
退出
|
void OnStateChange(buzz::XmppEngine::State state);
|
Called with notifications about the progress of the sign-in attempt. You can override this method if extending this class.
自己状态变化检测
|
void WakeTasks();
|
Called internally.
|
int64 CurrentTime();
|
Called internally.
|
void OnMessage(cricket::Message *pmsg);
|
Called internally with asynchronous messages.
|
buzz::XmppReturnStatus SendStanza(const buzz::XmlElement *stanza);
|
Sends a stanza out through the XmppClient member.
发送消息到
peer
|
3.7.1. 发送消息到好友举例:
sprintf(buff12,
"hi,SME Jingle is wating for you!/n -----Input '??' for help information./n -----Input 'alllist' for CPE list /n");
buzz::XmlElement *message
= new buzz::XmlElement(buzz::QN_MESSAGE);
message->AddAttr(buzz::QN_FROM,xmpp_client_->jid().Str());
message->AddAttr(buzz::QN_TO,status.jid().Str());
message->AddAttr(buzz::QN_TYPE,buzz::STR_CHAT);
message->AddElement(new buzz::XmlElement(buzz::QN_BODY));
message->AddText(buff12,1);
xmpp_client_->SendStanza(message);
3.8. talk_base::MessageHandler类
描述:
被很多类继承。
方法如下:
Name
|
Description
|
Virtual OnMessage()
|
虚函数
|
3.9. talk_base::Message类
描述:
变量:
Value
|
Description
|
message_id
|
Uint32
|
|
|
方法如下:
Name
|
Description
|
|
|
3.10. Buzz::XmppTask类
描述:
方法如下:
Name
|
Description
|
ProcessStart
|
在
HandleStanza
后运行。
|
HandleStanza
|
处理接收的消息。
返回
true,
接着执行
ProcessStart
返回
false
,则继续处理下一条
|
4. 开发
可以在例子PCP基础上修改。或者下载freetalk 1.9软件。