| OLD | NEW | 
| (Empty) |  | 
 |    1 // Copyright 2004 The Chromium Authors. All rights reserved. | 
 |    2 // Use of this source code is governed by a BSD-style license that can be | 
 |    3 // found in the LICENSE file. | 
 |    4  | 
 |    5 #ifndef WEBRTC_LIBJINGLE_XMPP_CHATROOMMODULE_H_ | 
 |    6 #define WEBRTC_LIBJINGLE_XMPP_CHATROOMMODULE_H_ | 
 |    7  | 
 |    8 #include "third_party/xmpp/module.h" | 
 |    9 #include "third_party/xmpp/rostermodule.h" | 
 |   10  | 
 |   11 namespace buzz { | 
 |   12  | 
 |   13 // forward declarations | 
 |   14 class XmppChatroomModule; | 
 |   15 class XmppChatroomHandler; | 
 |   16 class XmppChatroomMember; | 
 |   17 class XmppChatroomMemberEnumerator; | 
 |   18  | 
 |   19 enum XmppChatroomState { | 
 |   20   XMPP_CHATROOM_STATE_NOT_IN_ROOM      = 0, | 
 |   21   XMPP_CHATROOM_STATE_REQUESTED_ENTER  = 1, | 
 |   22   XMPP_CHATROOM_STATE_IN_ROOM          = 2, | 
 |   23   XMPP_CHATROOM_STATE_REQUESTED_EXIT   = 3, | 
 |   24 }; | 
 |   25  | 
 |   26 //! Module that encapsulates a chatroom. | 
 |   27 class XmppChatroomModule : public XmppModule { | 
 |   28 public: | 
 |   29  | 
 |   30   //! Creates a new XmppChatroomModule | 
 |   31   static XmppChatroomModule* Create(); | 
 |   32   virtual ~XmppChatroomModule() {} | 
 |   33  | 
 |   34   //! Sets the chatroom handler (callbacks) for the chatroom | 
 |   35   virtual XmppReturnStatus set_chatroom_handler(XmppChatroomHandler* handler) = 
     0; | 
 |   36  | 
 |   37   //! Gets the chatroom handler for the module | 
 |   38   virtual XmppChatroomHandler* chatroom_handler() = 0; | 
 |   39  | 
 |   40   //! Sets the jid of the chatroom. | 
 |   41   //! Has to be set before entering the chatroom and can't be changed | 
 |   42   //! while in the chatroom | 
 |   43   virtual XmppReturnStatus set_chatroom_jid(const Jid& chatroom_jid) = 0; | 
 |   44  | 
 |   45   //! The jid for the chatroom | 
 |   46   virtual const Jid& chatroom_jid() const = 0; | 
 |   47  | 
 |   48   //! Sets the nickname of the member | 
 |   49   //! Has to be set before entering the chatroom and can't be changed | 
 |   50   //! while in the chatroom | 
 |   51   virtual XmppReturnStatus set_nickname(const std::string& nickname) = 0; | 
 |   52  | 
 |   53   //! The nickname of the member in the chatroom | 
 |   54   virtual const std::string& nickname() const = 0; | 
 |   55  | 
 |   56   //! Returns the jid of the member (this is the chatroom_jid plus the | 
 |   57   //! nickname as the resource name) | 
 |   58   virtual const Jid member_jid() const = 0; | 
 |   59  | 
 |   60   //! Requests that the user enter a chatroom | 
 |   61   //! The EnterChatroom callback will be called when the request is complete. | 
 |   62   //! Password should be empty for a room that doesn't require a password | 
 |   63   //! If the room doesn't exist, the server will create an "Instant Room" if the | 
 |   64   //! server policy supports this action. | 
 |   65   //! There will be different methods for creating/configuring a "Reserved Room" | 
 |   66   //! Async callback for this method is ChatroomEnteredStatus | 
 |   67   virtual XmppReturnStatus RequestEnterChatroom(const std::string& password, | 
 |   68       const std::string& client_version, | 
 |   69       const std::string& locale) = 0; | 
 |   70  | 
 |   71   //! Requests that the user exit a chatroom | 
 |   72   //! Async callback for this method is ChatroomExitedStatus | 
 |   73   virtual XmppReturnStatus RequestExitChatroom() = 0; | 
 |   74  | 
 |   75   //! Requests a status change | 
 |   76   //! status is the standard XMPP status code | 
 |   77   //! extended_status is the extended status when status is XMPP_PRESENCE_XA | 
 |   78   virtual XmppReturnStatus RequestConnectionStatusChange( | 
 |   79       XmppPresenceConnectionStatus connection_status) = 0; | 
 |   80  | 
 |   81   //! Returns the number of members in the room | 
 |   82   virtual size_t GetChatroomMemberCount() = 0; | 
 |   83  | 
 |   84   //! Gets an enumerator for the members in the chatroom | 
 |   85   //! The caller must delete the enumerator when the caller is finished with it. | 
 |   86   //! The caller must also ensure that the lifetime of the enumerator is | 
 |   87   //! scoped by the XmppChatRoomModule that created it. | 
 |   88   virtual XmppReturnStatus CreateMemberEnumerator(XmppChatroomMemberEnumerator**
      enumerator) = 0; | 
 |   89  | 
 |   90   //! Gets the subject of the chatroom | 
 |   91   virtual const std::string subject() = 0; | 
 |   92  | 
 |   93   //! Returns the current state of the user with respect to the chatroom | 
 |   94   virtual XmppChatroomState state() = 0; | 
 |   95  | 
 |   96   virtual XmppReturnStatus SendMessage(const XmlElement& message) = 0; | 
 |   97 }; | 
 |   98  | 
 |   99 //! Class for enumerating participatns | 
 |  100 class XmppChatroomMemberEnumerator { | 
 |  101 public: | 
 |  102   virtual ~XmppChatroomMemberEnumerator() { } | 
 |  103   //! Returns the member at the current position | 
 |  104   //! Returns null if the enumerator is before the beginning | 
 |  105   //! or after the end of the collection | 
 |  106   virtual XmppChatroomMember* current() = 0; | 
 |  107  | 
 |  108   //! Returns whether the enumerator is valid | 
 |  109   //! This returns true if the collection has changed | 
 |  110   //! since the enumerator was created | 
 |  111   virtual bool IsValid() = 0; | 
 |  112  | 
 |  113   //! Returns whether the enumerator is before the beginning | 
 |  114   //! This is the initial state of the enumerator | 
 |  115   virtual bool IsBeforeBeginning() = 0; | 
 |  116  | 
 |  117   //! Returns whether the enumerator is after the end | 
 |  118   virtual bool IsAfterEnd() = 0; | 
 |  119  | 
 |  120   //! Advances the enumerator to the next position | 
 |  121   //! Returns false is the enumerator is advanced | 
 |  122   //! off the end of the collection | 
 |  123   virtual bool Next() = 0; | 
 |  124  | 
 |  125   //! Advances the enumerator to the previous position | 
 |  126   //! Returns false is the enumerator is advanced | 
 |  127   //! off the end of the collection | 
 |  128   virtual bool Prev() = 0; | 
 |  129 }; | 
 |  130  | 
 |  131  | 
 |  132 //! Represents a single member in a chatroom | 
 |  133 class XmppChatroomMember { | 
 |  134 public: | 
 |  135   virtual ~XmppChatroomMember() { } | 
 |  136  | 
 |  137   //! The jid for the member in the chatroom | 
 |  138   virtual const Jid member_jid() const = 0; | 
 |  139  | 
 |  140   //! The full jid for the member | 
 |  141   //! This is only available in non-anonymous rooms. | 
 |  142   //! If the room is anonymous, this returns JID_EMPTY | 
 |  143   virtual const Jid full_jid() const = 0; | 
 |  144  | 
 |  145    //! Returns the backing presence for this member | 
 |  146   virtual const XmppPresence* presence() const = 0; | 
 |  147  | 
 |  148   //! The nickname for this member | 
 |  149   virtual const std::string name() const = 0; | 
 |  150 }; | 
 |  151  | 
 |  152 //! Status codes for ChatroomEnteredStatus callback | 
 |  153 enum XmppChatroomEnteredStatus | 
 |  154 { | 
 |  155   //! User successfully entered the room | 
 |  156   XMPP_CHATROOM_ENTERED_SUCCESS                    = 0, | 
 |  157   //! The nickname confliced with somebody already in the room | 
 |  158   XMPP_CHATROOM_ENTERED_FAILURE_NICKNAME_CONFLICT  = 1, | 
 |  159   //! A password is required to enter the room | 
 |  160   XMPP_CHATROOM_ENTERED_FAILURE_PASSWORD_REQUIRED  = 2, | 
 |  161   //! The specified password was incorrect | 
 |  162   XMPP_CHATROOM_ENTERED_FAILURE_PASSWORD_INCORRECT = 3, | 
 |  163   //! The user is not a member of a member-only room | 
 |  164   XMPP_CHATROOM_ENTERED_FAILURE_NOT_A_MEMBER       = 4, | 
 |  165   //! The user cannot enter because the user has been banned | 
 |  166   XMPP_CHATROOM_ENTERED_FAILURE_MEMBER_BANNED      = 5, | 
 |  167   //! The room has the maximum number of users already | 
 |  168   XMPP_CHATROOM_ENTERED_FAILURE_MAX_USERS          = 6, | 
 |  169   //! The room has been locked by an administrator | 
 |  170   XMPP_CHATROOM_ENTERED_FAILURE_ROOM_LOCKED        = 7, | 
 |  171   //! Someone in the room has blocked you | 
 |  172   XMPP_CHATROOM_ENTERED_FAILURE_MEMBER_BLOCKED     = 8, | 
 |  173   //! You have blocked someone in the room | 
 |  174   XMPP_CHATROOM_ENTERED_FAILURE_MEMBER_BLOCKING    = 9, | 
 |  175   //! Client is old. User must upgrade to a more recent version for | 
 |  176   // hangouts to work. | 
 |  177   XMPP_CHATROOM_ENTERED_FAILURE_OUTDATED_CLIENT    = 10, | 
 |  178   //! Some other reason | 
 |  179   XMPP_CHATROOM_ENTERED_FAILURE_UNSPECIFIED        = 2000, | 
 |  180 }; | 
 |  181  | 
 |  182 //! Status codes for ChatroomExitedStatus callback | 
 |  183 enum XmppChatroomExitedStatus | 
 |  184 { | 
 |  185   //! The user requested to exit and did so | 
 |  186   XMPP_CHATROOM_EXITED_REQUESTED                   = 0, | 
 |  187   //! The user was banned from the room | 
 |  188   XMPP_CHATROOM_EXITED_BANNED                      = 1, | 
 |  189   //! The user has been kicked out of the room | 
 |  190   XMPP_CHATROOM_EXITED_KICKED                      = 2, | 
 |  191   //! The user has been removed from the room because the | 
 |  192   //! user is no longer a member of a member-only room | 
 |  193   //! or the room has changed to membership-only | 
 |  194   XMPP_CHATROOM_EXITED_NOT_A_MEMBER                = 3, | 
 |  195   //! The system is shutting down | 
 |  196   XMPP_CHATROOM_EXITED_SYSTEM_SHUTDOWN             = 4, | 
 |  197   //! For some other reason | 
 |  198   XMPP_CHATROOM_EXITED_UNSPECIFIED                 = 5, | 
 |  199 }; | 
 |  200  | 
 |  201 //! The XmppChatroomHandler is the interface for callbacks from the | 
 |  202 //! the chatroom | 
 |  203 class XmppChatroomHandler { | 
 |  204 public: | 
 |  205   virtual ~XmppChatroomHandler() {} | 
 |  206  | 
 |  207   //! Indicates the response to RequestEnterChatroom method | 
 |  208   //! XMPP_CHATROOM_SUCCESS represents success. | 
 |  209   //! Other status codes are for errors | 
 |  210   virtual void ChatroomEnteredStatus(XmppChatroomModule* room, | 
 |  211                                      const XmppPresence* presence, | 
 |  212                                      XmppChatroomEnteredStatus status) = 0; | 
 |  213  | 
 |  214  | 
 |  215   //! Indicates that the user has exited the chatroom, either due to | 
 |  216   //! a call to RequestExitChatroom or for some other reason. | 
 |  217   //! status indicates the reason the user exited | 
 |  218   virtual void ChatroomExitedStatus(XmppChatroomModule* room, | 
 |  219                                     XmppChatroomExitedStatus status) = 0; | 
 |  220  | 
 |  221   //! Indicates a member entered the room. | 
 |  222   //! It can be called before ChatroomEnteredStatus. | 
 |  223   virtual void MemberEntered(XmppChatroomModule* room, | 
 |  224                                   const XmppChatroomMember* entered_member) = 0; | 
 |  225  | 
 |  226   //! Indicates that a member exited the room. | 
 |  227   virtual void MemberExited(XmppChatroomModule* room, | 
 |  228                               const XmppChatroomMember* exited_member) = 0; | 
 |  229  | 
 |  230   //! Indicates that the data for the member has changed | 
 |  231   //! (such as the nickname or presence) | 
 |  232   virtual void MemberChanged(XmppChatroomModule* room, | 
 |  233                              const XmppChatroomMember* changed_member) = 0; | 
 |  234  | 
 |  235   //! Indicates a new message has been received | 
 |  236   //! message is the message - | 
 |  237   // $TODO - message should be changed | 
 |  238   //! to a strongly-typed message class that contains info | 
 |  239   //! such as the sender, message bodies, etc., | 
 |  240   virtual void MessageReceived(XmppChatroomModule* room, | 
 |  241                                const XmlElement& message) = 0; | 
 |  242 }; | 
 |  243  | 
 |  244  | 
 |  245 } | 
 |  246  | 
 |  247 #endif  // WEBRTC_LIBJINGLE_XMPP_CHATROOMMODULE_H_ | 
| OLD | NEW |