blob: 13ca2dc6f83644b8c7cf36302e4343c28c192633 [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>
Zhenkai Zhu92bb6952013-02-06 16:43:30 -080029#include <map>
Zhenkai Zhue42b4572013-01-22 15:57:54 -080030#include <boost/thread/shared_mutex.hpp>
31#include <boost/thread/locks.hpp>
Zhenkai Zhu92bb6952013-02-06 16:43:30 -080032#include "scheduler.h"
Zhenkai Zhue42b4572013-01-22 15:57:54 -080033
34class ContentServer
35{
36public:
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080037 ContentServer(Ccnx::CcnxWrapperPtr ccnx, ActionLogPtr actionLog, const boost::filesystem::path &rootDir,
Alexander Afanasyev1d1cc832013-02-05 20:03:36 -080038 const Ccnx::Name &deviceName, const std::string &sharedFolderName, const std::string &appName,
39 int freshness = -1);
Zhenkai Zhue42b4572013-01-22 15:57:54 -080040 ~ContentServer();
41
42 // the assumption is, when the interest comes in, interest is informs of
43 // /some-prefix/topology-independent-name
44 // currently /topology-independent-name must begin with /action or /file
45 // so that ContentServer knows where to look for the content object
46 void registerPrefix(const Ccnx::Name &prefix);
47 void deregisterPrefix(const Ccnx::Name &prefix);
48
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080049private:
Alexander Afanasyev4d086752013-02-07 13:06:04 -080050 void
51 filterAndServe (Ccnx::Name forwardingHint, const Ccnx::Name &interest);
Zhenkai Zhuc3a27872013-01-25 19:21:25 -080052
53 void
Alexander Afanasyev4d086752013-02-07 13:06:04 -080054 serve_Action (Ccnx::Name forwardingHint, Ccnx::Name interest);
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080055
56 void
Alexander Afanasyev4d086752013-02-07 13:06:04 -080057 serve_File (Ccnx::Name forwardingHint, Ccnx::Name interest);
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080058
59 void
Alexander Afanasyev4d086752013-02-07 13:06:04 -080060 serve_Action_Execute(Ccnx::Name forwardingHint, Ccnx::Name interest);
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080061
62 void
Alexander Afanasyev4d086752013-02-07 13:06:04 -080063 serve_File_Execute(Ccnx::Name forwardingHint, Ccnx::Name interest);
Zhenkai Zhue42b4572013-01-22 15:57:54 -080064
Zhenkai Zhu92bb6952013-02-06 16:43:30 -080065 void
66 flushStaleDbCache();
67
Zhenkai Zhue42b4572013-01-22 15:57:54 -080068private:
69 Ccnx::CcnxWrapperPtr m_ccnx;
70 ActionLogPtr m_actionLog;
71 typedef boost::shared_mutex Mutex;
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080072
73 typedef boost::unique_lock<Mutex> ScopedLock;
Zhenkai Zhue42b4572013-01-22 15:57:54 -080074 typedef std::set<Ccnx::Name>::iterator PrefixIt;
75 std::set<Ccnx::Name> m_prefixes;
76 Mutex m_mutex;
77 boost::filesystem::path m_dbFolder;
Zhenkai Zhu13d224d2013-01-23 19:40:25 -080078 int m_freshness;
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080079
Zhenkai Zhu92bb6952013-02-06 16:43:30 -080080 SchedulerPtr m_scheduler;
81 typedef std::map<Hash, ObjectDbPtr> DbCache;
82 DbCache m_dbCache;
83 Mutex m_dbCacheMutex;
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080084
85 Ccnx::Name m_deviceName;
86 std::string m_sharedFolderName;
Alexander Afanasyev1d1cc832013-02-05 20:03:36 -080087 std::string m_appName;
Zhenkai Zhue42b4572013-01-22 15:57:54 -080088};
89#endif // CONTENT_SERVER_H