00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifdef HAVE_CONFIG_H
00018 # include <dtn-config.h>
00019 #endif
00020
00021 #include "APIRegistration.h"
00022 #include "bundling/Bundle.h"
00023 #include "bundling/BundleDaemon.h"
00024 #include "bundling/BundleList.h"
00025 #include "session/Session.h"
00026
00027 namespace dtn {
00028
00029
00030 APIRegistration::APIRegistration(const oasys::Builder& builder)
00031 : Registration(builder)
00032 {
00033 bundle_list_ = new BlockingBundleList(logpath_);
00034 session_notify_list_ = NULL;
00035 }
00036
00037
00038 APIRegistration::APIRegistration(u_int32_t regid,
00039 const EndpointIDPattern& endpoint,
00040 failure_action_t action,
00041 u_int32_t session_flags,
00042 u_int32_t expiration,
00043 const std::string& script)
00044 : Registration(regid, endpoint, action, session_flags, expiration, script)
00045 {
00046 bundle_list_ = new BlockingBundleList(logpath_);
00047 if (session_flags & Session::CUSTODY) {
00048 session_notify_list_ = new BlockingBundleList(logpath_);
00049 session_notify_list_->logpath_appendf("/session_notify");
00050 } else {
00051 session_notify_list_ = NULL;
00052 }
00053 }
00054
00055
00056 void
00057 APIRegistration::serialize(oasys::SerializeAction* a)
00058 {
00059 Registration::serialize(a);
00060
00061 if (a->action_code() == oasys::Serialize::UNMARSHAL &&
00062 (session_flags_ & Session::CUSTODY))
00063 {
00064 session_notify_list_ = new BlockingBundleList(logpath_);
00065 session_notify_list_->logpath_appendf("/session_notify");
00066 }
00067 }
00068
00069
00070 APIRegistration::~APIRegistration()
00071 {
00072 delete bundle_list_;
00073 if (session_notify_list_) {
00074 delete session_notify_list_;
00075 }
00076 }
00077
00078
00079 void
00080 APIRegistration::deliver_bundle(Bundle* bundle)
00081 {
00082 if (!active() && (failure_action_ == DROP)) {
00083 log_info("deliver_bundle: "
00084 "dropping bundle id %d for passive registration %d (%s)",
00085 bundle->bundleid(), regid_, endpoint_.c_str());
00086
00087
00088 BundleDaemon::post(new BundleDeliveredEvent(bundle, this));
00089 return;
00090 }
00091
00092 if (!active() && (failure_action_ == EXEC)) {
00093
00094
00095 log_info("deliver_bundle: "
00096 "running script '%s' for registration %d (%s)",
00097 script_.c_str(), regid_, endpoint_.c_str());
00098
00099 system(script_.c_str());
00100
00101 }
00102
00103 log_info("deliver_bundle: queuing bundle id %d for %s delivery to %s",
00104 bundle->bundleid(),
00105 active() ? "active" : "deferred",
00106 endpoint_.c_str());
00107
00108 if (BundleDaemon::instance()->params_.test_permuted_delivery_) {
00109 bundle_list_->insert_random(bundle);
00110 } else {
00111 bundle_list_->push_back(bundle);
00112 }
00113 }
00114
00115
00116 void
00117 APIRegistration::session_notify(Bundle* bundle)
00118 {
00119 log_debug("session_notify *%p", bundle);
00120 session_notify_list_->push_back(bundle);
00121 }
00122
00123 }