IBR-DTNSuite  0.8
daemon/src/net/DiscoveryService.cpp
Go to the documentation of this file.
00001 /*
00002  * DiscoveryService.cpp
00003  *
00004  *  Created on: 11.09.2009
00005  *      Author: morgenro
00006  */
00007 
00008 #include "net/DiscoveryService.h"
00009 #include "ibrdtn/data/SDNV.h"
00010 #include "ibrdtn/data/BundleString.h"
00011 #include <string>
00012 
00013 using namespace dtn::data;
00014 
00015 namespace dtn
00016 {
00017         namespace net
00018         {
00019                 DiscoveryService::DiscoveryService()
00020                  : _provider(NULL)
00021                 {
00022                 }
00023 
00024                 DiscoveryService::DiscoveryService(DiscoveryServiceProvider *provider)
00025                  : _provider(provider)
00026                 {
00027                 }
00028 
00029                 DiscoveryService::DiscoveryService(std::string name, std::string parameters)
00030                  : _service_name(name), _service_parameters(parameters), _provider(NULL)
00031                 {
00032                 }
00033 
00034                 DiscoveryService::~DiscoveryService()
00035                 {
00036                 }
00037 
00038                 size_t DiscoveryService::getLength() const
00039                 {
00040                         BundleString name(_service_name);
00041                         BundleString parameters(_service_parameters);
00042 
00043                         return name.getLength() + parameters.getLength();
00044                 }
00045 
00046                 std::string DiscoveryService::getName() const
00047                 {
00048                         return _service_name;
00049                 }
00050 
00051                 std::string DiscoveryService::getParameters() const
00052                 {
00053                         return _service_parameters;
00054                 }
00055 
00056                 void DiscoveryService::update(const ibrcommon::vinterface &net)
00057                 {
00058                         if (_provider != NULL) _provider->update(net, _service_name, _service_parameters);
00059                 }
00060 
00061                 std::ostream &operator<<(std::ostream &stream, const DiscoveryService &service)
00062                 {
00063                         BundleString name(service._service_name);
00064                         BundleString parameters(service._service_parameters);
00065 
00066                         stream << name << parameters;
00067 
00068                         return stream;
00069                 }
00070 
00071                 std::istream &operator>>(std::istream &stream, DiscoveryService &service)
00072                 {
00073                         BundleString name;
00074                         BundleString parameters;
00075 
00076                         stream >> name >> parameters;
00077 
00078                         service._service_name = (std::string)name;
00079                         service._service_parameters = (std::string)parameters;
00080 
00081                         return stream;
00082                 }
00083         }
00084 }