| /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| /* |
| * Copyright (c) 2013 University of California, Los Angeles |
| * |
| * This program is free software; you can redistribute it and/or modify |
| * it under the terms of the GNU General Public License version 2 as |
| * published by the Free Software Foundation; |
| * |
| * This program is distributed in the hope that it will be useful, |
| * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| * GNU General Public License for more details. |
| * |
| * You should have received a copy of the GNU General Public License |
| * along with this program; if not, write to the Free Software |
| * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| * |
| * Zhenkai Zhu <zhenkai@cs.ucla.edu> |
| * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| */ |
| |
| #ifndef DISPATCHER_H |
| #define DISPATCHER_H |
| |
| #include "action-log.h" |
| #include "sync-core.h" |
| #include "ccnx-wrapper.h" |
| #include "executor.h" |
| #include "object-db.h" |
| #include "object-manager.h" |
| #include "content-server.h" |
| #include <boost/function.hpp> |
| #include <boost/filesystem.hpp> |
| #include <boost/shared_ptr.hpp> |
| #include <map> |
| |
| typedef boost::shared_ptr<ActionItem> ActionItemPtr; |
| |
| // TODO: |
| // This class lacks a permanent table to store the files in fetching process |
| // and fetch the missing pieces for those in the table after the application launches |
| class Dispatcher |
| { |
| public: |
| typedef enum |
| { |
| UPDATE = 0, |
| DELETE = 1 |
| } ActionType; |
| |
| // sharedFolder is the name to be used in NDN name; |
| // rootDir is the shared folder dir in local file system; |
| Dispatcher(const boost::filesystem::path &path, const std::string &localUserName, const Ccnx::Name &localPrefix, |
| const std::string &sharedFolder, const boost::filesystem::path &rootDir, |
| Ccnx::CcnxWrapperPtr ccnx, SchedulerPtr scheduler, int poolSize = 2); |
| ~Dispatcher(); |
| |
| // ----- Callbacks, they only submit the job to executor and immediately return so that event processing thread won't be blocked for too long ------- |
| |
| // callback to process local file change |
| void |
| fileChangedCallback(const boost::filesystem::path &relativeFilepath, ActionType type); |
| |
| // callback to process remote sync state change |
| void |
| syncStateChangedCallback(const SyncStateMsgPtr &stateMsg); |
| |
| // callback to process remote action data |
| void |
| actionReceivedCallback(const ActionItemPtr &actionItem); |
| |
| // callback to porcess file data |
| void |
| fileSegmentReceivedCallback(const Ccnx::Name &name, const Ccnx::Bytes &content); |
| |
| // callback to assemble file |
| void |
| fileReadyCallback(const Ccnx::Name &fileNamePrefix); |
| |
| private: |
| void |
| fileChanged(const boost::filesystem::path &relativeFilepath, ActionType type); |
| |
| void |
| syncStateChanged(const SyncStateMsgPtr &stateMsg); |
| |
| void |
| actionReceived(const ActionItemPtr &actionItem); |
| |
| void |
| fileSegmentReceived(const Ccnx::Name &name, const Ccnx::Bytes &content); |
| |
| void |
| fileReady(const Ccnx::Name &fileNamePrefix); |
| |
| private: |
| Ccnx::CcnxWrapperPtr m_ccnx; |
| SyncCore *m_core; |
| SyncLogPtr m_syncLog; |
| ActionLogPtr m_actionLog; |
| |
| boost::filesystem::path m_rootDir; |
| Executor m_executor; |
| ObjectManager m_objectManager; |
| Ccnx::Name m_localUserName; |
| // maintain object db ptrs so that we don't need to create them |
| // for every fetched segment of a file |
| map<Ccnx::Name, ObjectDbPtr> m_objectDbMap; |
| std::string m_sharedFolder; |
| ContentServer *m_server; |
| }; |
| |
| namespace Error |
| { |
| struct Dispatcher : virtual boost::exception, virtual std::exception {}; |
| typedef boost::error_info<struct tag_errmsg, std::string> error_info_str; |
| } |
| |
| #endif // DISPATCHER_H |
| |