blob: 12a5bc7b0e684fc7a380a6090dc4fa25e5fa0fb3 [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 Name &)> InterestCallback;
CcnxWrapper();
virtual ~CcnxWrapper();
virtual int
setInterestFilter (const Name &prefix, const InterestCallback &interestCallback);
virtual void
clearInterestFilter (const Name &prefix);
virtual int
sendInterest (const Name &interest, Closure *closure, const Selectors &selector = Selectors());
virtual int
publishData (const Name &name, const unsigned char *buf, size_t len, int freshness);
int
publishData (const Name &name, const Bytes &content, int freshness);
static Name
getLocalPrefix ();
Bytes
createContentObject(const Name &name, const unsigned char *buf, size_t len, int freshness = 2147/* max value for ccnx*/);
int
putToCcnd (const Bytes &contentObject);
protected:
void
connectCcnd();
/// @cond include_hidden
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<Name, InterestCallback> m_registeredInterests;
};
typedef boost::shared_ptr<CcnxWrapper> CcnxWrapperPtr;
} // Ccnx
#endif