3
* Copyright 2006, Google Inc.
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions are met:
8
* 1. Redistributions of source code must retain the above copyright notice,
9
* this list of conditions and the following disclaimer.
10
* 2. Redistributions in binary form must reproduce the above copyright notice,
11
* this list of conditions and the following disclaimer in the documentation
12
* and/or other materials provided with the distribution.
13
* 3. The name of the author may not be used to endorse or promote products
14
* derived from this software without specific prior written permission.
16
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
// LibjinglePlus is a class that connects to Google Talk, creates
29
// some common tasks, and emits signals when things change
31
#ifndef LIBJINGLEPLUS_H__
32
#define LIBJINGLEPLUS_H__
34
#include "talk/base/basicdefs.h"
35
#include "talk/app/rosteritem.h"
36
#include "talk/app/message.h"
37
#include "talk/app/status.h"
38
#include "talk/xmpp/xmppengine.h"
39
#include "talk/base/scoped_ptr.h"
42
class LibjinglePlusWorker;
44
class LibjinglePlusNotify {
46
virtual ~LibjinglePlusNotify() {}
48
/* Libjingle+ works on its own thread. It will call WakeupMainThread
49
* when it has something to report. The main thread should then wake up,
50
* and call DoCallbacks on the LibjinglePlus object.
52
* This function gets called from libjingle+'s worker thread. All other
53
* methods in LibjinglePlusNotify get called from the thread you call
56
* If running on Windows, libjingle+ will use Windows messages to generate
57
* callbacks from the main thread, and you don't need to do anything here.
59
virtual void WakeupMainThread() = 0;
62
/* Called when the connection state changes */
63
virtual void OnStateChange(buzz::XmppEngine::State) = 0;
65
/* Called when the socket closes */
66
virtual void OnSocketClose(int error_code) = 0;
68
/* Called when XMPP is being sent or received. Used for debugging */
69
virtual void OnXmppOutput(const std::string &output) = 0;
70
virtual void OnXmppInput(const std::string &input) = 0;
73
/* Called when someone's Status is updated */
74
virtual void OnStatusUpdate(const buzz::Status &status) = 0;
76
/* Called when a status update results in an error */
77
virtual void OnStatusError(const buzz::XmlElement &stanza) = 0;
79
/* Called with an IQ return code */
80
virtual void OnIqDone(bool success, const buzz::XmlElement &stanza) = 0;
83
/* Called when a message comes in. */
84
virtual void OnMessage(const buzz::XmppMessage &message) = 0;
88
/* Called when we start refreshing the roster */
89
virtual void OnRosterRefreshStarted() = 0;
90
/* Called when we have the entire roster */
91
virtual void OnRosterRefreshFinished() = 0;
92
/* Called when an item on the roster is created or updated */
93
virtual void OnRosterItemUpdated(const buzz::RosterItem &ri) = 0;
94
/* Called when an item on the roster is removed */
95
virtual void OnRosterItemRemoved(const buzz::RosterItem &ri) = 0;
98
virtual void OnRosterSubscribe(const buzz::Jid &jid) = 0;
99
virtual void OnRosterUnsubscribe(const buzz::Jid &jid) = 0;
100
virtual void OnRosterSubscribed(const buzz::Jid &jid) = 0;
101
virtual void OnRosterUnsubscribed(const buzz::Jid &jid) = 0;
108
/* Provide the constructor with your interface. */
109
LibjinglePlus(LibjinglePlusNotify *notify);
112
/* Logs in and starts doing stuff
114
* If cookie_auth is true, password must be a Gaia SID. Otherwise,
115
* it should be the user's password
117
void Login(const std::string &username, const std::string &password,
118
const std::string &machine_address, bool is_test, bool cookie_auth);
121
void SendPresence(const buzz::Status & s);
122
void SendDirectedPresence(const buzz::Jid & j, const buzz::Status & s);
123
void SendDirectedMUCPresence(const buzz::Jid & j, const buzz::Status & s,
124
const std::string &user_nick, const std::string &api_capability,
125
const std::string &api_message, const std::string &role);
128
void SendXmppMessage(const buzz::XmppMessage & m);
131
void SendXmppIq(const buzz::Jid &to_jid, bool is_get,
132
const buzz::XmlElement *iq_element);
135
void UpdateRosterItem(const buzz::Jid & jid, const std::string & name,
136
const std::vector<std::string> & groups, buzz::GrType grt);
137
void RemoveRosterItem(const buzz::Jid &jid);
139
/* Call this from the thread you want to receive callbacks on. Typically, this will be called
140
* after your WakeupMainThread() notify function is called.
142
* On Windows, libjingle+ will trigger its callback from the Windows message loop, and
143
* you needn't call this yourself.
148
void LoginInternal(const std::string &jid, const std::string &password,
149
const std::string &machine_address, bool is_test);
151
LibjinglePlusWorker *worker_;
154
#endif // LIBJINGLE_PLUS_H__