blob: 8d24b195289ca91cff2dfd4088e1dc237068934a [file] [log] [blame]
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -08001#ifndef CCNX_WRAPPER_H
2#define CCNX_WRAPPER_H
3
4extern "C" {
5#include <ccn/ccn.h>
6#include <ccn/charbuf.h>
7#include <ccn/keystore.h>
8#include <ccn/uri.h>
9#include <ccn/bloom.h>
10#include <ccn/signing.h>
11}
12
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -080013#include <boost/thread/recursive_mutex.hpp>
14#include <boost/thread/thread.hpp>
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080015
16#include "ccnx-common.h"
Zhenkai Zhu9bad2bf2012-12-28 15:31:46 -080017#include "ccnx-interest.h"
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080018#include "ccnx-closure.h"
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -080019
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080020using namespace std;
21
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -080022namespace Ccnx {
23
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080024struct CcnxOperationException : virtual boost::exception, virtual exception { };
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -080025
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080026class CcnxWrapper
27{
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -080028public:
Zhenkai Zhubad089c2012-12-28 10:28:27 -080029 typedef boost::function<void (const string &)> InterestCallback;
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -080030
31 CcnxWrapper();
32 virtual ~CcnxWrapper();
33
34 virtual int
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080035 setInterestFilter (const string &prefix, const InterestCallback &interestCallback);
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -080036
37 virtual void
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080038 clearInterestFilter (const string &prefix);
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -080039
40 virtual int
Zhenkai Zhu9bad2bf2012-12-28 15:31:46 -080041 sendInterest (const Interest &interest, Closure *closure);
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -080042
43 virtual int
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080044 publishData (const string &name, const unsigned char *buf, size_t len, int freshness);
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -080045
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080046 int
47 publishData (const string &name, const Bytes &content, int freshness);
48
49 static string
50 getLocalPrefix ();
51
52 static string
Zhenkai Zhubad089c2012-12-28 10:28:27 -080053 extractName(const unsigned char *data, const ccn_indexbuf *comps);
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080054
55protected:
56 Bytes
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080057 createContentObject(const string &name, const unsigned char *buf, size_t len, int freshness);
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -080058
59 int
Zhenkai Zhubad089c2012-12-28 10:28:27 -080060 putToCcnd (const Bytes &contentObject);
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -080061
62protected:
63 void
64 connectCcnd();
65
66 /// @cond include_hidden
67 void
68 createKeyLocator ();
69
70 void
71 initKeyStore ();
72
73 const ccn_pkey *
74 getPrivateKey ();
75
76 const unsigned char *
77 getPublicKeyDigest ();
78
79 ssize_t
80 getPublicKeyDigestLength ();
81
82 void
83 ccnLoop ();
84
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -080085 /// @endcond
86
87protected:
88 ccn* m_handle;
89 ccn_keystore *m_keyStore;
90 ccn_charbuf *m_keyLoactor;
91 // to lock, use "boost::recursive_mutex::scoped_lock scoped_lock(mutex);
92 boost::recursive_mutex m_mutex;
93 boost::thread m_thread;
94 bool m_running;
95 bool m_connected;
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080096 map<string, InterestCallback> m_registeredInterests;
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -080097 // std::list< std::pair<std::string, InterestCallback> > m_registeredInterests;
98};
99
100typedef boost::shared_ptr<CcnxWrapper> CcnxWrapperPtr;
101
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -0800102
103} // Ccnx
104
105#endif