4905dbbe6c
Currently, add-ons are disconnected when ChatProtocol::Shutdown() is called, which the add-on can do by itself― but there is no standard way for add-ons to notify the app about their Shutdown. Because of this, they tend to not call Shutdown()― instead (as in the case of the Jabber add-on), they display a BAlert (IM_ERROR) notifying the user of the connection error, but the account is considered active by Cardie (and its threads are still existant, including its ProtocolLooper). Zombies are bad, so this is redesigned somewhat with this commit: Protocols should no longer call ChatProtocol::Shutdown() themselves, they must send an IM_MESSAGE of IM_PROTOCOL_DISABLE to the app. This will delete its ProtocolLooper, which in turn will send a notification to the user and delete the ChatProtocol, and so calling ChatProtocol::Shutdown(). In the included protocols, an IM_ERROR is sent right before IM_PROTOCOL_DISABLE is sent if due to a connection error. This is not required, but it is courteous to inform your user about the "why." :)
103 lines
2.7 KiB
C++
103 lines
2.7 KiB
C++
/*
|
|
* Copyright 2009-2011, Andrea Anzani. All rights reserved.
|
|
* Copyright 2009-2011, Pier Luigi Fiorini. All rights reserved.
|
|
* Distributed under the terms of the MIT License.
|
|
*/
|
|
#ifndef _SERVER_H
|
|
#define _SERVER_H
|
|
|
|
#include <Message.h>
|
|
#include <MessageFilter.h>
|
|
#include <Notification.h>
|
|
|
|
#include <libsupport/KeyMap.h>
|
|
|
|
#include "AppConstants.h"
|
|
#include "ChatCommand.h"
|
|
#include "Contact.h"
|
|
#include "Conversation.h"
|
|
#include "ProtocolLooper.h"
|
|
#include "User.h"
|
|
|
|
class ChatProtocol;
|
|
class RosterItem;
|
|
class ProtocolLooper;
|
|
|
|
|
|
typedef KeyMap<bigtime_t, ProtocolLooper*> ProtocolLoopers;
|
|
typedef KeyMap<BString, bigtime_t> AccountInstances;
|
|
|
|
|
|
class Server: public BMessageFilter {
|
|
public:
|
|
Server();
|
|
void Quit();
|
|
void LoginAll();
|
|
|
|
virtual filter_result Filter(BMessage* message, BHandler** target);
|
|
filter_result ImMessage(BMessage* msg);
|
|
void ImError(BMessage* msg);
|
|
|
|
void AddProtocolLooper(bigtime_t instanceId,
|
|
ChatProtocol* cayap);
|
|
void RemoveProtocolLooper(bigtime_t instanceId);
|
|
ProtocolLooper* GetProtocolLooper(bigtime_t instanceId);
|
|
|
|
AccountInstances
|
|
GetAccounts();
|
|
|
|
void SendProtocolMessage(BMessage* msg);
|
|
void SendAllProtocolMessage(BMessage* msg);
|
|
|
|
RosterMap Contacts() const;
|
|
Contact* ContactById(BString id, int64 instance);
|
|
void AddContact(Contact* contact, int64 instance);
|
|
|
|
UserMap Users() const;
|
|
User* UserById(BString id, int64 instance);
|
|
void AddUser(User* user, int64 instance);
|
|
|
|
ChatMap Conversations() const;
|
|
Conversation* ConversationById(BString id, int64 instance);
|
|
void AddConversation(Conversation* chat, int64 instance);
|
|
|
|
ChatCommand* CommandById(BString id, int64 instance);
|
|
|
|
BObjectList<BMessage> ChatPopUpItems();
|
|
BObjectList<BMessage> UserPopUpItems();
|
|
|
|
private:
|
|
ProtocolLooper* _LooperFromMessage(BMessage* message);
|
|
|
|
Contact* _EnsureContact(BMessage* message);
|
|
User* _EnsureUser(BMessage* message);
|
|
User* _EnsureUser(BString id, ProtocolLooper* protoLooper);
|
|
Contact* _GetOwnContact(BMessage* message);
|
|
Conversation* _EnsureConversation(BMessage* message);
|
|
|
|
Role* _GetRole(BMessage* msg);
|
|
|
|
void _ProtocolNotification(ProtocolLooper* looper,
|
|
BString title, BString desc,
|
|
notification_type type=B_INFORMATION_NOTIFICATION);
|
|
void _SendNotification(BString title, BString content,
|
|
BBitmap* icon=NULL,
|
|
notification_type type=B_INFORMATION_NOTIFICATION);
|
|
|
|
void _ReplicantStatusNotify(UserStatus status);
|
|
|
|
ProtocolLoopers fLoopers;
|
|
AccountInstances
|
|
fAccounts;
|
|
|
|
CommandMap fCommands;
|
|
BObjectList<BMessage>
|
|
fChatItems;
|
|
BObjectList<BMessage>
|
|
fUserItems;
|
|
};
|
|
|
|
|
|
#endif // _SERVER_H
|
|
|