blob: 55037b763952d53473038dd52ba55933b575fab3 [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 Afanasyev3cca13f2013-02-07 16:06:46 -080038 const Ccnx::Name &userName, const std::string &sharedFolderName, const std::string &appName,
Alexander Afanasyev1d1cc832013-02-05 20:03:36 -080039 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 Afanasyev3cca13f2013-02-07 16:06:46 -080054 filterAndServeImpl (const Ccnx::Name &forwardingHint, const Ccnx::Name &name, const Ccnx::Name &interest);
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080055
56 void
Alexander Afanasyev3cca13f2013-02-07 16:06:46 -080057 serve_Action (const Ccnx::Name &forwardingHint, const Ccnx::Name &name, const Ccnx::Name &interest);
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080058
59 void
Alexander Afanasyev3cca13f2013-02-07 16:06:46 -080060 serve_File (const Ccnx::Name &forwardingHint, const Ccnx::Name &name, const Ccnx::Name &interest);
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080061
62 void
Alexander Afanasyev3cca13f2013-02-07 16:06:46 -080063 serve_Action_Execute(const Ccnx::Name &forwardingHint, const Ccnx::Name &name, const Ccnx::Name &interest);
64
65 void
66 serve_File_Execute(const Ccnx::Name &forwardingHint, const Ccnx::Name &name, const Ccnx::Name &interest);
Zhenkai Zhue42b4572013-01-22 15:57:54 -080067
Zhenkai Zhu92bb6952013-02-06 16:43:30 -080068 void
69 flushStaleDbCache();
70
Zhenkai Zhue42b4572013-01-22 15:57:54 -080071private:
72 Ccnx::CcnxWrapperPtr m_ccnx;
73 ActionLogPtr m_actionLog;
74 typedef boost::shared_mutex Mutex;
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080075
76 typedef boost::unique_lock<Mutex> ScopedLock;
Zhenkai Zhue42b4572013-01-22 15:57:54 -080077 typedef std::set<Ccnx::Name>::iterator PrefixIt;
78 std::set<Ccnx::Name> m_prefixes;
79 Mutex m_mutex;
80 boost::filesystem::path m_dbFolder;
Zhenkai Zhu13d224d2013-01-23 19:40:25 -080081 int m_freshness;
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080082
Zhenkai Zhu92bb6952013-02-06 16:43:30 -080083 SchedulerPtr m_scheduler;
84 typedef std::map<Hash, ObjectDbPtr> DbCache;
85 DbCache m_dbCache;
86 Mutex m_dbCacheMutex;
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080087
Alexander Afanasyev3cca13f2013-02-07 16:06:46 -080088 Ccnx::Name m_userName;
Alexander Afanasyev28ca3ed2013-01-24 23:17:15 -080089 std::string m_sharedFolderName;
Alexander Afanasyev1d1cc832013-02-05 20:03:36 -080090 std::string m_appName;
Zhenkai Zhue42b4572013-01-22 15:57:54 -080091};
92#endif // CONTENT_SERVER_H