00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "APIRegistration.h"
00019 #include "bundling/Bundle.h"
00020 #include "bundling/BundleDaemon.h"
00021 #include "bundling/BundleList.h"
00022
00023 namespace dtn {
00024
00025 APIRegistration::APIRegistration(const oasys::Builder& builder)
00026 : Registration(builder)
00027 {
00028 bundle_list_ = new BlockingBundleList(logpath_);
00029 }
00030
00031 APIRegistration::APIRegistration(u_int32_t regid,
00032 const EndpointIDPattern& endpoint,
00033 failure_action_t action,
00034 u_int32_t expiration,
00035 const std::string& script)
00036 : Registration(regid, endpoint, action, expiration, script)
00037 {
00038 bundle_list_ = new BlockingBundleList(logpath_);
00039 }
00040
00041 APIRegistration::~APIRegistration()
00042 {
00043 delete bundle_list_;
00044 }
00045
00046 void
00047 APIRegistration::deliver_bundle(Bundle* bundle)
00048 {
00049 if (!active() && (failure_action_ == DROP)) {
00050 log_info("deliver_bundle: "
00051 "dropping bundle id %d for passive registration %d (%s)",
00052 bundle->bundleid_, regid_, endpoint_.c_str());
00053
00054
00055 BundleDaemon::post(new BundleDeliveredEvent(bundle, this));
00056 return;
00057 }
00058
00059 if (!active() && (failure_action_ == EXEC)) {
00060
00061
00062 log_info("deliver_bundle: "
00063 "running script '%s' for registration %d (%s)",
00064 script_.c_str(), regid_, endpoint_.c_str());
00065
00066 system(script_.c_str());
00067
00068 }
00069
00070 log_info("deliver_bundle: queuing bundle id %d for %s delivery to %s",
00071 bundle->bundleid_,
00072 active() ? "active" : "deferred",
00073 endpoint_.c_str());
00074
00075 if (BundleDaemon::instance()->params_.test_permuted_delivery_) {
00076 bundle_list_->insert_random(bundle);
00077 } else {
00078 bundle_list_->push_back(bundle);
00079 }
00080 }
00081
00082
00083 }