2010-05-07 04:47:10 -05:00
|
|
|
/*
|
2011-12-03 16:38:03 -06:00
|
|
|
* Copyright 2009-2011, Andrea Anzani. All rights reserved.
|
|
|
|
* Copyright 2009-2011, Pier Luigi Fiorini. All rights reserved.
|
2010-05-07 04:47:10 -05:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
|
|
|
#ifndef _SERVER_H
|
|
|
|
#define _SERVER_H
|
|
|
|
|
|
|
|
#include <Message.h>
|
|
|
|
#include <MessageFilter.h>
|
|
|
|
|
2010-05-08 14:35:28 -05:00
|
|
|
#include <libsupport/KeyMap.h>
|
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
#include "CayaConstants.h"
|
2021-05-23 14:39:07 -05:00
|
|
|
#include "Contact.h"
|
2021-05-24 01:47:21 -05:00
|
|
|
#include "Conversation.h"
|
2021-05-31 11:56:45 -05:00
|
|
|
#include "User.h"
|
2010-05-07 04:47:10 -05:00
|
|
|
|
2010-05-16 16:02:50 -05:00
|
|
|
class CayaProtocol;
|
2010-05-07 04:47:10 -05:00
|
|
|
class RosterItem;
|
2010-05-16 16:02:50 -05:00
|
|
|
class ProtocolLooper;
|
2010-05-07 04:47:10 -05:00
|
|
|
|
2021-05-27 11:15:30 -05:00
|
|
|
|
2021-05-23 14:39:07 -05:00
|
|
|
typedef KeyMap<BString, Contact*> RosterMap;
|
2021-05-31 11:56:45 -05:00
|
|
|
typedef KeyMap<BString, User*> UserMap;
|
2021-05-24 01:47:21 -05:00
|
|
|
typedef KeyMap<BString, Conversation*> ChatMap;
|
2010-05-16 16:02:50 -05:00
|
|
|
typedef KeyMap<bigtime_t, ProtocolLooper*> ProtocolLoopers;
|
2021-06-01 21:43:19 -05:00
|
|
|
typedef KeyMap<BString, bigtime_t> AccountInstances;
|
2010-05-07 04:47:10 -05:00
|
|
|
|
2021-05-27 11:15:30 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
class Server: public BMessageFilter {
|
|
|
|
public:
|
2010-05-16 16:02:50 -05:00
|
|
|
Server();
|
2021-05-31 13:04:58 -05:00
|
|
|
void Quit();
|
|
|
|
void LoginAll();
|
2010-05-07 04:47:10 -05:00
|
|
|
|
|
|
|
virtual filter_result Filter(BMessage* message, BHandler** target);
|
|
|
|
filter_result ImMessage(BMessage* msg);
|
|
|
|
|
2010-05-20 16:31:55 -05:00
|
|
|
void AddProtocolLooper(bigtime_t instanceId,
|
|
|
|
CayaProtocol* cayap);
|
2010-05-16 16:02:50 -05:00
|
|
|
void RemoveProtocolLooper(bigtime_t instanceId);
|
2021-06-01 21:43:19 -05:00
|
|
|
ProtocolLooper* GetProtocolLooper(bigtime_t instanceId);
|
|
|
|
|
|
|
|
AccountInstances
|
|
|
|
GetAccounts();
|
2010-05-07 04:47:10 -05:00
|
|
|
|
|
|
|
void SendProtocolMessage(BMessage* msg);
|
2010-05-16 16:02:50 -05:00
|
|
|
void SendAllProtocolMessage(BMessage* msg);
|
2010-05-07 04:47:10 -05:00
|
|
|
|
2021-05-24 01:47:21 -05:00
|
|
|
RosterMap Contacts() const;
|
|
|
|
Contact* ContactById(BString id);
|
|
|
|
void AddContact(Contact* contact);
|
|
|
|
|
2021-05-31 11:56:45 -05:00
|
|
|
UserMap Users() const;
|
|
|
|
User* UserById(BString id);
|
|
|
|
void AddUser(User* user);
|
|
|
|
|
2021-05-24 01:47:21 -05:00
|
|
|
ChatMap Conversations() const;
|
|
|
|
Conversation* ConversationById(BString id);
|
|
|
|
void AddConversation(Conversation* chat);
|
2010-05-07 04:47:10 -05:00
|
|
|
|
2010-05-20 16:31:55 -05:00
|
|
|
// TODO: there should be a contact for each account.
|
2021-05-31 13:04:58 -05:00
|
|
|
BString GetOwnContact();
|
2010-05-07 04:47:10 -05:00
|
|
|
|
|
|
|
private:
|
2011-12-14 17:36:27 -06:00
|
|
|
ProtocolLooper* _LooperFromMessage(BMessage* message);
|
2021-05-31 11:56:45 -05:00
|
|
|
|
2021-05-24 01:47:21 -05:00
|
|
|
Contact* _EnsureContact(BMessage* message);
|
2021-05-31 11:56:45 -05:00
|
|
|
User* _EnsureUser(BMessage* message);
|
2021-06-02 16:53:03 -05:00
|
|
|
User* _EnsureUser(BString id, ProtocolLooper* protoLooper);
|
2021-05-24 01:47:21 -05:00
|
|
|
Conversation* _EnsureConversation(BMessage* message);
|
2021-05-31 11:56:45 -05:00
|
|
|
|
2011-12-14 17:36:27 -06:00
|
|
|
void _ReplicantStatusNotify(CayaStatus status);
|
|
|
|
|
|
|
|
RosterMap fRosterMap;
|
2021-05-31 11:56:45 -05:00
|
|
|
UserMap fUserMap;
|
2021-05-24 01:47:21 -05:00
|
|
|
ChatMap fChatMap;
|
2011-12-14 17:36:27 -06:00
|
|
|
ProtocolLoopers fLoopers;
|
2021-06-01 21:43:19 -05:00
|
|
|
AccountInstances
|
|
|
|
fAccounts;
|
2021-05-31 13:04:58 -05:00
|
|
|
BString fMySelf;
|
2010-05-07 04:47:10 -05:00
|
|
|
};
|
|
|
|
|
2021-05-27 11:15:30 -05:00
|
|
|
|
2010-05-07 04:47:10 -05:00
|
|
|
#endif // _SERVER_H
|
2021-05-27 11:15:30 -05:00
|
|
|
|