Initialize m_running variable in Sync::CcnxWrapper
diff --git a/model/sync-ccnx-wrapper.cc b/model/sync-ccnx-wrapper.cc
index 741a143..3755324 100644
--- a/model/sync-ccnx-wrapper.cc
+++ b/model/sync-ccnx-wrapper.cc
@@ -29,17 +29,21 @@
namespace Sync {
CcnxWrapper::CcnxWrapper()
+ : m_handle (0)
+ , m_keyStore (0)
+ , m_keyLoactor (0)
+ , m_running (true)
{
m_handle = ccn_create();
ccn_connect(m_handle, NULL);
initKeyStore();
createKeyLocator();
- m_thread = thread(&CcnxWrapper::ccnLoop, this);
+ m_thread = thread (&CcnxWrapper::ccnLoop, this);
}
CcnxWrapper::~CcnxWrapper()
{
- running = false;
+ m_running = false;
m_thread.join();
ccn_disconnect(m_handle);
ccn_destroy(&m_handle);
@@ -56,10 +60,10 @@
ccn_charbuf_append_tt(m_keyLoactor, CCN_DTAG_Key, CCN_DTAG);
res = ccn_append_pubkey_blob(m_keyLoactor, ccn_keystore_public_key(m_keyStore));
if (res >= 0)
- {
- ccn_charbuf_append_closer(m_keyLoactor); /* </Key> */
- ccn_charbuf_append_closer(m_keyLoactor); /* </KeyLocator> */
- }
+ {
+ ccn_charbuf_append_closer(m_keyLoactor); /* </Key> */
+ ccn_charbuf_append_closer(m_keyLoactor); /* </KeyLocator> */
+ }
}
const ccn_pkey* CcnxWrapper::getPrivateKey()
@@ -94,18 +98,18 @@
pfds[0].fd = ccn_get_connection_fd(m_handle);
pfds[0].events = POLLIN;
- while (running)
- {
- if (res >= 0)
+ while (m_running)
{
- int ret = poll(pfds, 1, 100);
- if (ret >= 0)
- {
- recursive_mutex::scoped_lock lock(m_mutex);
- res = ccn_run(m_handle, 0);
- }
+ if (res >= 0)
+ {
+ int ret = poll(pfds, 1, 100);
+ if (ret >= 0)
+ {
+ recursive_mutex::scoped_lock lock(m_mutex);
+ res = ccn_run(m_handle, 0);
+ }
+ }
}
- }
}
int CcnxWrapper::publishData(string name, string dataBuffer, int freshness)
@@ -136,14 +140,14 @@
static ccn_upcall_res incomingInterest(
- ccn_closure *selfp,
- ccn_upcall_kind kind,
- ccn_upcall_info *info)
+ ccn_closure *selfp,
+ ccn_upcall_kind kind,
+ ccn_upcall_info *info)
{
function<void (string)> f = *(function<void (string)> *)selfp->data;
switch (kind)
- {
+ {
case CCN_UPCALL_FINAL:
delete selfp;
return CCN_UPCALL_RESULT_OK;
@@ -153,30 +157,30 @@
default:
return CCN_UPCALL_RESULT_OK;
- }
+ }
string interest;
for (int i = 0; i < info->interest_comps->n - 1; i++)
- {
- char *comp;
- size_t size;
- interest += "/";
- ccn_name_comp_get(info->interest_ccnb, info->interest_comps, i, (const unsigned char **)&comp, &size);
- interest += comp;
- }
+ {
+ char *comp;
+ size_t size;
+ interest += "/";
+ ccn_name_comp_get(info->interest_ccnb, info->interest_comps, i, (const unsigned char **)&comp, &size);
+ interest += comp;
+ }
f(interest);
return CCN_UPCALL_RESULT_OK;
}
static ccn_upcall_res incomingData(
- ccn_closure *selfp,
- ccn_upcall_kind kind,
- ccn_upcall_info *info)
+ ccn_closure *selfp,
+ ccn_upcall_kind kind,
+ ccn_upcall_info *info)
{
function<void (string)> f = *(function<void (string)> *)selfp->data;
switch (kind)
- {
+ {
case CCN_UPCALL_FINAL:
delete selfp;
return CCN_UPCALL_RESULT_OK;
@@ -186,7 +190,7 @@
default:
return CCN_UPCALL_RESULT_OK;
- }
+ }
char *pcontent;
size_t len;
diff --git a/model/sync-ccnx-wrapper.h b/model/sync-ccnx-wrapper.h
index 037d2d2..71ee321 100644
--- a/model/sync-ccnx-wrapper.h
+++ b/model/sync-ccnx-wrapper.h
@@ -50,23 +50,6 @@
* with ccnx library
*/
class CcnxWrapper {
-private:
- ccn* m_handle;
- ccn_keystore *m_keyStore;
- ccn_charbuf *m_keyLoactor;
- // to lock, use "boost::recursive_mutex::scoped_lock scoped_lock(mutex);
- boost::recursive_mutex m_mutex;
- boost::thread m_thread;
-
-private:
- void createKeyLocator();
- void initKeyStore();
- const ccn_pkey *getPrivateKey();
- const unsigned char *getPublicKeyDigest();
- ssize_t getPublicKeyDigestLength();
- void ccnLoop();
- bool running;
-
public:
/**
@@ -74,8 +57,8 @@
* keystore 2) init keylocator 3) start a thread to hold a loop of ccn_run
*
*/
- CcnxWrapper();
- ~CcnxWrapper();
+ CcnxWrapper();
+ ~CcnxWrapper();
/**
* @brief send Interest; need to grab lock m_mutex first
@@ -84,8 +67,9 @@
* @param dataCallback the callback function to deal with the returned data
* @return the return code of ccn_express_interest
*/
- int sendInterest(std::string strInterest, boost::function<void (std::string)>
- dataCallback);
+ int
+ sendInterest(std::string strInterest, boost::function<void (std::string)>
+ dataCallback);
/**
* @brief set Interest filter (specify what interest you want to receive
@@ -94,8 +78,9 @@
* @param interestCallback the callback function to deal with the returned data
* @return the return code of ccn_set_interest_filter
*/
- int setInterestFilter(std::string prefix, boost::function<void (std::string)>
- interestCallback);
+ int
+ setInterestFilter(std::string prefix, boost::function<void (std::string)>
+ interestCallback);
/**
* @brief publish data and put it to local ccn content store; need to grab
@@ -106,8 +91,36 @@
* @param freshness the freshness time for the data object
* @return code generated by ccnx library calls, >0 if success
*/
- int publishData(std::string name, std::string dataBuffer, int freshness);
+ int
+ publishData(std::string name, std::string dataBuffer, int freshness);
+private:
+ void
+ createKeyLocator ();
+
+ void
+ initKeyStore ();
+
+ const ccn_pkey *
+ getPrivateKey ();
+
+ const unsigned char *
+ getPublicKeyDigest ();
+
+ ssize_t
+ getPublicKeyDigestLength ();
+
+ void
+ ccnLoop ();
+
+private:
+ ccn* m_handle;
+ ccn_keystore *m_keyStore;
+ ccn_charbuf *m_keyLoactor;
+ // to lock, use "boost::recursive_mutex::scoped_lock scoped_lock(mutex);
+ boost::recursive_mutex m_mutex;
+ boost::thread m_thread;
+ bool m_running;
};
} // Sync