Yingdi Yu | 2c9e771 | 2014-10-20 11:55:05 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2013, Regents of the University of California |
| 4 | * |
| 5 | * BSD license, See the LICENSE file for more information |
| 6 | * |
| 7 | * Author: Yingdi Yu <yingdi@cs.ucla.edu> |
| 8 | */ |
| 9 | |
| 10 | #ifndef CHRONOCHAT_CONTROLLER_BACKEND_HPP |
| 11 | #define CHRONOCHAT_CONTROLLER_BACKEND_HPP |
| 12 | |
| 13 | #include <QThread> |
| 14 | #include <QStringList> |
| 15 | #include <QMutex> |
| 16 | |
| 17 | #ifndef Q_MOC_RUN |
| 18 | #include "common.hpp" |
| 19 | #include "contact-manager.hpp" |
| 20 | #include "invitation.hpp" |
| 21 | #include "validator-invitation.hpp" |
| 22 | #include <ndn-cxx/security/key-chain.hpp> |
| 23 | #endif |
| 24 | |
| 25 | namespace chronos { |
| 26 | |
| 27 | class ControllerBackend : public QThread |
| 28 | { |
| 29 | Q_OBJECT |
| 30 | |
| 31 | public: |
| 32 | ControllerBackend(QObject* parent = 0); |
| 33 | |
| 34 | ~ControllerBackend(); |
| 35 | |
| 36 | ContactManager* |
| 37 | getContactManager() |
| 38 | { |
| 39 | return &m_contactManager; |
| 40 | } |
| 41 | |
| 42 | protected: |
| 43 | void |
| 44 | run(); |
| 45 | |
| 46 | private: |
| 47 | void |
| 48 | setInvitationListener(); |
| 49 | |
| 50 | ndn::Name |
| 51 | getInvitationRoutingPrefix(); |
| 52 | |
| 53 | void |
| 54 | onInvitationPrefixReset(); |
| 55 | |
| 56 | void |
| 57 | onInvitationPrefixResetFailed(const std::string& failInfo); |
| 58 | |
| 59 | void |
| 60 | onInvitationInterest(const ndn::Name& prefix, const ndn::Interest& interest, |
| 61 | size_t routingPrefixOffset); |
| 62 | |
| 63 | void |
| 64 | onInvitationRegisterFailed(const Name& prefix, const std::string& failInfo); |
| 65 | |
| 66 | void |
| 67 | onInvitationValidated(const shared_ptr<const Interest>& interest); |
| 68 | |
| 69 | void |
| 70 | onInvitationValidationFailed(const shared_ptr<const Interest>& interest, |
| 71 | std::string failureInfo); |
| 72 | |
| 73 | void |
| 74 | onLocalPrefix(const Interest& interest, Data& data); |
| 75 | |
| 76 | void |
| 77 | onLocalPrefixTimeout(const Interest& interest); |
| 78 | |
| 79 | void |
| 80 | updateLocalPrefix(const Name& localPrefix); |
| 81 | |
| 82 | signals: |
| 83 | void |
| 84 | identityUpdated(const QString& identity); |
| 85 | |
| 86 | void |
| 87 | localPrefixUpdated(const QString& localPrefix); |
| 88 | |
| 89 | void |
| 90 | invitaionValidated(QString alias, QString chatroom, ndn::Name invitationINterest); |
| 91 | |
| 92 | void |
| 93 | startChatroomOnInvitation(chronos::Invitation invitation, bool secured); |
| 94 | |
| 95 | public slots: |
| 96 | void |
| 97 | shutdown(); |
| 98 | |
| 99 | void |
| 100 | addChatroom(QString chatroom); |
| 101 | |
| 102 | void |
| 103 | removeChatroom(QString chatroom); |
| 104 | |
| 105 | void |
| 106 | onUpdateLocalPrefixAction(); |
| 107 | |
| 108 | void |
| 109 | onIdentityChanged(const QString& identity); |
| 110 | |
| 111 | void |
| 112 | onInvitationResponded(const ndn::Name& invitationName, bool accepted); |
| 113 | |
| 114 | private slots: |
| 115 | void |
| 116 | onContactIdListReady(const QStringList& list); |
| 117 | |
| 118 | private: |
| 119 | ndn::Face m_face; |
| 120 | |
| 121 | Name m_identity; //TODO: set/get |
| 122 | |
| 123 | Name m_localPrefix; |
| 124 | |
| 125 | // Contact Manager |
| 126 | ContactManager m_contactManager; |
| 127 | |
| 128 | // Security related; |
| 129 | ndn::KeyChain m_keyChain; |
| 130 | ValidatorInvitation m_validator; |
| 131 | |
| 132 | // RegisteredPrefixId |
| 133 | const ndn::RegisteredPrefixId* m_invitationListenerId; |
| 134 | |
| 135 | // ChatRoomList |
| 136 | QStringList m_chatDialogList; |
| 137 | |
| 138 | QMutex m_mutex; |
| 139 | }; |
| 140 | |
| 141 | } // namespace chronos |
| 142 | |
| 143 | #endif // CHRONOCHAT_CONTROLLER_BACKEND_HPP |