TcaControlBundle.h

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2005-2006 University of Waterloo
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
00015  */
00016 
00017 
00018 #ifndef _TCA_CONTROLBUNDLE_H_
00019 #define _TCA_CONTROLBUNDLE_H_
00020 
00021 
00022 // Warning: This file is included by both the dtnd and the tca_admin app.
00023 // Any changes here must be okay for both apps.
00024 
00025 #include <string>
00026 #include <vector>
00027 
00028 namespace dtn {
00029 
00030 // TODO: Make individual subclass for each TcaControlBundle type
00031 // and add strong argument checking (number of args, syntax, even semantic
00032 // correctness in some cases)
00033 
00034 // Note: args can be appended manually, using args_.push_back(arg)
00035 
00036 class TcaControlBundle
00037 {
00038 public:
00039 
00040     enum TypeCode {
00041         CB_NULL,
00042         CB_ADV,
00043         CB_ADV_SENT,
00044         CB_ASK,
00045         CB_ASK_RECEIVED,
00046         CB_ASK_SENT,
00047         CB_COA,
00048         CB_COA_SENT,
00049         CB_REG_RECEIVED,
00050         CB_ROUTES,
00051         CB_UNB,
00052         CB_LINK_ANNOUNCE,
00053         CB_LINK_AVAILABLE,
00054         CB_LINK_UNAVAILABLE,
00055         CB_CONTACT_UP,
00056         CB_CONTACT_DOWN,
00057         CB_UNKNOWN              // error: unrecognized code
00058     };
00059 
00060     TypeCode type_;
00061     std::string code_;
00062     std::vector<std::string> args_;
00063 
00064     TcaControlBundle() : type_(CB_NULL), code_(),  args_() { };
00065 
00066     // construct from Bundle payload, parsing out code and args
00067     // you can also just give a code here to construct an argless bundle
00068     TcaControlBundle(const std::string& payload);
00069     
00070     virtual ~TcaControlBundle() { }
00071 
00072     // retrieve as string (suitable for sending as bundle payload)
00073     virtual std::string str() const;
00074 
00075     void dump(const std::string& intro) const;
00076 
00077     // todo: remove this from public interface someday
00078     static std::string eat_to_tab(std::string& s);
00079 
00080 protected:
00081 
00082     static bool parse_payload(const std::string& payload,
00083                               TypeCode& type,
00084                               std::string& code, std::string& body);
00085 
00086 };
00087 
00088 
00089 // A TcaWrappedBundle is a TcaControlBundle that includes a source and
00090 // dest field as args_[0] and args_[1] respectively. This is useful for
00091 // "tunnelling" regular addressed bundles over the control API, preserving
00092 // their source and dest fields.
00093 
00094 
00095 class TcaWrappedBundle : public TcaControlBundle
00096 {
00097 public:
00098 
00099     // construct directly from string
00100     TcaWrappedBundle(const std::string& payload) : TcaControlBundle(payload) {}
00101     
00102     // construct from existing ControlBundle
00103     TcaWrappedBundle(const TcaControlBundle& cb) : TcaControlBundle(cb) {}
00104 
00105     // construct empty but addressed bundle
00106     TcaWrappedBundle(const std::string& code,
00107                      const std::string& src, const std::string& dest);
00108 
00109     const std::string source() const;
00110     const std::string dest() const;
00111 
00112     void append_arg(const std::string& arg) { args_.push_back(arg); }
00113 };
00114 
00115 } // namespace dtn
00116 
00117 #endif /* _TCA_CONTROLBUNDLE_H_ */

Generated on Sat Sep 8 08:36:18 2007 for DTN Reference Implementation by  doxygen 1.5.3