~ubuntu-branches/debian/experimental/kopete/experimental

« back to all changes in this revision

Viewing changes to protocols/jabber/libjingle/talk/examples/plus/libjingleplus.h

  • Committer: Package Import Robot
  • Author(s): Maximiliano Curia
  • Date: 2015-02-24 11:32:57 UTC
  • mfrom: (1.1.41 vivid)
  • Revision ID: package-import@ubuntu.com-20150224113257-gnupg4v7lzz18ij0
Tags: 4:14.12.2-1
* New upstream release (14.12.2).
* Bump Standards-Version to 3.9.6, no changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * libjingle
 
3
 * Copyright 2006, Google Inc.
 
4
 *
 
5
 * Redistribution and use in source and binary forms, with or without
 
6
 * modification, are permitted provided that the following conditions are met:
 
7
 *
 
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.
 
15
 *
 
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.
 
26
 */
 
27
 
 
28
// LibjinglePlus is a class that connects to Google Talk, creates
 
29
// some common tasks, and emits signals when things change
 
30
 
 
31
#ifndef LIBJINGLEPLUS_H__
 
32
#define LIBJINGLEPLUS_H__
 
33
 
 
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"
 
40
 
 
41
 
 
42
class LibjinglePlusWorker;
 
43
 
 
44
class LibjinglePlusNotify {
 
45
 public:
 
46
  virtual ~LibjinglePlusNotify() {}
 
47
 
 
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.
 
51
   *
 
52
   * This function gets called from libjingle+'s worker thread. All other
 
53
   * methods in LibjinglePlusNotify get called from the thread you call
 
54
   * DoCallbacks() on.
 
55
   *
 
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.
 
58
   */
 
59
  virtual void WakeupMainThread() = 0;
 
60
 
 
61
  /* Connection */
 
62
  /* Called when the connection state changes */
 
63
  virtual void OnStateChange(buzz::XmppEngine::State) = 0;
 
64
 
 
65
  /* Called when the socket closes */
 
66
  virtual void OnSocketClose(int error_code) = 0;
 
67
 
 
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;
 
71
 
 
72
  /* Presence */
 
73
  /* Called when someone's Status is updated */
 
74
  virtual void OnStatusUpdate(const buzz::Status &status) = 0;
 
75
 
 
76
  /* Called when a status update results in an error */
 
77
  virtual void OnStatusError(const buzz::XmlElement &stanza) = 0;
 
78
 
 
79
  /* Called with an IQ return code */
 
80
  virtual void OnIqDone(bool success, const buzz::XmlElement &stanza) = 0;
 
81
 
 
82
  /* Message */
 
83
  /* Called when a message comes in. */
 
84
  virtual void OnMessage(const buzz::XmppMessage &message) = 0;
 
85
 
 
86
  /* Roster */
 
87
 
 
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;
 
96
 
 
97
  /* Subscriptions */
 
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;
 
102
 
 
103
};
 
104
 
 
105
class LibjinglePlus 
 
106
{
 
107
 public:
 
108
  /* Provide the constructor with your interface. */
 
109
  LibjinglePlus(LibjinglePlusNotify *notify);
 
110
  ~LibjinglePlus();
 
111
 
 
112
  /* Logs in and starts doing stuff 
 
113
   *
 
114
   * If cookie_auth is true, password must be a Gaia SID. Otherwise,
 
115
   * it should be the user's password
 
116
   */
 
117
  void Login(const std::string &username, const std::string &password,
 
118
             const std::string &machine_address, bool is_test, bool cookie_auth);
 
119
 
 
120
  /* Set Presence */
 
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);
 
126
 
 
127
  /* Send Message */
 
128
  void SendXmppMessage(const buzz::XmppMessage & m);
 
129
 
 
130
  /* Send IQ */
 
131
  void SendXmppIq(const buzz::Jid &to_jid, bool is_get,
 
132
                  const buzz::XmlElement *iq_element);
 
133
 
 
134
  /* Set Roster */
 
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);
 
138
 
 
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.
 
141
   *
 
142
   * On Windows, libjingle+ will trigger its callback from the Windows message loop, and
 
143
   * you needn't call this yourself.
 
144
   */
 
145
  void DoCallbacks();
 
146
 
 
147
 private:
 
148
  void LoginInternal(const std::string &jid, const std::string &password,
 
149
                     const std::string &machine_address, bool is_test);
 
150
 
 
151
  LibjinglePlusWorker *worker_;
 
152
};
 
153
 
 
154
#endif  // LIBJINGLE_PLUS_H__