blob: 6ee57495b250039a280220b24c753eaf48dead73 [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"
17#include "ccnx-closure.h"
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -080018
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080019using namespace std;
20
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -080021namespace Ccnx {
22
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080023struct CcnxOperationException : virtual boost::exception, virtual exception { };
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -080024
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080025class CcnxWrapper
26{
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -080027public:
Zhenkai Zhubad089c2012-12-28 10:28:27 -080028 typedef boost::function<void (const string &)> InterestCallback;
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -080029
30 CcnxWrapper();
31 virtual ~CcnxWrapper();
32
33 virtual int
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080034 setInterestFilter (const string &prefix, const InterestCallback &interestCallback);
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -080035
36 virtual void
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080037 clearInterestFilter (const string &prefix);
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -080038
39 virtual int
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080040 sendInterest (const string &strInterest, Closure *closure);
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -080041
42 virtual int
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080043 publishData (const string &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
46 publishData (const string &name, const Bytes &content, int freshness);
47
48 static string
49 getLocalPrefix ();
50
51 static string
Zhenkai Zhubad089c2012-12-28 10:28:27 -080052 extractName(const unsigned char *data, const ccn_indexbuf *comps);
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080053
54protected:
55 Bytes
Zhenkai Zhu974c5a62012-12-28 14:15:30 -080056 createContentObject(const string &name, const unsigned char *buf, size_t len, int freshness);
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -080057
58 int
Zhenkai Zhubad089c2012-12-28 10:28:27 -080059 putToCcnd (const Bytes &contentObject);
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -080060
61protected:
62 void
63 connectCcnd();
64
65 /// @cond include_hidden
66 void
67 createKeyLocator ();
68
69 void
70 initKeyStore ();
71
72 const ccn_pkey *
73 getPrivateKey ();
74
75 const unsigned char *
76 getPublicKeyDigest ();
77
78 ssize_t
79 getPublicKeyDigestLength ();
80
81 void
82 ccnLoop ();
83
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -080084 /// @endcond
85
86protected:
87 ccn* m_handle;
88 ccn_keystore *m_keyStore;
89 ccn_charbuf *m_keyLoactor;
90 // to lock, use "boost::recursive_mutex::scoped_lock scoped_lock(mutex);
91 boost::recursive_mutex m_mutex;
92 boost::thread m_thread;
93 bool m_running;
94 bool m_connected;
Zhenkai Zhu43eb2732012-12-28 00:48:26 -080095 map<string, InterestCallback> m_registeredInterests;
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -080096 // std::list< std::pair<std::string, InterestCallback> > m_registeredInterests;
97};
98
99typedef boost::shared_ptr<CcnxWrapper> CcnxWrapperPtr;
100
Zhenkai Zhu1ddeb6f2012-12-27 14:04:18 -0800101
102} // Ccnx
103
104#endif