blob: 42466eb1658fdbf89d8c27f876b24945400bf942 [file] [log] [blame]
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -08001#ifndef CCNX_WRAPPER_H
2#define CCNX_WRAPPER_H
3
Zhenkai Zhu7f4258e2012-12-29 19:55:13 -08004#include <boost/thread/locks.hpp>
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -08005#include <boost/thread/recursive_mutex.hpp>
6#include <boost/thread/thread.hpp>
Zhenkai Zhu974c5a62012-12-28 14:15:30 -08007
8#include "ccnx-common.h"
Zhenkai Zhuf47109b2013-01-02 19:41:34 -08009#include "ccnx-name.h"
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080010#include "ccnx-closure.h"
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -080011
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080012using namespace std;
13
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -080014namespace Ccnx {
15
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080016struct CcnxOperationException : virtual boost::exception, virtual exception { };
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -080017
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080018class CcnxWrapper
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080019{
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -080020public:
Zhenkai Zhu7f4258e2012-12-29 19:55:13 -080021 typedef boost::shared_mutex Lock;
22 typedef boost::unique_lock<Lock> WriteLock;
23 typedef boost::shared_lock<Lock> ReadLock;
24
25 typedef boost::recursive_mutex RecLock;
26 typedef boost::unique_lock<RecLock> UniqueRecLock;
27
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080028 typedef boost::function<void (const Name &)> InterestCallback;
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -080029
30 CcnxWrapper();
31 virtual ~CcnxWrapper();
32
33 virtual int
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080034 setInterestFilter (const Name &prefix, const InterestCallback &interestCallback);
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -080035
36 virtual void
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080037 clearInterestFilter (const Name &prefix);
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -080038
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080039 virtual int
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080040 sendInterest (const Name &interest, Closure *closure, const Selectors &selector = Selectors());
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -080041
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080042 virtual int
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080043 publishData (const Name &name, const unsigned char *buf, size_t len, int freshness);
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -080044
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080045 int
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080046 publishData (const Name &name, const Bytes &content, int freshness);
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080047
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080048 static Name
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080049 getLocalPrefix ();
50
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080051 Bytes
Zhenkai Zhu82de6d22013-01-03 14:15:35 -080052 createContentObject(const Name &name, const unsigned char *buf, size_t len, int freshness = 2147/* max value for ccnx*/);
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -080053
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080054 int
Zhenkai Zhubad089c2012-12-28 10:28:27 -080055 putToCcnd (const Bytes &contentObject);
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080056
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -080057protected:
58 void
59 connectCcnd();
60
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080061 /// @cond include_hidden
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -080062 void
63 createKeyLocator ();
64
65 void
66 initKeyStore ();
67
68 const ccn_pkey *
69 getPrivateKey ();
70
71 const unsigned char *
72 getPublicKeyDigest ();
73
74 ssize_t
75 getPublicKeyDigestLength ();
76
77 void
78 ccnLoop ();
79
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -080080 /// @endcond
81
82protected:
83 ccn* m_handle;
84 ccn_keystore *m_keyStore;
85 ccn_charbuf *m_keyLoactor;
86 // to lock, use "boost::recursive_mutex::scoped_lock scoped_lock(mutex);
Zhenkai Zhu7f4258e2012-12-29 19:55:13 -080087 RecLock m_mutex;
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -080088 boost::thread m_thread;
89 bool m_running;
90 bool m_connected;
Zhenkai Zhucb2d0dd2013-01-03 14:10:48 -080091 map<Name, InterestCallback> m_registeredInterests;
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -080092};
93
94typedef boost::shared_ptr<CcnxWrapper> CcnxWrapperPtr;
95
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -080096
97} // Ccnx
98
Zhenkai Zhu0d8f5d52012-12-30 12:54:07 -080099#endif