blob: 946170d89ab52377b0bb067667453e2d6503f7c5 [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,
37 const Ccnx::Name &deviceName, const std::string &sharedFolderName, int freshness = -1);
Zhenkai Zhue42b4572013-01-22 15:57:54 -080038 ~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 Afanasyev28ca3ed2013-01-24 23:17:15 -080047private:
Zhenkai Zhue42b4572013-01-22 15:57:54 -080048 void
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080049 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 Zhue42b4572013-01-22 15:57:54 -080059
60private:
61 Ccnx::CcnxWrapperPtr m_ccnx;
62 ActionLogPtr m_actionLog;
63 typedef boost::shared_mutex Mutex;
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080064
65 typedef boost::unique_lock<Mutex> ScopedLock;
Zhenkai Zhue42b4572013-01-22 15:57:54 -080066 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 Zhu13d224d2013-01-23 19:40:25 -080070 int m_freshness;
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080071
72 Executor m_executor;
73
74 Ccnx::Name m_deviceName;
75 std::string m_sharedFolderName;
Zhenkai Zhue42b4572013-01-22 15:57:54 -080076};
77#endif // CONTENT_SERVER_H