source: source/ariba/AribaModule.cpp@ 2410

Last change on this file since 2410 was 2409, checked in by mies, 16 years ago

moved tidy & pingpong

File size: 4.7 KB
Line 
1// [License]
2// The Ariba-Underlay Copyright
3//
4// Copyright (c) 2008-2009, Institute of Telematics, UniversitÀt Karlsruhe (TH)
5//
6// Institute of Telematics
7// UniversitÀt Karlsruhe (TH)
8// Zirkel 2, 76128 Karlsruhe
9// Germany
10//
11// Redistribution and use in source and binary forms, with or without
12// modification, are permitted provided that the following conditions are
13// met:
14//
15// 1. Redistributions of source code must retain the above copyright
16// notice, this list of conditions and the following disclaimer.
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// THIS SOFTWARE IS PROVIDED BY THE INSTITUTE OF TELEMATICS ``AS IS'' AND
22// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ARIBA PROJECT OR
25// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32//
33// The views and conclusions contained in the software and documentation
34// are those of the authors and should not be interpreted as representing
35// official policies, either expressed or implied, of the Institute of
36// Telematics.
37// [License]
38
39#include "AribaModule.h"
40
41// boost/std includes
42#include <assert.h>
43#include <boost/regex.hpp>
44
45// ariba includes
46#include "ariba/utility/misc/Helper.h"
47
48// hack includes
49#include "ariba/interface/UnderlayAbstraction.h"
50#include "ariba/communication/EndpointDescriptor.h"
51#include "ariba/communication/modules/network/NetworkLocator.h"
52
53using namespace ariba::utility::Helper;
54using ariba::interface::UnderlayAbstraction;
55
56namespace ariba {
57
58AribaModule::AribaModule() {
59
60 // init with default values
61 this->underlay_abs = NULL;
62 this->ip_addr = NULL;
63 this->tcp_port = 41402;
64 this->udp_port = 41402;
65 this->started = false;
66}
67
68AribaModule::~AribaModule() {
69}
70
71
72string AribaModule::getBootstrapHints(const Name& spoVNetName) const {
73
74}
75
76void AribaModule::addBootstrapHints(string boot_info) {
77 string str = boot_info;
78 static ::boost::regex boot_expr("<([^>:]+)[:]?([0-9]+)?>([^<]+)(.*)");
79 ::boost::smatch what;
80 while (::boost::regex_match(str, what, boot_expr)) {
81 std::cout << what[1].str() << ":" << what[2].str() << "=" << what[3]
82 << std::endl;
83 str = what[4].str();
84 }
85}
86
87void AribaModule::addBootstrapNode(const Name& spovnet, const Name& node,
88 communication::EndpointDescriptor* desc) {
89
90}
91
92const communication::EndpointDescriptor* AribaModule::getBootstrapNode(
93 const Name& spovnet) {
94 return NULL;
95}
96
97// @see Module.h
98void AribaModule::initialize() {
99
100 // preconditions
101 assert(!started);
102
103 // init variables
104 underlay_abs = NULL;
105}
106
107// @see Module.h
108void AribaModule::start() {
109
110 // preconditions
111 assert(underlay_abs == NULL);
112 assert(!started);
113
114 // create the base communication component
115 started = true;
116 underlay_abs = new interface::UnderlayAbstraction();
117}
118
119// @see Module.h
120void AribaModule::stop() {
121
122 // preconditions
123 assert(underlay_abs != NULL);
124 assert(started);
125
126 // delete base communication component
127 started = false;
128 delete underlay_abs;
129}
130
131// @see Module.h
132string AribaModule::getName() const {
133 return "ariba";
134}
135
136// @see Module.h
137void AribaModule::setProperty(string key, string value) {
138 if (key == "ip.addr") {
139 if (ip_addr != NULL) delete ip_addr;
140 communication::IPv4Locator* loc = new communication::IPv4Locator();
141 *loc = communication::IPv4Locator::fromString(value);
142 ip_addr = loc;
143 } else if (key == "tcp.port") tcp_port = stoi(value);
144 else if (key == "udp.port") udp_port = stoi(value);
145 else if (key == "bootstrap.hints") addBootstrapHints(value);
146}
147
148// @see Module.h
149const string AribaModule::getProperty(string key) const {
150 if (key == "ip.addr") return ip_addr->toString();
151 else if (key == "tcp.port") return ultos(tcp_port);
152 else if (key == "udp.port") return ultos(udp_port);
153 else if (key == "bootstrap.hints") return getBootstrapHints();
154}
155
156// @see Module.h
157const vector<string> AribaModule::getProperties() const {
158 vector<string> properties;
159 properties.push_back("ip.addr");
160 properties.push_back("tcp.port");
161 properties.push_back("udp.port");
162 properties.push_back("hints");
163 return properties;
164}
165
166} // namespace ariba
Note: See TracBrowser for help on using the repository browser.