Zhenkai Zhu | e42b457 | 2013-01-22 15:57:54 -0800 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2013 University of California, Los Angeles |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
| 18 | * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu> |
| 19 | * Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 20 | */ |
| 21 | |
Alexander Afanasyev | 28ca3ed | 2013-01-24 23:17:15 -0800 | [diff] [blame^] | 22 | #ifndef CONTENT_SERVER_H |
| 23 | #define CONTENT_SERVER_H |
| 24 | |
Zhenkai Zhu | e42b457 | 2013-01-22 15:57:54 -0800 | [diff] [blame] | 25 | #include "ccnx-wrapper.h" |
| 26 | #include "object-db.h" |
| 27 | #include "action-log.h" |
| 28 | #include <set> |
| 29 | #include <boost/thread/shared_mutex.hpp> |
| 30 | #include <boost/thread/locks.hpp> |
Alexander Afanasyev | 28ca3ed | 2013-01-24 23:17:15 -0800 | [diff] [blame^] | 31 | #include "executor.h" |
Zhenkai Zhu | e42b457 | 2013-01-22 15:57:54 -0800 | [diff] [blame] | 32 | |
| 33 | class ContentServer |
| 34 | { |
| 35 | public: |
Alexander Afanasyev | 28ca3ed | 2013-01-24 23:17:15 -0800 | [diff] [blame^] | 36 | ContentServer(Ccnx::CcnxWrapperPtr ccnx, ActionLogPtr actionLog, const boost::filesystem::path &rootDir, |
| 37 | const Ccnx::Name &deviceName, const std::string &sharedFolderName, int freshness = -1); |
Zhenkai Zhu | e42b457 | 2013-01-22 15:57:54 -0800 | [diff] [blame] | 38 | ~ContentServer(); |
| 39 | |
| 40 | // the assumption is, when the interest comes in, interest is informs of |
| 41 | // /some-prefix/topology-independent-name |
| 42 | // currently /topology-independent-name must begin with /action or /file |
| 43 | // so that ContentServer knows where to look for the content object |
| 44 | void registerPrefix(const Ccnx::Name &prefix); |
| 45 | void deregisterPrefix(const Ccnx::Name &prefix); |
| 46 | |
Alexander Afanasyev | 28ca3ed | 2013-01-24 23:17:15 -0800 | [diff] [blame^] | 47 | private: |
Zhenkai Zhu | e42b457 | 2013-01-22 15:57:54 -0800 | [diff] [blame] | 48 | void |
Alexander Afanasyev | 28ca3ed | 2013-01-24 23:17:15 -0800 | [diff] [blame^] | 49 | serve_Action (Ccnx::Name forwardingHint, const Ccnx::Name &interest); |
| 50 | |
| 51 | void |
| 52 | serve_File (Ccnx::Name forwardingHint, const Ccnx::Name &interest); |
| 53 | |
| 54 | void |
| 55 | serve_Action_Execute(Ccnx::Name forwardingHint, Ccnx::Name interest); |
| 56 | |
| 57 | void |
| 58 | serve_File_Execute(Ccnx::Name forwardingHint, Ccnx::Name interest); |
Zhenkai Zhu | e42b457 | 2013-01-22 15:57:54 -0800 | [diff] [blame] | 59 | |
| 60 | private: |
| 61 | Ccnx::CcnxWrapperPtr m_ccnx; |
| 62 | ActionLogPtr m_actionLog; |
| 63 | typedef boost::shared_mutex Mutex; |
Alexander Afanasyev | 28ca3ed | 2013-01-24 23:17:15 -0800 | [diff] [blame^] | 64 | |
| 65 | typedef boost::unique_lock<Mutex> ScopedLock; |
Zhenkai Zhu | e42b457 | 2013-01-22 15:57:54 -0800 | [diff] [blame] | 66 | typedef std::set<Ccnx::Name>::iterator PrefixIt; |
| 67 | std::set<Ccnx::Name> m_prefixes; |
| 68 | Mutex m_mutex; |
| 69 | boost::filesystem::path m_dbFolder; |
Zhenkai Zhu | 13d224d | 2013-01-23 19:40:25 -0800 | [diff] [blame] | 70 | int m_freshness; |
Alexander Afanasyev | 28ca3ed | 2013-01-24 23:17:15 -0800 | [diff] [blame^] | 71 | |
| 72 | Executor m_executor; |
| 73 | |
| 74 | Ccnx::Name m_deviceName; |
| 75 | std::string m_sharedFolderName; |
Zhenkai Zhu | e42b457 | 2013-01-22 15:57:54 -0800 | [diff] [blame] | 76 | }; |
| 77 | #endif // CONTENT_SERVER_H |