blob: c4b70c6e32d1d57e634c2a0b9755b88dbe280bdf [file] [log] [blame]
Zhenkai Zhue42b4572013-01-22 15:57:54 -08001/* -*- 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 Afanasyev28ca3ed2013-01-24 23:17:15 -080022#ifndef CONTENT_SERVER_H
23#define CONTENT_SERVER_H
24
Zhenkai Zhue42b4572013-01-22 15:57:54 -080025#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 Afanasyev28ca3ed2013-01-24 23:17:15 -080031#include "executor.h"
Zhenkai Zhue42b4572013-01-22 15:57:54 -080032
33class ContentServer
34{
35public:
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080036 ContentServer(Ccnx::CcnxWrapperPtr ccnx, ActionLogPtr actionLog, const boost::filesystem::path &rootDir,
Alexander Afanasyev1d1cc832013-02-05 20:03:36 -080037 const Ccnx::Name &deviceName, const std::string &sharedFolderName, const std::string &appName,
38 int freshness = -1);
Zhenkai Zhue42b4572013-01-22 15:57:54 -080039 ~ContentServer();
40
41 // the assumption is, when the interest comes in, interest is informs of
42 // /some-prefix/topology-independent-name
43 // currently /topology-independent-name must begin with /action or /file
44 // so that ContentServer knows where to look for the content object
45 void registerPrefix(const Ccnx::Name &prefix);
46 void deregisterPrefix(const Ccnx::Name &prefix);
47
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080048private:
Alexander Afanasyev1d1cc832013-02-05 20:03:36 -080049 // void
50 // serve (Ccnx::Name forwardingHint, const Ccnx::Name &interest);
Zhenkai Zhuc3a27872013-01-25 19:21:25 -080051
52 void
Alexander Afanasyev1d1cc832013-02-05 20:03:36 -080053 serve_Action (Ccnx::Name forwardingHint, Ccnx::Name locatorPrefix, Ccnx::Name interest);
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080054
55 void
Alexander Afanasyev1d1cc832013-02-05 20:03:36 -080056 serve_File (Ccnx::Name forwardingHint, Ccnx::Name locatorPrefix, Ccnx::Name interest);
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080057
58 void
Alexander Afanasyev1d1cc832013-02-05 20:03:36 -080059 serve_Action_Execute(Ccnx::Name forwardingHint, Ccnx::Name locatorPrefix, Ccnx::Name interest);
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080060
61 void
Alexander Afanasyev1d1cc832013-02-05 20:03:36 -080062 serve_File_Execute(Ccnx::Name forwardingHint, Ccnx::Name locatorPrefix, Ccnx::Name interest);
Zhenkai Zhue42b4572013-01-22 15:57:54 -080063
64private:
65 Ccnx::CcnxWrapperPtr m_ccnx;
66 ActionLogPtr m_actionLog;
67 typedef boost::shared_mutex Mutex;
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080068
69 typedef boost::unique_lock<Mutex> ScopedLock;
Zhenkai Zhue42b4572013-01-22 15:57:54 -080070 typedef std::set<Ccnx::Name>::iterator PrefixIt;
71 std::set<Ccnx::Name> m_prefixes;
72 Mutex m_mutex;
73 boost::filesystem::path m_dbFolder;
Zhenkai Zhu13d224d2013-01-23 19:40:25 -080074 int m_freshness;
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080075
76 Executor m_executor;
77
78 Ccnx::Name m_deviceName;
79 std::string m_sharedFolderName;
Alexander Afanasyev1d1cc832013-02-05 20:03:36 -080080 std::string m_appName;
Zhenkai Zhue42b4572013-01-22 15:57:54 -080081};
82#endif // CONTENT_SERVER_H