Changeset 12060 for source/ariba/utility
- Timestamp:
- Jun 19, 2013, 11:05:49 AM (11 years ago)
- Location:
- source/ariba/utility
- Files:
-
- 16 added
- 9 deleted
- 33 edited
Legend:
- Unmodified
- Added
- Removed
-
source/ariba/utility/CMakeLists.txt
r10700 r12060 45 45 add_subdir_sources( 46 46 addressing 47 addressing2 47 48 bootstrap 48 49 configuration 49 50 internal 50 51 logging 51 measurement52 52 messages 53 53 misc -
source/ariba/utility/addressing
- Property svn:mergeinfo changed (with no actual effect on merging)
-
source/ariba/utility/addressing/endpoint_set.hpp
r10653 r12060 1 #ifndef ENDPOINT_SET_HPP_ 2 #define ENDPOINT_SET_HPP_ 1 #ifndef ENDPOINT_SET_HPP_DEPRECATED_ 2 #define ENDPOINT_SET_HPP_DEPRECATED_ 3 3 4 4 #include "addressing.hpp" -
source/ariba/utility/addressing/facades/address_v.hpp
r10789 r12060 13 13 14 14 #include "../detail/address_convenience.hpp" 15 16 #include <boost/shared_ptr.hpp> 15 17 16 18 namespace ariba { … … 26 28 class address_v: public detail::address_convenience<address_v> { 27 29 public: 30 typedef boost::shared_ptr<address_v> shared_ptr; 31 28 32 virtual ~address_v() {} 29 33 -
source/ariba/utility/addressing/ip_address.hpp
r6919 r12060 1 #ifndef IP_ADDRESS_HPP_ 2 #define IP_ADDRESS_HPP_ 1 #ifndef IP_ADDRESS_HPP_DEPRECATED_ 2 #define IP_ADDRESS_HPP_DEPRECATED_ 3 3 4 4 #include <string> -
source/ariba/utility/addressing/tcpip_endpoint.hpp
r5284 r12060 1 #ifndef TCPIP_ENDPOINT_HPP_ 2 #define TCPIP_ENDPOINT_HPP_ 1 #ifndef TCPIP_ENDPOINT_HPP_DEPRECATED_ 2 #define TCPIP_ENDPOINT_HPP_DEPRECATED_ 3 3 4 4 #include<string> -
source/ariba/utility/bootstrap/modules/bluetoothsdp
- Property svn:mergeinfo changed (with no actual effect on merging)
-
source/ariba/utility/bootstrap/modules/periodicbroadcast
- Property svn:mergeinfo changed (with no actual effect on merging)
-
source/ariba/utility/bootstrap/modules/periodicbroadcast/PeriodicBroadcast.h
r10653 r12060 40 40 #define __PERIODIC_BROADCAST_H 41 41 42 // ariba 42 43 #include "ariba/config.h" 43 44 #include "ariba/utility/bootstrap/modules/BootstrapModule.h" 45 #include "ariba/utility/logging/Logging.h" 46 #include "ariba/utility/system/Timer.h" 47 48 // ariba messages 49 #include "PeriodicBroadcastMessage.h" 50 51 // (ariba) link-local 52 #include "ariba/utility/transport/StreamTransport/StreamTransport.hpp" 53 54 // system 44 55 #include <map> 45 56 #include <string> 46 57 #include <ctime> 47 58 #include <iostream> 59 60 // boost 48 61 #include <boost/asio.hpp> 49 62 #include <boost/foreach.hpp> 50 63 #include <boost/thread/mutex.hpp> 51 64 #include <boost/thread/thread.hpp> 52 #include "ariba/utility/bootstrap/modules/BootstrapModule.h" 53 #include "ariba/utility/logging/Logging.h" 54 #include "ariba/utility/system/Timer.h" 55 #include "PeriodicBroadcastMessage.h" 56 57 //link-local 58 #include "ariba/utility/transport/tcpip/tcpip.hpp" 65 59 66 60 67 using std::map; … … 301 308 302 309 // include all link-local interfaces 303 vector<uint64_t> scope_ids = ariba::transport:: tcpip::get_interface_scope_ids();310 vector<uint64_t> scope_ids = ariba::transport::get_interface_scope_ids(); 304 311 305 312 BOOST_FOREACH ( uint64_t id, scope_ids ) -
source/ariba/utility/logging/Logging.h
r10700 r12060 97 97 98 98 static int __loglevel__ = 2; //default is info 99 // static int __loglevel__ = 1; // XXX use higher log level 99 100 100 101 #define logging_trace(x) { logging_stdout(x); } -
source/ariba/utility/messages.h
r3690 r12060 40 40 #define MESSAGES_H_ 41 41 42 // TODO wÃŒrde sagen das brauchen wir nicht mehr 43 // ---> ÃŒberall dieses include rausnehmen und ggf #include "messages/Message.h" einfÃŒgen.. 44 42 45 #include "messages/Message.h" 43 #include "messages/MessageSender.h" 44 #include "messages/MessageReceiver.h"45 #include "messages/MessageUtilities.h"46 #include "messages/MessageProvider.h" 47 #include "messages/TextMessage.h"46 //#include "messages/MessageSender.h" // TODO wird das noch genutzt..? Wenn nein, sollte es weg! 47 //#include "messages/MessageReceiver.h" 48 //#include "messages/MessageUtilities.h" 49 ////#include "messages/MessageProvider.h" // DEPRECATED 50 //#include "messages/TextMessage.h" 48 51 49 52 #endif /* MESSAGES_H_ */ -
source/ariba/utility/messages/Message.cpp
r8620 r12060 41 41 #include "ariba/utility/serialization/DataStream.hpp" 42 42 43 #include "ariba/utility/logging/Logging.h" 44 43 45 NAMESPACE_BEGIN 44 46 … … 80 82 } 81 83 84 85 reboost::message_t Message::wrap_up_for_sending() 86 { 87 assert( ! wrapped_up ); 88 wrapped_up = true; 89 90 //// Adapt to new message system //// 91 Data data = data_serialize(this, DEFAULT_V); 92 reboost::shared_buffer_t buf(data.getBuffer(), data.getLength() / 8); 93 94 newstyle_payload.push_front(buf); 95 96 return newstyle_payload; 97 } 98 99 reboost::shared_buffer_t Message::serialize_into_shared_buffer() 100 { 101 assert ( newstyle_payload.length() == 0 ); 102 103 //// Adapt to new message system //// 104 Data data = data_serialize(this, DEFAULT_V); 105 reboost::shared_buffer_t buf(data.getBuffer(), data.getLength() / 8); 106 107 return buf; 108 } 109 110 111 reboost::shared_buffer_t Message::deserialize_from_shared_buffer(reboost::shared_buffer_t buff) 112 { 113 // NOTE: legacy payload is not allowed when using shared buffers 114 this->legacy_payload_disabled = true; 115 116 assert( buff.size() > 0 ); 117 118 // const_cast is necessary here, but without legacy payload we should be save here (more or less) 119 Data dat(const_cast<uint8_t*>(buff.data()), buff.size() * 8); 120 121 size_t len = this->SERIALIZATION_METHOD_NAME(DESERIALIZE, dat) / 8; 122 123 // return remaining sub-buffer 124 return buff(len); 125 } 126 127 128 82 129 NAMESPACE_END 83 130 84 131 std::ostream& operator<<(std::ostream& stream, const ariba::utility::Message& msg ) { 85 132 using_serialization; 86 stream << "msg(type=" << typeid(msg).name() ;133 stream << "msg(type=" << typeid(msg).name() << ","; 87 134 stream << "len=" << (data_length(&msg)/8) << ","; 88 135 Data data = data_serialize(&msg); 89 stream << " ,data=" << data;136 stream << "data=" << data; 90 137 data.release(); 91 138 stream << ")"; 92 139 return stream; 93 140 } 94 -
source/ariba/utility/messages/Message.h
r6919 r12060 62 62 #include "ariba/utility/serialization.h" 63 63 64 // reboost messages 65 #include "ariba/utility/transport/messages/message.hpp" 66 67 64 68 std::ostream& operator<<(std::ostream& stream, const ariba::utility::Message& msg ); 65 69 … … 82 86 friend std::ostream& ::operator<<(std::ostream& stream, const ariba::utility::Message& msg ); 83 87 84 // root binary data85 shared_array<uint8_t> root;86 87 88 // payload 89 bool legacy_payload_disabled; 88 90 bool releasePayload; 89 91 Data payload; //< messages binary data 92 93 // XXX testing... 94 reboost::message_t newstyle_payload; 95 bool wrapped_up; 90 96 91 97 // addresses and control info … … 98 104 */ 99 105 inline Message() : 100 root(), releasePayload(true), payload(), srcAddr(NULL),destAddr(NULL) { 106 legacy_payload_disabled(false), releasePayload(true), payload(), 107 newstyle_payload(), wrapped_up(false), srcAddr(NULL),destAddr(NULL) { 101 108 } 102 109 … … 106 113 */ 107 114 explicit inline Message( const Data& data ) : 108 releasePayload(true), srcAddr(NULL),destAddr(NULL) { 115 legacy_payload_disabled(false), releasePayload(true), 116 newstyle_payload(), wrapped_up(false), srcAddr(NULL),destAddr(NULL) { // FIXME newstyle_payload..? 109 117 this->payload = data.clone(); 110 118 // this->root = shared_array<uint8_t>((uint8_t*)data.getBuffer()); … … 225 233 return decapsulate<T>(); 226 234 } 235 236 237 // XXX testing 238 void set_payload_message(reboost::message_t msg) 239 { 240 newstyle_payload = msg; 241 } 242 243 void append_buffer(reboost::shared_buffer_t buff) 244 { 245 newstyle_payload.push_back(buff); 246 } 247 248 249 // XXX testing... packs this message into the payload message (do not use twice!!) 250 virtual reboost::message_t wrap_up_for_sending(); 251 252 253 /** 254 * Uses the old serialization system to serialize itself into a (new style) shared buffer. 255 */ 256 virtual reboost::shared_buffer_t serialize_into_shared_buffer(); 257 258 /* 259 * XXX experimental 260 * 261 * Uses the old serialization system to deserialize itself out of a (new style) shared buffer. 262 * @return remaining sub-buffer (the "payload") 263 * 264 * Note: This is some kind of a hack! handle with care. 265 */ 266 virtual reboost::shared_buffer_t deserialize_from_shared_buffer(reboost::shared_buffer_t buff); 267 227 268 228 269 protected: … … 262 303 * @return A explicit payload serializer 263 304 */ 264 finline PayloadSerializer Payload( size_t length = ~0 ) { 305 finline PayloadSerializer Payload( size_t length = ~0 ) 306 { 307 // assert( ! legacy_payload_disabled ); // FIXME aktuell 308 265 309 return PayloadSerializer( this, length ); 266 310 } -
source/ariba/utility/messages/MessageProvider.cpp
r6919 r12060 37 37 // [License] 38 38 39 #include "MessageProvider.h"40 41 NAMESPACE_BEGIN42 43 MessageProvider::MessageProvider() {44 }45 46 MessageProvider::~MessageProvider() {47 }48 49 bool MessageProvider::sendMessageToReceivers( const Message* message ) {50 bool sent = false;51 for (size_t i=0; i<receivers.size(); i++)52 if (receivers[i]->receiveMessage(message, LinkID::UNSPECIFIED, NodeID::UNSPECIFIED)) sent = true;53 return sent;54 }55 56 void MessageProvider::addMessageReceiver( MessageReceiver* receiver ) {57 receivers.push_back(receiver);58 }59 60 void MessageProvider::removeMessageReceiver( MessageReceiver* receiver ) {61 for (size_t i=0; i<receivers.size(); i++)62 if (receivers[i]==receiver) {63 receivers.erase( receivers.begin()+i );64 break;65 }66 }67 68 NAMESPACE_END39 //#include "MessageProvider.h" 40 // 41 //NAMESPACE_BEGIN 42 // 43 //MessageProvider::MessageProvider() { 44 //} 45 // 46 //MessageProvider::~MessageProvider() { 47 //} 48 // 49 //bool MessageProvider::sendMessageToReceivers( const Message* message ) { 50 // bool sent = false; 51 // for (size_t i=0; i<receivers.size(); i++) 52 // if (receivers[i]->receiveMessage(message, LinkID::UNSPECIFIED, NodeID::UNSPECIFIED)) sent = true; 53 // return sent; 54 //} 55 // 56 //void MessageProvider::addMessageReceiver( MessageReceiver* receiver ) { 57 // receivers.push_back(receiver); 58 //} 59 // 60 //void MessageProvider::removeMessageReceiver( MessageReceiver* receiver ) { 61 // for (size_t i=0; i<receivers.size(); i++) 62 // if (receivers[i]==receiver) { 63 // receivers.erase( receivers.begin()+i ); 64 // break; 65 // } 66 //} 67 // 68 //NAMESPACE_END -
source/ariba/utility/messages/MessageProvider.h
r3690 r12060 1 // XXX DEPRECATED 2 1 3 // [License] 2 4 // The Ariba-Underlay Copyright … … 37 39 // [License] 38 40 41 // XXX DEPRECATED 42 39 43 #ifndef MESSAGEPROVIDER_H_ 40 44 #define MESSAGEPROVIDER_H_ 41 45 42 #include "_namespace.h"43 #include "MessageReceiver.h"44 #include "ariba/utility/types/LinkID.h"45 #include "ariba/utility/types/NodeID.h"46 #include <vector>47 48 using std::vector;49 using ariba::utility::LinkID;50 using ariba::utility::NodeID;51 52 NAMESPACE_BEGIN53 54 55 / **56 * This class defines an interface for message providers.57 * Implementing classes must allow receivers to register themselves.58 *59 * @author Sebastian Mies60 */61 class MessageProvider {62 private:63 vector<MessageReceiver*> receivers;64 65 protected:66 bool sendMessageToReceivers( const Message* message );67 68 public:69 /**70 * Constructor.71 */72 MessageProvider();73 74 /**75 * Destructor.76 */77 ~MessageProvider();78 79 /**80 * Adds a message receiver.81 *82 * @param receiver The receiver.83 */84 void addMessageReceiver( MessageReceiver* receiver );85 86 /**87 * Removes a message receiver.88 *89 * @param receiver The receiver.90 */91 void removeMessageReceiver( MessageReceiver* receiver );92 };93 94 NAMESPACE_END46 //#include "_namespace.h" 47 //#include "MessageReceiver.h" 48 //#include "ariba/utility/types/LinkID.h" 49 //#include "ariba/utility/types/NodeID.h" 50 //#include <vector> 51 // 52 //using std::vector; 53 //using ariba::utility::LinkID; 54 //using ariba::utility::NodeID; 55 // 56 //NAMESPACE_BEGIN 57 // 58 // 59 ///** 60 // * This class defines an interface for message providers. 61 // * Implementing classes must allow receivers to register themselves. 62 // * 63 // * @author Sebastian Mies 64 // */ 65 //class MessageProvider { 66 //private: 67 // vector<MessageReceiver*> receivers; 68 // 69 //protected: 70 // bool sendMessageToReceivers( const Message* message ); 71 // 72 //public: 73 // /** 74 // * Constructor. 75 // */ 76 // MessageProvider(); 77 // 78 // /** 79 // * Destructor. 80 // */ 81 // ~MessageProvider(); 82 // 83 // /** 84 // * Adds a message receiver. 85 // * 86 // * @param receiver The receiver. 87 // */ 88 // void addMessageReceiver( MessageReceiver* receiver ); 89 // 90 // /** 91 // * Removes a message receiver. 92 // * 93 // * @param receiver The receiver. 94 // */ 95 // void removeMessageReceiver( MessageReceiver* receiver ); 96 //}; 97 // 98 //NAMESPACE_END 95 99 96 100 #endif /* MESSAGEPROVIDER_H_ */ -
source/ariba/utility/messages/MessageReceiver.cpp
r3690 r12060 49 49 } 50 50 51 bool MessageReceiver::receiveMessage( const Message*message, const LinkID& link, const NodeID& node ) {52 //std::cout << "UNIMPLEMENTED MessageReceiver got Message:" << (Message*)message << std::endl;53 return false;54 }51 //bool MessageReceiver::receiveMessage( reboost::shared_buffer_t message, const LinkID& link, const NodeID& node ) { 52 // //std::cout << "UNIMPLEMENTED MessageReceiver got Message:" << (Message*)message << std::endl; 53 // return false; 54 //} 55 55 56 56 NAMESPACE_END -
source/ariba/utility/messages/MessageReceiver.h
r3690 r12060 40 40 #define MESSAGERECEIVER_H__ 41 41 42 #include "ariba/utility/messages/Message.h" 42 //#include "ariba/utility/messages/Message.h" 43 // reboost messages 44 #include "ariba/utility/transport/messages/message.hpp" 43 45 #include "ariba/utility/types/LinkID.h" 44 46 #include "ariba/utility/types/NodeID.h" … … 73 75 * @return True, when the message has been accepted. 74 76 */ 75 virtual bool receiveMessage( const Message* message, const LinkID& link, const NodeID& node ); 77 virtual bool receiveMessage( reboost::shared_buffer_t message, 78 const LinkID& link, 79 const NodeID& node, 80 bool bypass_overlay ) = 0; 76 81 }; 77 82 -
source/ariba/utility/misc/Demultiplexer.hpp
r3705 r12060 136 136 137 137 SERVICE_LISTENER_MAP_CITERATOR it = mapServiceListener.find( id ); 138 if( it == mapServiceListener.end() ) return NULL;138 if( it == mapServiceListener.end() ) return 0; 139 139 else return it->second; 140 140 } -
source/ariba/utility/system/StartupWrapper.cpp
r10700 r12060 36 36 // Telematics. 37 37 // [License] 38 39 // XXX NOTE: Use this class with caution! Config support is outdated. 38 40 39 41 #include "StartupWrapper.h" -
source/ariba/utility/system/StartupWrapper.h
r4483 r12060 36 36 // Telematics. 37 37 // [License] 38 39 // XXX NOTE: Use this class with caution! Config support is outdated. 38 40 39 41 #ifndef __STARTUP_WRAPPER_H -
source/ariba/utility/system/SystemQueue.cpp
r7533 r12060 69 69 } 70 70 71 // maps to function call internally to the Event-system 72 void SystemQueue::scheduleCall( const boost::function0<void>& function, uint32_t delay) 73 { 74 // copy function object 75 boost::function0<void>* function_ptr = new boost::function0<void>(); 76 (*function_ptr) = function; 77 78 // schedule special call-event 79 scheduleEvent( SystemEvent(&internal_function_caller, SystemEventType::DEFAULT, function_ptr), delay ); 80 81 } 82 71 83 #ifdef UNDERLAY_OMNET 72 84 void SystemQueue::handleMessage(cMessage* msg){ -
source/ariba/utility/system/SystemQueue.h
r7468 r12060 60 60 #endif 61 61 62 #include <boost/function.hpp> 63 64 62 65 using std::vector; 63 66 using boost::posix_time::ptime; … … 108 111 */ 109 112 void scheduleEvent( const SystemEvent& event, uint32_t delay = 0 ); 113 114 /** 115 * This method schedules a function call in the SystemQueue. 116 * (Like scheduleEvent, but to be used with boost::bind.) 117 * 118 * @param function: The function to be called [void function()] 119 * @param The delay in milli-seconds 120 */ 121 void scheduleCall( const boost::function0<void>& function, uint32_t delay = 0 ); 110 122 111 123 /** … … 170 182 #endif 171 183 184 185 172 186 private: 173 187 … … 235 249 volatile bool systemQueueRunning; 236 250 #endif 237 251 252 253 private: 254 /** 255 * This inner class handles the function-call events. 256 * @see SystemQueue::scheduleCall 257 */ 258 class FunctionCaller : public SystemEventListener 259 { 260 void handleSystemEvent(const SystemEvent& event) 261 { 262 boost::function0<void>* function_ptr = event.getData< boost::function0<void> >(); 263 (*function_ptr)(); 264 delete function_ptr; 265 } 266 }; 267 268 FunctionCaller internal_function_caller; 238 269 }; // class SystemQueue 239 270 -
source/ariba/utility/transport
- Property svn:mergeinfo changed (with no actual effect on merging)
-
source/ariba/utility/transport/CMakeLists.txt
r10700 r12060 38 38 39 39 add_headers( 40 test_transport.hpp41 transport_connection.hpp42 transport.hpp43 transport_listener.hpp44 40 transport_peer.cpp 45 41 transport_peer.hpp 46 transport_protocol.hpp47 42 ) 48 43 49 add_subdir_sources(asio messages rfcomm tcpip) 44 add_subdir_sources(asio messages rfcomm StreamTransport) 45 -
source/ariba/utility/transport/messages/message.cpp
r10653 r12060 24 24 os << "message({size=" << m.size() << ",buffers=" << (int) m.length() 25 25 << ",hash=" << m.hash() << "},"; 26 m. foreach(ts);26 m.msg_foreach(ts); 27 27 os << ")"; 28 28 return os; -
source/ariba/utility/transport/messages/message.hpp
r10653 r12060 17 17 18 18 /// message size type 19 typedef signed char mlength_t; 19 //typedef signed char mlength_t; // <--- don't do this!! 20 //typedef size_t mlength_t; 21 typedef int mlength_t; // signed int seems necessary 20 22 21 23 /// maximum number of buffers per message (default is 8) 22 24 const mlength_t message_max_buffers = (1L << 3); 25 //const mlength_t message_max_buffers = (1L << 4); 23 26 24 27 //! A Copy-on-Write Message with Shared Buffers. … … 70 73 /// Copy message 71 74 inline message_t(const message_t& msg) : 72 imsg(msg.imsg) { 73 imsg->owner = NULL; 75 imsg(msg.imsg) 76 { 77 if ( imsg ) 78 imsg->owner = NULL; 74 79 } 75 80 … … 142 147 /// Returns the number of buffers inside this message. 143 148 inline mlength_t length() const { 149 if ( ! imsg ) 150 return 0; 151 144 152 return (imsg->length); 145 153 } … … 167 175 /// Iterates over a partial set of buffers. 168 176 template<typename T> 169 inline void foreach(const T& work, size_t index_ = 0, size_t size_ = 0) const {177 inline void msg_foreach(const T& work, size_t index_ = 0, size_t size_ = 0) const { 170 178 T op = work; 171 179 if (size_ == 0) size_ = size() - index_; … … 192 200 inline void read(boctet_t* mem, size_t idx = 0, size_t size_ = 0) const { 193 201 struct read_buffer rb = { mem }; 194 foreach(rb, idx, size_);202 msg_foreach(rb, idx, size_); 195 203 } 196 204 … … 198 206 inline void write(const boctet_t* mem, size_t idx = 0, size_t size_ = 0) { 199 207 struct write_buffer wb = { mem }; 200 foreach(wb, idx, size_);208 msg_foreach(wb, idx, size_); 201 209 } 202 210 … … 227 235 message_t m; 228 236 struct sub_message sm = { &m }; 229 foreach(sm, index, size);237 msg_foreach(sm, index, size); 230 238 return m; 231 239 } -
source/ariba/utility/transport/messages/shared_buffer.hpp
r10700 r12060 9 9 10 10 #include <cstring> 11 #include <string> 11 12 #include <boost/shared_ptr.hpp> 12 13 … … 18 19 #include "buffer.hpp" 19 20 21 #include <stdexcept> 22 20 23 namespace reboost { 24 25 class illegal_sub_buffer: public std::runtime_error 26 { 27 public: 28 /** Takes a character string describing the error. */ 29 explicit illegal_sub_buffer(const std::string& __arg) : 30 std::runtime_error(__arg) 31 { 32 } 33 34 virtual ~illegal_sub_buffer() throw() {} 35 }; 21 36 22 37 /** … … 104 119 parent(new deleteable_buffer(buffer, size)) 105 120 { 121 } 122 123 // /// XXX debug... copy! 124 // /// create shared buffer from buffer 125 // inline shared_buffer_t(const char* buffer, bsize_t size) : 126 // buffer_t(), parent(new deleteable_buffer(size)) { 106 127 // memcpy(parent->mutable_data(), buffer, parent->size()); 107 // data(parent->mutable_data()); 108 // this->size(parent->size()); 109 } 128 // data(parent->mutable_data()); this->size(parent->size()); 129 // } 110 130 111 131 /// clone data from a normal buffer … … 129 149 130 150 /// return sub-buffer. 131 inline self operator()(bsize_t index, bsize_t size = 0) const { 151 inline self operator()(bsize_t index, bsize_t size = 0) const 152 { 153 // special cases 154 if ( index + size > size_ ) 155 { 156 // empty sub-buffer 157 if ( index == size_ ) 158 { 159 self n; 160 return n; 161 } 162 163 // ERROR: index out of bounds 164 throw illegal_sub_buffer("Index or size out of bounds in shared_buffer"); 165 } 166 167 // regular case 132 168 self n(*this); 133 169 n.data_ += index; -
source/ariba/utility/transport/rfcomm/CMakeLists.txt
r10700 r12060 40 40 bluetooth_endpoint.hpp 41 41 bluetooth_rfcomm.hpp 42 rfcomm_transport.hpp43 42 ) 44 43 45 add_sources(rfcomm_transport.cpp) 44 #add_sources() 45 -
source/ariba/utility/transport/transport_peer.cpp
r10700 r12060 1 2 #include "ariba/config.h"3 1 #include "transport_peer.hpp" 4 #include "transport.hpp" 5 #include <boost/asio/ip/tcp.hpp> 2 3 // ariba 4 #include "StreamTransport/StreamTransport.hpp" 5 #include "ariba/utility/addressing2/tcpip_endpoint.hpp" 6 7 // boost 6 8 #include <boost/asio/error.hpp> 7 9 #include <boost/foreach.hpp> 8 9 #ifdef ECLIPSE_PARSER10 #define foreach(a, b) for(a : b)11 #else12 #define foreach(a, b) BOOST_FOREACH(a, b)13 #endif14 10 15 11 // namespace ariba::transport … … 17 13 namespace transport { 18 14 19 using namespace a riba::addressing;15 using namespace addressing2; 20 16 using boost::asio::ip::tcp; 21 17 … … 26 22 use_logging_cpp(transport_peer); 27 23 28 transport_peer::transport_peer( endpoint_set& local_set ) : local(local_set) { 29 30 // setup tcp transports 31 foreach(tcp_port_address port, local.tcp) { 24 transport_peer::transport_peer() : 25 local(new addressing2::endpoint_set()) 26 { 27 } 28 29 EndpointSetPtr transport_peer::add_listenOn_endpoints(EndpointSetPtr endpoints) 30 { 31 // TCP Endpoints 32 BOOST_FOREACH( shared_ptr<tcpip_endpoint> endp, endpoints->get_tcpip_endpoints() ) 33 { 34 // automatic port detection 35 bool port_detection = false; 36 uint16_t try_port = 41322; 32 37 33 if (local.ip.size() > 0) { 34 foreach(ip_address ip_addr, local.ip) { 35 36 tcp::endpoint endp(ip_addr.asio(), port.asio()); 37 create_service(endp); 38 } 39 } else { 40 tcp::endpoint endp_v6(tcp::v6(), port.asio()); 41 tcp::endpoint endp_v4(tcp::v4(), port.asio()); 42 43 create_service(endp_v6); 44 create_service(endp_v4); 38 tcp::endpoint asio_endp = endp->to_asio(); 39 if ( asio_endp.port() == 0 ) 40 { 41 port_detection = true; 45 42 } 46 43 47 } 48 44 45 // create new server socket 46 do 47 { 48 try 49 { 50 // automatic port detection 51 if ( port_detection ) 52 { 53 asio_endp.port(try_port); 54 endp = tcpip_endpoint::create_TcpIP_Endpoint(asio_endp); 55 } 56 57 TransportProtocolPtr tmp_ptr(new StreamTransport<tcp>(endp->to_asio())); 58 transport_streams.push_back(tmp_ptr); 59 logging_info("Listening on IP/TCP " << endp->to_string()); 60 61 local->add_endpoint(endp); 62 port_detection = false; 63 } 64 65 catch (boost::system::system_error& e) 66 { 67 // address in use 68 if (e.code() == boost::asio::error::address_in_use) 69 { 70 // BRANCH: automatic port detection 71 if ( port_detection ) 72 { 73 // give up ? 74 if ( try_port > 41422 ) 75 { 76 logging_warn("[WARN] Unable to find free port. Giving up. :-( Last try was: " 77 << endp->to_string() << ". Endpoint will be ignored!"); 78 79 port_detection = false; 80 } 81 else 82 { 83 // try next port 84 try_port++; 85 } 86 } 87 // BRANCH: explicit given port --> error 88 else 89 { 90 logging_warn("[WARN] Address already in use: " 91 << endp->to_string() << ". Endpoint will be ignored!"); 92 } 93 } 94 95 // Rethrow 96 else 97 { 98 throw; 99 } 100 } 101 } while ( port_detection ); 102 } 103 104 // TODO Bluetooth Endpoints 49 105 #ifdef HAVE_LIBBLUETOOTH 50 foreach(rfcomm_channel_address channel, local.rfcomm) {51 if (local.bluetooth.size() > 0) {52 foreach(mac_address mac, local.bluetooth) {53 rfcomm::endpoint endp(mac.bluetooth(), channel.value());54 create_service(endp);55 }56 } else {57 rfcomm::endpoint endp(channel.value());58 create_service(endp);59 }60 }106 // foreach(rfcomm_channel_address channel, local.rfcomm) { 107 // if (local.bluetooth.size() > 0) { 108 // foreach(mac_address mac, local.bluetooth) { 109 // rfcomm::endpoint endp(mac.bluetooth(), channel.value()); 110 // create_service(endp); 111 // } 112 // } else { 113 // rfcomm::endpoint endp(channel.value()); 114 // create_service(endp); 115 // } 116 // } 61 117 #endif 62 } 63 64 void transport_peer::create_service(tcp::endpoint endp) { 65 try { 66 TcpIpPtr tmp_ptr(new tcpip(endp)); 67 tcps.push_back(tmp_ptr); 68 logging_info("Listening on IP/TCP " << endp); 69 70 } catch (boost::system::system_error& e) { 71 if (e.code() == boost::asio::error::address_in_use) { 72 logging_warn("[WARN] Address already in use: " 73 << endp << ". Endpoint will be ignored!"); 74 } else { 75 // Rethrow 76 throw; 77 } 78 } 79 } 118 119 return local; 120 } 121 122 //void transport_peer::create_service(tcp::endpoint endp) { 123 // try { 124 // TransportProtocolPtr tmp_ptr(new StreamTransport<tcp>(endp)); 125 // tcps.push_back(tmp_ptr); 126 // logging_info("Listening on IP/TCP " << endp); 127 // 128 // } catch (boost::system::system_error& e) { 129 // if (e.code() == boost::asio::error::address_in_use) { 130 // logging_warn("[WARN] Address already in use: " 131 // << endp << ". Endpoint will be ignored!"); 132 // } else { 133 // // Rethrow 134 // throw; 135 // } 136 // } 137 //} 80 138 81 139 #ifdef HAVE_LIBBLUETOOTH 82 void transport_peer::create_service(rfcomm::endpoint endp) {83 try {84 rfcomm_transport::sptr tmp_ptr(new rfcomm_transport(endp));85 rfcomms.push_back(tmp_ptr);86 logging_info("Listening on bluetooth/RFCOMM " << endp);87 88 } catch (boost::system::system_error& e) {89 if (e.code() == boost::asio::error::address_in_use) {90 logging_warn("[WARN] Address already in use: "91 << endp << ". Endpoint will be ignored!");92 } else {93 // Rethrow94 throw;95 }96 }97 }140 //void transport_peer::create_service(rfcomm::endpoint endp) { 141 // try { 142 // TransportProtocolPtr tmp_ptr(new StreamTransport<rfcomm>(endp)); 143 // rfcomms.push_back(tmp_ptr); 144 // logging_info("Listening on bluetooth/RFCOMM " << endp); 145 // 146 // } catch (boost::system::system_error& e) { 147 // if (e.code() == boost::asio::error::address_in_use) { 148 // logging_warn("[WARN] Address already in use: " 149 // << endp << ". Endpoint will be ignored!"); 150 // } else { 151 // // Rethrow 152 // throw; 153 // } 154 // } 155 //} 98 156 #endif 99 157 … … 101 159 } 102 160 103 void transport_peer::start() { 104 foreach(TcpIpPtr tcp, tcps) { 105 tcp->start(); 106 } 107 108 #ifdef HAVE_LIBBLUETOOTH 109 foreach(rfcomm_transport::sptr x, rfcomms) { 110 x->start(); 111 } 112 #endif 113 } 114 115 void transport_peer::stop() { 116 foreach(TcpIpPtr tcp, tcps) { 117 tcp->stop(); 118 } 119 120 #ifdef HAVE_LIBBLUETOOTH 121 foreach(rfcomm_transport::sptr x, rfcomms) { 122 x->stop(); 123 } 124 #endif 161 void transport_peer::start() 162 { 163 BOOST_FOREACH(TransportProtocolPtr stream, transport_streams) 164 { 165 stream->start(); 166 } 167 } 168 169 void transport_peer::stop() 170 { 171 BOOST_FOREACH(TransportProtocolPtr stream, transport_streams) 172 { 173 stream->stop(); 174 } 125 175 } 126 176 127 177 128 178 void transport_peer::send( 129 const endpoint_set&endpoints,179 const const_EndpointSetPtr endpoints, 130 180 reboost::message_t message, 131 181 uint8_t priority) 132 182 { 133 foreach(TcpIpPtr tcp, tcps) { 134 tcp->send(endpoints, message, priority); 135 } 136 137 #ifdef HAVE_LIBBLUETOOTH 138 foreach(rfcomm_transport::sptr x, rfcomms) { 139 x->send(endpoints, message, priority); 140 } 141 #endif 142 } 143 144 void transport_peer::terminate( const address_v* remote ) { 145 if (remote->instanceof<tcpip_endpoint>())// TODO direkt auf der richtigen verbindung 146 { 147 foreach(TcpIpPtr tcp, tcps) { 148 tcp->terminate(remote); 149 } 150 } 151 #ifdef HAVE_LIBBLUETOOTH 152 if (remote->instanceof<rfcomm_endpoint>()) { 153 foreach(rfcomm_transport::sptr x, rfcomms) { 154 x->terminate(remote); 155 } 156 } 157 #endif 158 } 159 160 void transport_peer::register_listener( transport_listener* listener ) { 161 foreach(TcpIpPtr tcp, tcps) { 162 tcp->register_listener(listener); 163 } 164 165 #ifdef HAVE_LIBBLUETOOTH 166 foreach(rfcomm_transport::sptr x, rfcomms) { 167 x->register_listener(listener); 168 } 169 #endif 183 BOOST_FOREACH(TransportProtocolPtr stream, transport_streams) 184 { 185 stream->send(endpoints, message, priority); 186 } 187 } 188 189 // XXX DEPRECATED 190 //void transport_peer::terminate( const address_v* remote ) { 191 // if (remote->instanceof<tcpip_endpoint>())// TODO direkt auf der richtigen verbindung 192 // { 193 // foreach(TransportProtocolPtr tcp, tcps) { 194 // tcp->terminate(remote); 195 // } 196 // } 197 //#ifdef HAVE_LIBBLUETOOTH 198 // if (remote->instanceof<rfcomm_endpoint>()) { 199 // foreach(TransportProtocolPtr x, rfcomms) { 200 // x->terminate(remote); 201 // } 202 // } 203 //#endif 204 //} 205 206 void transport_peer::register_listener( transport_listener* listener ) 207 { 208 BOOST_FOREACH(TransportProtocolPtr stream, transport_streams) 209 { 210 stream->register_listener(listener); 211 } 170 212 } 171 213 -
source/ariba/utility/transport/transport_peer.hpp
r10700 r12060 2 2 #define TRANSPORT_PEER_HPP_ 3 3 4 // ariba 4 5 #include "ariba/config.h" 5 6 #include "ariba/utility/logging/Logging.h" 6 #include "transport_protocol.hpp" 7 #include "ariba/utility/addressing/endpoint_set.hpp" 7 #include "ariba/utility/addressing2/endpoint_set.hpp" 8 9 // ariba interfaces 10 #include "interfaces/transport_protocol.hpp" 11 12 // boost 8 13 #include <boost/shared_ptr.hpp> 9 #include "rfcomm/bluetooth_rfcomm.hpp" 14 15 // boost-adaption 16 //#include "rfcomm/bluetooth_rfcomm.hpp" 10 17 11 18 … … 14 21 namespace transport { 15 22 16 using namespace ariba::addressing;17 18 class tcpip;19 20 #ifdef HAVE_LIBBLUETOOTH21 class rfcomm_transport;22 #endif23 24 23 /** 25 * TODO: Doc 24 * This class allocates implementations of various transport 25 * protocols and can send messages to an entire set of endpoints 26 26 * 27 * @author Sebastian Mies <mies@tm.uka.de> 27 * @author Sebastian Mies <mies@tm.uka.de>, Mario Hock 28 28 */ 29 /// this transport peer allocates implementations of various transport 30 /// protocols and can send messages to an entire set of endpoints 31 class transport_peer : public transport_protocol{29 class transport_peer : 30 public transport_protocol 31 { 32 32 use_logging_h(transport_peer); 33 typedef boost::shared_ptr<transport_protocol> TransportProtocolPtr; 34 33 35 public: 34 transport_peer( endpoint_set& local_set ); 36 transport_peer(); 37 38 /** 39 * Adds endpoints on which ariba should listen ("server"-sockets) 40 * 41 * @return An endpoint_set holding all active endpoints ariba is listening on. 42 */ 43 addressing2::EndpointSetPtr add_listenOn_endpoints(addressing2::EndpointSetPtr endpoints); 44 35 45 virtual ~transport_peer(); 36 46 virtual void start(); … … 38 48 39 49 virtual void send( 40 const endpoint_set&endpoints,50 const addressing2::const_EndpointSetPtr endpoints, 41 51 reboost::message_t message, 42 uint8_t priority = 0); 43 44 /// @deprecated: Use terminate() from transport_connection instead 45 virtual void terminate( const address_v* remote ); 46 52 uint8_t priority = system_priority::OVERLAY); 53 47 54 virtual void register_listener( transport_listener* listener ); 48 55 56 49 57 private: 50 void create_service(tcp::endpoint endp); 51 #ifdef HAVE_LIBBLUETOOTH 52 void create_service(boost::asio::bluetooth::rfcomm::endpoint endp); 53 #endif 54 55 endpoint_set& local; 56 std::vector< boost::shared_ptr<tcpip> > tcps; 57 #ifdef HAVE_LIBBLUETOOTH 58 std::vector< boost::shared_ptr<rfcomm_transport> > rfcomms; 59 #endif 58 addressing2::EndpointSetPtr local; 59 std::vector<TransportProtocolPtr> transport_streams; 60 60 }; 61 61 -
source/ariba/utility/types/Identifier.h
r4625 r12060 50 50 #include "ariba/utility/serialization.h" 51 51 52 // XXX EXPERIMENTAL 53 #include "ariba/utility/transport/messages/shared_buffer.hpp" 54 52 55 /**< maximum length of the key */ 53 56 #define MAX_KEYLENGTH 192 … … 69 72 use_logging_h( Identifier ); 70 73 public: 74 75 // XXX EXPERIMENTAL 76 reboost::shared_buffer_t serialize() const 77 { 78 Data data = data_serialize(this, DEFAULT_V); 79 reboost::shared_buffer_t buf(data.getBuffer(), data.getLength() / 8); 80 81 return buf; 82 } 83 84 reboost::shared_buffer_t deserialize(reboost::shared_buffer_t buff) 85 { 86 Data dat(const_cast<uint8_t*>(buff.data()), buff.size() * 8); 87 88 size_t len = this->SERIALIZATION_METHOD_NAME(DESERIALIZE, dat) / 8; 89 90 // return remaining sub-buffer 91 return buff(len); 92 } 93 71 94 72 95 //------------------------------------------------------------------------- -
source/ariba/utility/types/OverlayParameterSet.h
r4625 r12060 53 53 54 54 typedef enum _OverlayStructure { 55 OverlayStructureOneHop = 0, 55 OverlayStructureOneHop = 0, // DEPRECATED, DO NOT USE 56 56 OverlayStructureChord = 1, 57 57 } OverlayStructure; -
source/ariba/utility/types/ServiceID.cpp
r3690 r12060 76 76 } 77 77 78 string ServiceID::toString() const { 78 string ServiceID::toString() const 79 { 80 if ( *this == ServiceID::UNSPECIFIED ) 81 return "UNSPEC"; 82 79 83 return ariba::utility::Helper::ultos( id ); 80 84 }
Note:
See TracChangeset
for help on using the changeset viewer.