Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9c0bd8d

Browse files
committed
Avoid deprecated ndn-cxx functions
Change-Id: Ic9fab00b75e9519315ee776dbc464794a9e56f1c
1 parente4b74bd commit9c0bd8d

File tree

9 files changed

+128
-141
lines changed

9 files changed

+128
-141
lines changed

‎examples/data-producer.cpp‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*-*/
22
/*
3-
* Copyright (c) 2014-2019, Regents of the University of California.
3+
* Copyright (c) 2014-2022, Regents of the University of California.
44
*
55
* This file is part of NDN repo-ng (Next generation of NDN repository).
66
* See AUTHORS.md for complete list of repo-ng authors and contributors.
@@ -138,7 +138,7 @@ Publisher::generateFromFile()
138138

139139
std::string name;
140140
getline(insertStream, name);
141-
auto data =createData(ndn::Name(name));
141+
auto data =createData(name);
142142
m_face.put(*data);
143143

144144
m_scheduler.schedule(timeInterval, [this] {generateFromFile(); });
@@ -148,11 +148,10 @@ std::shared_ptr<ndn::Data>
148148
Publisher::createData(const ndn::Name& name)
149149
{
150150
static ndn::KeyChain keyChain;
151-
static std::vector<uint8_t>content(1500,'-');
151+
staticconststd::vector<uint8_t>content(1500,'-');
152152

153-
auto data = std::make_shared<ndn::Data>();
154-
data->setName(name);
155-
data->setContent(content.data(), content.size());
153+
auto data = std::make_shared<ndn::Data>(name);
154+
data->setContent(content);
156155
keyChain.sign(*data);
157156
return data;
158157
}
@@ -203,7 +202,7 @@ main(int argc, char* argv[])
203202
generator.duration =milliseconds(boost::lexical_cast<uint64_t>(optarg));
204203
}
205204
catch (const boost::bad_lexical_cast&) {
206-
std::cerr <<"-s option should be an integer" << std::endl;;
205+
std::cerr <<"-s option should be an integer" << std::endl;
207206
return1;
208207
}
209208
break;
@@ -212,7 +211,7 @@ main(int argc, char* argv[])
212211
generator.timeInterval =milliseconds(boost::lexical_cast<uint64_t>(optarg));
213212
}
214213
catch (const boost::bad_lexical_cast&) {
215-
std::cerr <<"-t option should be an integer" << std::endl;;
214+
std::cerr <<"-t option should be an integer" << std::endl;
216215
return1;
217216
}
218217
break;

‎src/handles/tcp-bulk-insert-handle.cpp‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*-*/
22
/*
3-
* Copyright (c) 2014-2019, Regents of the University of California.
3+
* Copyright (c) 2014-2022, Regents of the University of California.
44
*
55
* This file is part of NDN repo-ng (Next generation of NDN repository).
66
* See AUTHORS.md for complete list of repo-ng authors and contributors.
@@ -85,7 +85,7 @@ TcpBulkInsertHandle::listen(const std::string& host, const std::string& port)
8585
ip::tcp::resolver::iterator end;
8686

8787
if (endpoint == end)
88-
BOOST_THROW_EXCEPTION(Error("Cannot listen on" + host +" port" + port));
88+
NDN_THROW(Error("Cannot listen on" + host +" port" + port));
8989

9090
m_localEndpoint = *endpoint;
9191
NDN_LOG_DEBUG("Start listening on" << m_localEndpoint);
@@ -157,17 +157,17 @@ detail::TcpBulkInsertClient::handleReceive(const boost::system::error_code& erro
157157

158158
// do magic
159159

160+
auto bufferView =ndn::make_span(m_inputBuffer, m_inputBufferSize);
160161
std::size_t offset =0;
161-
162162
bool isOk =true;
163-
Block element;
164-
while (m_inputBufferSize - offset >0) {
165-
std::tie(isOk, element) =Block::fromBuffer(m_inputBuffer +offset, m_inputBufferSize - offset);
163+
while (offset < bufferView.size()) {
164+
Block element;
165+
std::tie(isOk, element) =Block::fromBuffer(bufferView.subspan(offset));
166166
if (!isOk)
167167
break;
168168

169169
offset += element.size();
170-
BOOST_ASSERT(offset <=m_inputBufferSize);
170+
BOOST_ASSERT(offset <=bufferView.size());
171171

172172
if (element.type() == ndn::tlv::Data) {
173173
try {
@@ -178,9 +178,9 @@ detail::TcpBulkInsertClient::handleReceive(const boost::system::error_code& erro
178178
else
179179
NDN_LOG_DEBUG("FAILED to inject" << data.getName());
180180
}
181-
catch (const std::runtime_error&) {
181+
catch (const std::runtime_error& e) {
182182
/// \todo Catch specific error after determining what wireDecode() can throw
183-
NDN_LOG_ERROR("Error decoding received Data packet");
183+
NDN_LOG_ERROR("Error decoding received Data packet:" << e.what());
184184
}
185185
}
186186
}

‎tests/dataset-fixtures.hpp‎

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*-*/
2-
/**
3-
* Copyright (c) 2014-2018, Regents of the University of California.
2+
/*
3+
* Copyright (c) 2014-2022, Regents of the University of California.
44
*
55
* This file is part of NDN repo-ng (Next generation of NDN repository).
66
* See AUTHORS.md for complete list of repo-ng authors and contributors.
@@ -21,6 +21,7 @@
2121
#defineREPO_TESTS_DATASET_FIXTURES_HPP
2222

2323
#include"identity-management-fixture.hpp"
24+
2425
#include<vector>
2526
#include<boost/mpl/vector.hpp>
2627

@@ -33,11 +34,7 @@ class DatasetBase : public virtual IdentityManagementFixture
3334
classError :publicstd::runtime_error
3435
{
3536
public:
36-
explicit
37-
Error(const std::string& what)
38-
: std::runtime_error(what)
39-
{
40-
}
37+
using std::runtime_error::runtime_error;
4138
};
4239

4340
using DataContainer = std::list<std::shared_ptr<ndn::Data>>;
@@ -56,11 +53,10 @@ class DatasetBase : public virtual IdentityManagementFixture
5653
if (map.count(name) >0)
5754
return map[name];
5855

59-
static std::vector<uint8_t>content(1500,'-');
56+
staticconststd::vector<uint8_t>content(1500,'-');
6057

61-
std::shared_ptr<ndn::Data> data = std::make_shared<ndn::Data>();
62-
data->setName(name);
63-
data->setContent(&content[0], content.size());
58+
auto data = std::make_shared<ndn::Data>(name);
59+
data->setContent(content);
6460
m_keyChain.sign(*data);
6561

6662
map.insert(std::make_pair(name, data));
@@ -73,7 +69,7 @@ class DatasetBase : public virtual IdentityManagementFixture
7369
if (map.count(name) >0)
7470
return map[name];
7571
else
76-
BOOST_THROW_EXCEPTION(Error("Data with name" + name.toUri() +" is not found"));
72+
NDN_THROW(Error("Data with name" + name.toUri() +" is not found"));
7773
}
7874

7975
private:

‎tests/integrated/test-basic-command-insert-delete.cpp‎

Lines changed: 58 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*-*/
22
/*
3-
* Copyright (c) 2014-2021, Regents of the University of California.
3+
* Copyright (c) 2014-2022, Regents of the University of California.
44
*
55
* This file is part of NDN repo-ng (Next generation of NDN repository).
66
* See AUTHORS.md for complete list of repo-ng authors and contributors.
@@ -32,7 +32,6 @@
3232
#include<ndn-cxx/util/random.hpp>
3333
#include<ndn-cxx/util/time.hpp>
3434

35-
#include<boost/asio/io_service.hpp>
3635
#include<boost/mpl/vector.hpp>
3736
#include<boost/test/unit_test.hpp>
3837

@@ -44,7 +43,7 @@ using ndn::time::milliseconds;
4443
// All the test cases in this test suite should be run at once.
4544
BOOST_AUTO_TEST_SUITE(TestBasicCommandInsertDelete)
4645

47-
conststaticuint8_tcontent[8] = {3,1,4,1,5,9,2,6};
46+
constuint8_tCONTENT[] = {3,1,4,1,5,9,2,6};
4847

4948
template<classDataset>
5049
classFixture :publicCommandFixture,publicRepoStorageFixture,publicDataset
@@ -59,7 +58,7 @@ class Fixture : public CommandFixture, public RepoStorageFixture, public Dataset
5958
{
6059
NamecmdPrefix("/repo/command");
6160
repoFace.registerPrefix(cmdPrefix,nullptr,
62-
[] (const Name& cmdPrefix,const std::string& reason) {
61+
[] (const Name&,const std::string& reason) {
6362
BOOST_FAIL("Command prefix registration error:" << reason);
6463
});
6564
}
@@ -113,11 +112,12 @@ class Fixture : public CommandFixture, public RepoStorageFixture, public Dataset
113112
ndn::security::InterestSigner signer;
114113
};
115114

116-
template<classT>void
115+
template<classT>
116+
void
117117
Fixture<T>::onInsertInterest(const Interest& interest)
118118
{
119119
Datadata(Name(interest.getName()));
120-
data.setContent(content,sizeof(content));
120+
data.setContent(CONTENT);
121121
data.setFreshnessPeriod(0_ms);
122122
keyChain.sign(data);
123123
insertFace.put(data);
@@ -126,56 +126,62 @@ Fixture<T>::onInsertInterest(const Interest& interest)
126126
eventIt->second.cancel();
127127
insertEvents.erase(eventIt);
128128
}
129-
// schedule an event 50ms later to check whether insert is Ok
130-
scheduler.schedule(500_ms,std::bind(&Fixture<T>::checkInsertOk,this, interest));
129+
130+
// schedule an event to check whether insert is ok
131+
scheduler.schedule(500_ms, [=] {this->checkInsertOk(interest); });
131132
}
132133

133-
template<classT>void
134+
template<classT>
135+
void
134136
Fixture<T>::onRegisterFailed(const std::string& reason)
135137
{
136138
BOOST_ERROR("ERROR: Failed to register prefix in local hub's daemon" + reason);
137139
}
138140

139-
template<classT>void
141+
template<classT>
142+
void
140143
Fixture<T>::delayedInterest()
141144
{
142145
BOOST_ERROR("Fetching interest does not come. It may be satisfied in CS or something is wrong");
143146
}
144147

145-
template<classT>void
146-
Fixture<T>::onInsertData(const Interest& interest,const Data& data)
148+
template<classT>
149+
void
150+
Fixture<T>::onInsertData(const Interest&,const Data& data)
147151
{
148152
RepoCommandResponse response;
149153
response.wireDecode(data.getContent().blockFromValue());
150-
int statusCode = response.getCode();
151-
BOOST_CHECK_EQUAL(statusCode,100);
154+
BOOST_CHECK_EQUAL(response.getCode(),100);
152155
}
153156

154-
template<classT>void
157+
template<classT>
158+
void
155159
Fixture<T>::onDeleteData(const Interest& interest,const Data& data)
156160
{
157161
RepoCommandResponse response;
158162
response.wireDecode(data.getContent().blockFromValue());
159-
int statusCode = response.getCode();
160-
BOOST_CHECK_EQUAL(statusCode,200);
163+
BOOST_CHECK_EQUAL(response.getCode(),200);
161164

162-
//schedlutean event to check whether delete isOk.
163-
scheduler.schedule(100_ms,std::bind(&Fixture<T>::checkDeleteOk,this,interest));
165+
// schedulean event to check whether delete isok
166+
scheduler.schedule(100_ms,[=] {this->checkDeleteOk(interest); });
164167
}
165168

166-
template<classT>void
167-
Fixture<T>::onInsertTimeout(const Interest& interest)
169+
template<classT>
170+
void
171+
Fixture<T>::onInsertTimeout(const Interest&)
168172
{
169173
BOOST_ERROR("Insert command timeout");
170174
}
171175

172-
template<classT>void
173-
Fixture<T>::onDeleteTimeout(const Interest& interest)
176+
template<classT>
177+
void
178+
Fixture<T>::onDeleteTimeout(const Interest&)
174179
{
175180
BOOST_ERROR("Delete command timeout");
176181
}
177182

178-
template<classT>void
183+
template<classT>
184+
void
179185
Fixture<T>::sendInsertInterest(const Interest& insertInterest)
180186
{
181187
insertFace.expressInterest(insertInterest,
@@ -184,7 +190,8 @@ Fixture<T>::sendInsertInterest(const Interest& insertInterest)
184190
std::bind(&Fixture<T>::onInsertTimeout,this, _1));
185191
}
186192

187-
template<classT>void
193+
template<classT>
194+
void
188195
Fixture<T>::sendDeleteInterest(const Interest& deleteInterest)
189196
{
190197
deleteFace.expressInterest(deleteInterest,
@@ -193,41 +200,43 @@ Fixture<T>::sendDeleteInterest(const Interest& deleteInterest)
193200
std::bind(&Fixture<T>::onDeleteTimeout,this, _1));
194201
}
195202

196-
template<classT>void
203+
template<classT>
204+
void
197205
Fixture<T>::checkInsertOk(const Interest& interest)
198206
{
199-
BOOST_TEST_MESSAGE(interest);
200-
std::shared_ptr<Data> data = handle->readData(interest);
201-
if (data) {
202-
int rc =memcmp(data->getContent().value(), content,sizeof(content));
203-
BOOST_CHECK_EQUAL(rc,0);
204-
}
205-
else {
206-
BOOST_ERROR("Check Insert Failed");
207+
BOOST_TEST_CONTEXT("Interest" <<interest) {
208+
auto data = handle->readData(interest);
209+
if (data) {
210+
BOOST_TEST(data->getContent().value_bytes() == CONTENT,boost::test_tools::per_element());
211+
}
212+
else {
213+
BOOST_ERROR("Insert check failed");
214+
}
207215
}
208216
}
209217

210-
template<classT>void
218+
template<classT>
219+
void
211220
Fixture<T>::checkDeleteOk(const Interest& interest)
212221
{
213-
std::map<Name, Name>::iterator name = deleteNamePairs.find(interest.getName());
214-
BOOST_CHECK_MESSAGE(name != deleteNamePairs.end(),"Delete name not found:" << interest.getName());
215-
InterestdataInterest(name->second);
216-
std::shared_ptr<Data> data = handle->readData(dataInterest);
222+
auto nameIt = deleteNamePairs.find(interest.getName());
223+
BOOST_CHECK_MESSAGE(nameIt != deleteNamePairs.end(),"Delete name not found:" << interest.getName());
224+
InterestdataInterest(nameIt->second);
225+
auto data = handle->readData(dataInterest);
217226
BOOST_CHECK(!data);
218227
}
219228

220-
template<classT>void
229+
template<classT>
230+
void
221231
Fixture<T>::scheduleInsertEvent()
222232
{
223233
int timeCount =1;
224-
for (typename T::DataContainer::iterator i =this->data.begin();
225-
i !=this->data.end(); ++i) {
234+
for (auto i =this->data.begin(); i !=this->data.end(); ++i) {
226235
NameinsertCommandName("/repo/command/insert");
227236
RepoCommandParameter insertParameter;
228237
insertParameter.setName(Name((*i)->getName())
229238
.appendNumber(ndn::random::generateWord64()));
230-
insertCommandName.append(insertParameter.wireEncode());
239+
insertCommandName.append(tlv::GenericNameComponent,insertParameter.wireEncode());
231240
Interest insertInterest = signer.makeCommandInterest(insertCommandName);
232241
// schedule a job to express insertInterest every 50ms
233242
scheduler.schedule(milliseconds(timeCount *50 +1000),
@@ -245,17 +254,17 @@ Fixture<T>::scheduleInsertEvent()
245254
}
246255
}
247256

248-
template<classT>void
257+
template<classT>
258+
void
249259
Fixture<T>::scheduleDeleteEvent()
250260
{
251261
int timeCount =1;
252-
for (typename T::DataContainer::iterator i =this->data.begin();
253-
i !=this->data.end(); ++i) {
262+
for (auto i =this->data.begin(); i !=this->data.end(); ++i) {
254263
NamedeleteCommandName("/repo/command/delete");
255264
RepoCommandParameter deleteParameter;
256265
deleteParameter.setProcessId(ndn::random::generateWord64());
257266
deleteParameter.setName((*i)->getName());
258-
deleteCommandName.append(deleteParameter.wireEncode());
267+
deleteCommandName.append(tlv::GenericNameComponent,deleteParameter.wireEncode());
259268
Interest deleteInterest = signer.makeCommandInterest(deleteCommandName);
260269
deleteNamePairs[deleteInterest.getName()] = (*i)->getName();
261270
scheduler.schedule(milliseconds(4000 + timeCount *50),
@@ -271,8 +280,8 @@ using Datasets = boost::mpl::vector<BasicDataset,
271280
BOOST_FIXTURE_TEST_CASE_TEMPLATE(InsertDelete, T, Datasets, Fixture<T>)
272281
{
273282
// schedule events
274-
this->scheduler.schedule(0_s,std::bind(&Fixture<T>::scheduleInsertEvent,this));
275-
this->scheduler.schedule(10_s,std::bind(&Fixture<T>::scheduleDeleteEvent,this));
283+
this->scheduler.schedule(0_s, [this] {this->scheduleInsertEvent(); });
284+
this->scheduler.schedule(10_s,[this] {this->scheduleDeleteEvent(); });
276285

277286
this->repoFace.processEvents(30_s);
278287
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp