Project

General

Profile

Bug #3607 » producer.cpp

The producer - Michael Sweatt, 04/25/2016 02:59 PM

 
1
#include <ndn-cxx/util/io.hpp>
2
#include <ndn-cxx/face.hpp>
3
#include <ndn-cxx/security/key-chain.hpp>
4

    
5
namespace ndn {
6

    
7
class Producer : noncopyable
8
{
9
public:
10
 void
11
 run()
12
 {
13
   m_face.setInterestFilter("/NTORRENT/foo/bar.txt/%FE%00/%FE%00/sha256digest=f4446686f2c9fd94d0d24b26eae465600547c1b37afdfca6abf026849dad0cda",
14
                            bind(&Producer::onInterest, this, _1, _2),
15
                            RegisterPrefixSuccessCallback(),
16
                            bind(&Producer::onRegisterFailed, this, _1, _2));
17
   m_face.processEvents();
18
 }
19

    
20
private:
21
 void
22
 onInterest(const InterestFilter& filter, const Interest& interest)
23
 {
24
   std::cout << "<< I: " << interest << std::endl;
25
   auto data = io::load<Data>("data.txt");
26
   std::cout << ">> D: " << *data << std::endl;
27
   m_face.put(*data);
28
 }
29

    
30

    
31
 void
32
 onRegisterFailed(const Name& prefix, const std::string& reason)
33
 {
34
   std::cerr << "ERROR: Failed to register prefix \""
35
             << prefix << "\" in local hub's daemon (" << reason << ")"
36
             << std::endl;
37
   m_face.shutdown();
38
 }
39

    
40
private:
41
 Face m_face;
42
 KeyChain m_keyChain;
43
};
44

    
45
} // namespace ndn
46

    
47
int
48
main(int argc, char** argv)
49
{
50
 ndn::Producer producer;
51
 try {
52
   producer.run();
53
 }
54
 catch (const std::exception& e) {
55
   std::cerr << "ERROR: " << e.what() << std::endl;
56
 }
57
 return 0;
58
}
(2-2/3)