00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _ANNOUNCE_H_
00018 #define _ANNOUNCE_H_
00019
00020 #include <oasys/debug/Log.h>
00021 #include <oasys/thread/Timer.h>
00022 #include <string>
00023 #include "naming/EndpointID.h"
00024 #include "conv_layers/ConvergenceLayer.h"
00025
00026 #ifndef FOUR_BYTE_ALIGN
00027 #define FOUR_BYTE_ALIGN(x) (((x) % 4) != 0) ? ((x) + (4 - ((x) % 4))) : (x)
00028 #endif
00029
00030 namespace dtn {
00031
00042 class Announce : public oasys::Logger
00043 {
00044 public:
00045
00049 const std::string& name() { return name_; }
00050
00054 const std::string& type() { return type_; }
00055
00060 const std::string& local_addr() { return local_; }
00061
00065 virtual size_t format_advertisement(u_char* buf, size_t len) = 0;
00066
00067 virtual ~Announce() {}
00068
00073 u_int interval_remaining()
00074 {
00075 struct timeval now;
00076 ::gettimeofday(&now,0);
00077 u_int timediff = TIMEVAL_DIFF_MSEC(now,data_sent_);
00078 if (timediff > interval_)
00079 return 0;
00080
00081 return (interval_ - timediff);
00082 }
00083
00087 static Announce* create_announce(const std::string& name,
00088 ConvergenceLayer* cl,
00089 int argc, const char* argv[]);
00090
00094 u_int interval() { return interval_; }
00095
00096 protected:
00097 Announce(const char* logpath = "/dtn/discovery/announce")
00098 : oasys::Logger("Announce","%s",logpath),
00099 cl_(NULL), interval_(0)
00100 {
00101 ::gettimeofday(&data_sent_,0);
00102 }
00103
00104 virtual bool configure(const std::string& name,
00105 ConvergenceLayer* cl,
00106 int argc, const char* argv[]) = 0;
00107
00108 ConvergenceLayer* cl_;
00109 std::string local_;
00110 std::string name_;
00111 std::string type_;
00112 u_int interval_;
00113
00114 struct timeval data_sent_;
00115 private:
00116 Announce(const Announce&)
00117 : oasys::Logger("Announce","/dtn/discovery/beacon") {}
00118 };
00119
00120 }
00121
00122 #endif // _ANNOUNCE_H_