Server.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright 2009-2011, Andrea Anzani. All rights reserved.
  3. * Copyright 2009-2011, Pier Luigi Fiorini. All rights reserved.
  4. * Distributed under the terms of the MIT License.
  5. */
  6. #ifndef _SERVER_H
  7. #define _SERVER_H
  8. #include <Message.h>
  9. #include <MessageFilter.h>
  10. #include <Notification.h>
  11. #include <libsupport/KeyMap.h>
  12. #include "AppConstants.h"
  13. #include "ChatCommand.h"
  14. #include "Contact.h"
  15. #include "Conversation.h"
  16. #include "Notifier.h"
  17. #include "ProtocolLooper.h"
  18. #include "User.h"
  19. class ChatProtocol;
  20. class RosterItem;
  21. class ProtocolLooper;
  22. typedef KeyMap<bigtime_t, ProtocolLooper*> ProtocolLoopers;
  23. typedef KeyMap<BString, bigtime_t> AccountInstances;
  24. typedef KeyMap<BString, bool> BoolMap;
  25. class Server: public BMessageFilter, public Notifier {
  26. public:
  27. Server();
  28. void Quit();
  29. void LoginAll();
  30. void Login(ProtocolLooper* looper);
  31. virtual filter_result Filter(BMessage* message, BHandler** target);
  32. filter_result ImMessage(BMessage* msg);
  33. void ImError(BMessage* msg);
  34. void AddProtocolLooper(bigtime_t instanceId,
  35. ChatProtocol* cayap);
  36. void RemoveProtocolLooper(bigtime_t instanceId);
  37. ProtocolLooper* GetProtocolLooper(bigtime_t instanceId);
  38. AccountInstances GetAccounts();
  39. AccountInstances GetActiveAccounts();
  40. void SendProtocolMessage(BMessage* msg);
  41. void SendAllProtocolMessage(BMessage* msg);
  42. RosterMap Contacts() const;
  43. Contact* ContactById(BString id, int64 instance);
  44. void AddContact(Contact* contact, int64 instance);
  45. UserMap Users() const;
  46. User* UserById(BString id, int64 instance);
  47. void AddUser(User* user, int64 instance);
  48. ChatMap Conversations() const;
  49. Conversation* ConversationById(BString id, int64 instance);
  50. void AddConversation(Conversation* chat, int64 instance);
  51. CommandMap Commands(int64 instance);
  52. ChatCommand* CommandById(BString id, int64 instance);
  53. BObjectList<BMessage> UserPopUpItems();
  54. private:
  55. ProtocolLooper* _LooperFromMessage(BMessage* message);
  56. Contact* _EnsureContact(BMessage* message);
  57. User* _EnsureUser(BMessage* message);
  58. User* _EnsureUser(BString id, ProtocolLooper* protoLooper);
  59. Contact* _GetOwnContact(BMessage* message);
  60. Conversation* _EnsureConversation(BMessage* message);
  61. void _ProtocolNotification(ProtocolLooper* looper,
  62. BString title, BString desc,
  63. notification_type type=B_INFORMATION_NOTIFICATION);
  64. void _SendNotification(BString title, BString content,
  65. BString id, BBitmap* icon=NULL,
  66. notification_type type=B_INFORMATION_NOTIFICATION);
  67. void _ReplicantStatusNotify(UserStatus status);
  68. ProtocolLoopers fLoopers;
  69. AccountInstances fAccounts;
  70. BoolMap fAccountEnabled;
  71. bool fStarted;
  72. CommandMap fCommands;
  73. BObjectList<BMessage> fUserItems;
  74. };
  75. #endif // _SERVER_H