00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef _BUNDLE_EVENT_H_
00039 #define _BUNDLE_EVENT_H_
00040
00041 #include "Bundle.h"
00042 #include "BundleRef.h"
00043 #include "BundleList.h"
00044 #include "CustodySignal.h"
00045 #include "contacts/Link.h"
00046
00047 namespace dtn {
00048
00055 class Bundle;
00056 class Contact;
00057 class Registration;
00058 class RouteEntry;
00059 class Link;
00060
00064 typedef enum {
00065 BUNDLE_RECEIVED = 0x1,
00066 BUNDLE_TRANSMITTED,
00067 BUNDLE_TRANSMIT_FAILED,
00068 BUNDLE_DELIVERED,
00069 BUNDLE_EXPIRED,
00070 BUNDLE_FREE,
00071 BUNDLE_FORWARD_TIMEOUT,
00072
00073 CONTACT_UP,
00074 CONTACT_DOWN,
00075
00076 LINK_CREATED,
00077 LINK_DELETED,
00078 LINK_AVAILABLE,
00079 LINK_UNAVAILABLE,
00080
00081 LINK_STATE_CHANGE_REQUEST,
00082
00083 REASSEMBLY_COMPLETED,
00084
00085 REGISTRATION_ADDED,
00086 REGISTRATION_REMOVED,
00087 REGISTRATION_EXPIRED,
00088
00089 ROUTE_ADD,
00090 ROUTE_DEL,
00091
00092 CUSTODY_SIGNAL,
00093 CUSTODY_TIMEOUT,
00094
00095 DAEMON_SHUTDOWN,
00096 DAEMON_STATUS,
00097
00098 } event_type_t;
00099
00103 inline const char*
00104 event_to_str(event_type_t event)
00105 {
00106 switch(event) {
00107
00108 case BUNDLE_RECEIVED: return "BUNDLE_RECEIVED";
00109 case BUNDLE_TRANSMITTED: return "BUNDLE_TRANSMITTED";
00110 case BUNDLE_TRANSMIT_FAILED:return "BUNDLE_TRANSMIT_FAILED";
00111 case BUNDLE_DELIVERED: return "BUNDLE_DELIVERED";
00112 case BUNDLE_EXPIRED: return "BUNDLE_EXPIRED";
00113 case BUNDLE_FREE: return "BUNDLE_FREE";
00114 case BUNDLE_FORWARD_TIMEOUT:return "BUNDLE_FORWARD_TIMEOUT";
00115
00116 case CONTACT_UP: return "CONTACT_UP";
00117 case CONTACT_DOWN: return "CONTACT_DOWN";
00118
00119 case LINK_CREATED: return "LINK_CREATED";
00120 case LINK_DELETED: return "LINK_DELETED";
00121 case LINK_AVAILABLE: return "LINK_AVAILABLE";
00122 case LINK_UNAVAILABLE: return "LINK_UNAVAILABLE";
00123
00124 case LINK_STATE_CHANGE_REQUEST:return "LINK_STATE_CHANGE_REQUEST";
00125
00126 case REASSEMBLY_COMPLETED: return "REASSEMBLY_COMPLETED";
00127
00128 case REGISTRATION_ADDED: return "REGISTRATION_ADDED";
00129 case REGISTRATION_REMOVED: return "REGISTRATION_REMOVED";
00130 case REGISTRATION_EXPIRED: return "REGISTRATION_EXPIRED";
00131
00132 case ROUTE_ADD: return "ROUTE_ADD";
00133 case ROUTE_DEL: return "ROUTE_DEL";
00134
00135 case CUSTODY_SIGNAL: return "CUSTODY_SIGNAL";
00136 case CUSTODY_TIMEOUT: return "CUSTODY_TIMEOUT";
00137
00138 case DAEMON_SHUTDOWN: return "SHUTDOWN";
00139 case DAEMON_STATUS: return "DAEMON_STATUS";
00140
00141 default: return "(invalid event type)";
00142 }
00143 }
00144
00148 typedef enum {
00149 EVENTSRC_PEER = 1,
00150 EVENTSRC_APP = 2,
00151 EVENTSRC_STORE = 3,
00152 EVENTSRC_ADMIN = 4,
00153 EVENTSRC_FRAGMENTATION = 5
00154 } event_source_t;
00155
00159 class BundleEvent {
00160 public:
00164 const event_type_t type_;
00165
00171 bool daemon_only_;
00172
00176 oasys::Notifier* processed_notifier_;
00177
00181 const char* type_str() {
00182 return event_to_str(type_);
00183 }
00184
00190 virtual ~BundleEvent()
00191 {
00192 if (processed_notifier_) {
00193 processed_notifier_->notify();
00194 }
00195 }
00196
00197 protected:
00202 BundleEvent(event_type_t type)
00203 : type_(type),
00204 daemon_only_(false),
00205 processed_notifier_(NULL) {}
00206 };
00207
00211 class BundleReceivedEvent : public BundleEvent {
00212 public:
00213
00214
00215
00216
00217 BundleReceivedEvent(Bundle* bundle,
00218 event_source_t source,
00219 size_t bytes_received = 0)
00220
00221 : BundleEvent(BUNDLE_RECEIVED),
00222 bundleref_(bundle, "BundleReceivedEvent"),
00223 source_(source)
00224 {
00225 if (bytes_received != 0)
00226 bytes_received_ = bytes_received;
00227 else
00228 bytes_received_ = bundle->payload_.length();
00229 }
00230
00232 BundleRef bundleref_;
00233
00235 event_source_t source_;
00236
00238 size_t bytes_received_;
00239 };
00240
00244 class BundleTransmittedEvent : public BundleEvent {
00245 public:
00246 BundleTransmittedEvent(Bundle* bundle, const ContactRef& contact,
00247 size_t bytes_sent, size_t reliably_sent)
00248 : BundleEvent(BUNDLE_TRANSMITTED),
00249 bundleref_(bundle, "BundleTransmittedEvent"),
00250 contact_(contact.object(), "BundleTransmittedEvent"),
00251 bytes_sent_(bytes_sent),
00252 reliably_sent_(reliably_sent) {}
00253
00255 BundleRef bundleref_;
00256
00258 ContactRef contact_;
00259
00261 size_t bytes_sent_;
00262
00266 size_t reliably_sent_;
00267 };
00268
00274 class BundleTransmitFailedEvent : public BundleEvent {
00275 public:
00276 BundleTransmitFailedEvent(Bundle* bundle, const ContactRef& contact)
00277 : BundleEvent(BUNDLE_TRANSMIT_FAILED),
00278 bundleref_(bundle, "BundleTransmitFailedEvent"),
00279 contact_(contact.object(), "BundleTransmitFailedEvent") {}
00280
00282 BundleRef bundleref_;
00283
00285 ContactRef contact_;
00286 };
00287
00291 class BundleDeliveredEvent : public BundleEvent {
00292 public:
00293 BundleDeliveredEvent(Bundle* bundle, Registration* registration)
00294 : BundleEvent(BUNDLE_DELIVERED),
00295 bundleref_(bundle, "BundleDeliveredEvent"),
00296 registration_(registration) {}
00297
00298
00300 BundleRef bundleref_;
00301
00303 Registration* registration_;
00304 };
00305
00309 class BundleExpiredEvent : public BundleEvent {
00310 public:
00311 BundleExpiredEvent(Bundle* bundle)
00312 : BundleEvent(BUNDLE_EXPIRED),
00313 bundleref_(bundle, "BundleExpiredEvent") {}
00314
00316 BundleRef bundleref_;
00317 };
00318
00322 class BundleFreeEvent : public BundleEvent {
00323 public:
00324 BundleFreeEvent(Bundle* bundle)
00325 : BundleEvent(BUNDLE_FREE),
00326 bundle_(bundle)
00327 {
00328
00329 daemon_only_ = true;
00330 }
00331
00333 Bundle* bundle_;
00334 };
00335
00340 class ContactEvent : public BundleEvent {
00341 public:
00345 typedef enum {
00346 INVALID = 0,
00347 NO_INFO,
00348 USER,
00349 BROKEN,
00350 SHUTDOWN,
00351 RECONNECT,
00352 IDLE,
00353 TIMEOUT,
00354 UNBLOCKED
00355 } reason_t;
00356
00360 static const char* reason_to_str(reason_t reason) {
00361 switch(reason) {
00362 case INVALID: return "INVALID";
00363 case NO_INFO: return "no additional info";
00364 case USER: return "user action";
00365 case SHUTDOWN: return "peer shut down";
00366 case BROKEN: return "connection broken";
00367 case RECONNECT: return "re-establishing connection";
00368 case IDLE: return "connection idle";
00369 case TIMEOUT: return "schedule timed out";
00370 case UNBLOCKED: return "no longer busy";
00371 }
00372 NOTREACHED;
00373 }
00374
00376 ContactEvent(event_type_t type, reason_t reason = NO_INFO)
00377 : BundleEvent(type), reason_(reason) {}
00378
00379 reason_t reason_;
00380 };
00381
00385 class ContactUpEvent : public ContactEvent {
00386 public:
00387 ContactUpEvent(const ContactRef& contact)
00388 : ContactEvent(CONTACT_UP),
00389 contact_(contact.object(), "ContactUpEvent") {}
00390
00392 ContactRef contact_;
00393 };
00394
00398 class ContactDownEvent : public ContactEvent {
00399 public:
00400 ContactDownEvent(const ContactRef& contact, reason_t reason)
00401 : ContactEvent(CONTACT_DOWN, reason),
00402 contact_(contact.object(), "ContactDownEvent") {}
00403
00405 ContactRef contact_;
00406 };
00407
00411 class LinkCreatedEvent : public ContactEvent {
00412 public:
00413 LinkCreatedEvent(Link* link)
00414 : ContactEvent(LINK_CREATED, ContactEvent::USER), link_(link) {}
00415
00416 Link* link_;
00417 };
00418
00422 class LinkDeletedEvent : public ContactEvent {
00423 public:
00424 LinkDeletedEvent(Link* link)
00425 : ContactEvent(LINK_DELETED, ContactEvent::USER), link_(link) {}
00426
00428 Link* link_;
00429 };
00430
00434 class LinkAvailableEvent : public ContactEvent {
00435 public:
00436 LinkAvailableEvent(Link* link, reason_t reason)
00437 : ContactEvent(LINK_AVAILABLE, reason), link_(link) {}
00438
00439 Link* link_;
00440 };
00441
00445 class LinkUnavailableEvent : public ContactEvent {
00446 public:
00447 LinkUnavailableEvent(Link* link, reason_t reason)
00448 : ContactEvent(LINK_UNAVAILABLE, reason), link_(link) {}
00449
00451 Link* link_;
00452 };
00453
00462 class LinkStateChangeRequest : public ContactEvent {
00463 public:
00465 typedef Link::state_t state_t;
00466
00467 LinkStateChangeRequest(Link* link, state_t state, reason_t reason)
00468 : ContactEvent(LINK_STATE_CHANGE_REQUEST, reason),
00469 link_(link), state_(state), contact_("LinkStateChangeRequest")
00470 {
00471 daemon_only_ = true;
00472
00473 contact_ = link->contact();
00474 old_state_ = link->state();
00475 }
00476
00478 Link* link_;
00479
00481 state_t state_;
00482
00484 ContactRef contact_;
00485
00487 state_t old_state_;
00488 };
00489
00493 class RegistrationAddedEvent : public BundleEvent {
00494 public:
00495 RegistrationAddedEvent(Registration* reg, event_source_t source)
00496 : BundleEvent(REGISTRATION_ADDED), registration_(reg),
00497 source_(source) {}
00498
00500 Registration* registration_;
00501
00503 event_source_t source_;
00504 };
00505
00509 class RegistrationRemovedEvent : public BundleEvent {
00510 public:
00511 RegistrationRemovedEvent(Registration* reg)
00512 : BundleEvent(REGISTRATION_REMOVED), registration_(reg) {}
00513
00515 Registration* registration_;
00516 };
00517
00521 class RegistrationExpiredEvent : public BundleEvent {
00522 public:
00523 RegistrationExpiredEvent(u_int32_t regid)
00524 : BundleEvent(REGISTRATION_EXPIRED), regid_(regid) {}
00525
00527 u_int32_t regid_;
00528 };
00529
00533 class RouteAddEvent : public BundleEvent {
00534 public:
00535 RouteAddEvent(RouteEntry* entry)
00536 : BundleEvent(ROUTE_ADD), entry_(entry) {}
00537
00539 RouteEntry* entry_;
00540 };
00541
00545 class RouteDelEvent : public BundleEvent {
00546 public:
00547 RouteDelEvent(const EndpointIDPattern& dest)
00548 : BundleEvent(ROUTE_DEL), dest_(dest) {}
00549
00551 EndpointIDPattern dest_;
00552 };
00553
00557 class ReassemblyCompletedEvent : public BundleEvent {
00558 public:
00559 ReassemblyCompletedEvent(Bundle* bundle, BundleList* fragments)
00560 : BundleEvent(REASSEMBLY_COMPLETED),
00561 bundle_(bundle, "ReassemblyCompletedEvent"),
00562 fragments_("ReassemblyCompletedEvent")
00563 {
00564 fragments->move_contents(&fragments_);
00565 }
00566
00568 BundleRef bundle_;
00569
00571 BundleList fragments_;
00572 };
00573
00577 class CustodySignalEvent : public BundleEvent {
00578 public:
00579 CustodySignalEvent(const CustodySignal::data_t& data)
00580 : BundleEvent(CUSTODY_SIGNAL), data_(data) {}
00581
00583 CustodySignal::data_t data_;
00584 };
00585
00589 class CustodyTimeoutEvent : public BundleEvent {
00590 public:
00591 CustodyTimeoutEvent(Bundle* bundle, Link* link)
00592 : BundleEvent(CUSTODY_TIMEOUT),
00593 bundle_(bundle, "CustodyTimeoutEvent"),
00594 link_(link) {}
00595
00597 BundleRef bundle_;
00598
00600 Link* link_;
00601 };
00602
00609 class ShutdownRequest : public BundleEvent {
00610 public:
00611 ShutdownRequest() : BundleEvent(DAEMON_SHUTDOWN)
00612 {
00613 daemon_only_ = true;
00614 }
00615 };
00616
00620 class StatusRequest : public BundleEvent {
00621 public:
00622 StatusRequest() : BundleEvent(DAEMON_STATUS)
00623 {
00624 daemon_only_ = true;
00625 }
00626 };
00627
00628 }
00629
00630 #endif