blob: 90089e7816b8e0928a7f00ebfd6d570fcf22ab74 [file] [log] [blame]
#ifndef CCNX_WRAPPER_H
#define CCNX_WRAPPER_H
#include <boost/thread/locks.hpp>
#include <boost/thread/recursive_mutex.hpp>
#include <boost/thread/thread.hpp>
#include "ccnx-common.h"
#include "ccnx-name.h"
#include "ccnx-closure.h"
using namespace std;
namespace Ccnx {
struct CcnxOperationException : virtual boost::exception, virtual exception { };
class CcnxWrapper
{
public:
typedef boost::shared_mutex Lock;
typedef boost::unique_lock<Lock> WriteLock;
typedef boost::shared_lock<Lock> ReadLock;
typedef boost::recursive_mutex RecLock;
typedef boost::unique_lock<RecLock> UniqueRecLock;
typedef boost::function<void (const string &)> InterestCallback;
CcnxWrapper();
virtual ~CcnxWrapper();
virtual int
setInterestFilter (const string &prefix, const InterestCallback &interestCallback);
virtual void
clearInterestFilter (const string &prefix);
virtual int
sendInterest (const string &interest, Closure *closure);
virtual int
publishData (const string &name, const unsigned char *buf, size_t len, int freshness);
int
publishData (const string &name, const Bytes &content, int freshness);
static string
getLocalPrefix ();
static string
extractName(const unsigned char *data, const ccn_indexbuf *comps);
protected:
Bytes
createContentObject(const string &name, const unsigned char *buf, size_t len, int freshness);
int
putToCcnd (const Bytes &contentObject);
protected:
void
connectCcnd();
/// @cond include_hidden
void
createKeyLocator ();
void
initKeyStore ();
const ccn_pkey *
getPrivateKey ();
const unsigned char *
getPublicKeyDigest ();
ssize_t
getPublicKeyDigestLength ();
void
ccnLoop ();
/// @endcond
protected:
ccn* m_handle;
ccn_keystore *m_keyStore;
ccn_charbuf *m_keyLoactor;
// to lock, use "boost::recursive_mutex::scoped_lock scoped_lock(mutex);
RecLock m_mutex;
boost::thread m_thread;
bool m_running;
bool m_connected;
map<string, InterestCallback> m_registeredInterests;
// std::list< std::pair<std::string, InterestCallback> > m_registeredInterests;
};
typedef boost::shared_ptr<CcnxWrapper> CcnxWrapperPtr;
} // Ccnx
#endif