libjingle學習

 
引言:
    目前還不清楚多線程如何操作。單線程基本清楚。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_OFFLINE = 1,    //離線
SHOW_XA = 2,
SHOW_AWAY = 3,     //空閒
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軟件。
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章