separate controller backend frontend

Change-Id: Ic4ba9c8154a600c978e75ea82ff36569270dd656
diff --git a/src/controller-backend.hpp b/src/controller-backend.hpp
new file mode 100644
index 0000000..2456641
--- /dev/null
+++ b/src/controller-backend.hpp
@@ -0,0 +1,143 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2013, Regents of the University of California
+ *
+ * BSD license, See the LICENSE file for more information
+ *
+ * Author: Yingdi Yu <yingdi@cs.ucla.edu>
+ */
+
+#ifndef CHRONOCHAT_CONTROLLER_BACKEND_HPP
+#define CHRONOCHAT_CONTROLLER_BACKEND_HPP
+
+#include <QThread>
+#include <QStringList>
+#include <QMutex>
+
+#ifndef Q_MOC_RUN
+#include "common.hpp"
+#include "contact-manager.hpp"
+#include "invitation.hpp"
+#include "validator-invitation.hpp"
+#include <ndn-cxx/security/key-chain.hpp>
+#endif
+
+namespace chronos {
+
+class ControllerBackend : public QThread
+{
+  Q_OBJECT
+
+public:
+  ControllerBackend(QObject* parent = 0);
+
+  ~ControllerBackend();
+
+  ContactManager*
+  getContactManager()
+  {
+    return &m_contactManager;
+  }
+
+protected:
+  void
+  run();
+
+private:
+  void
+  setInvitationListener();
+
+  ndn::Name
+  getInvitationRoutingPrefix();
+
+  void
+  onInvitationPrefixReset();
+
+  void
+  onInvitationPrefixResetFailed(const std::string& failInfo);
+
+  void
+  onInvitationInterest(const ndn::Name& prefix, const ndn::Interest& interest,
+                       size_t routingPrefixOffset);
+
+  void
+  onInvitationRegisterFailed(const Name& prefix, const std::string& failInfo);
+
+  void
+  onInvitationValidated(const shared_ptr<const Interest>& interest);
+
+  void
+  onInvitationValidationFailed(const shared_ptr<const Interest>& interest,
+                               std::string failureInfo);
+
+  void
+  onLocalPrefix(const Interest& interest, Data& data);
+
+  void
+  onLocalPrefixTimeout(const Interest& interest);
+
+  void
+  updateLocalPrefix(const Name& localPrefix);
+
+signals:
+  void
+  identityUpdated(const QString& identity);
+
+  void
+  localPrefixUpdated(const QString& localPrefix);
+
+  void
+  invitaionValidated(QString alias, QString chatroom, ndn::Name invitationINterest);
+
+  void
+  startChatroomOnInvitation(chronos::Invitation invitation, bool secured);
+
+public slots:
+  void
+  shutdown();
+
+  void
+  addChatroom(QString chatroom);
+
+  void
+  removeChatroom(QString chatroom);
+
+  void
+  onUpdateLocalPrefixAction();
+
+  void
+  onIdentityChanged(const QString& identity);
+
+  void
+  onInvitationResponded(const ndn::Name& invitationName, bool accepted);
+
+private slots:
+  void
+  onContactIdListReady(const QStringList& list);
+
+private:
+  ndn::Face m_face;
+
+  Name m_identity;  //TODO: set/get
+
+  Name m_localPrefix;
+
+  // Contact Manager
+  ContactManager m_contactManager;
+
+  // Security related;
+  ndn::KeyChain m_keyChain;
+  ValidatorInvitation m_validator;
+
+  // RegisteredPrefixId
+  const ndn::RegisteredPrefixId* m_invitationListenerId;
+
+  // ChatRoomList
+  QStringList m_chatDialogList;
+
+  QMutex m_mutex;
+};
+
+} // namespace chronos
+
+#endif // CHRONOCHAT_CONTROLLER_BACKEND_HPP