00001 /* 00002 * Copyright 2004-2006 Intel Corporation 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 #ifndef _FILE_CONVERGENCE_LAYER_H_ 00018 #define _FILE_CONVERGENCE_LAYER_H_ 00019 00020 #include "ConvergenceLayer.h" 00021 #include <oasys/thread/Thread.h> 00022 00023 namespace dtn { 00024 00025 class FileConvergenceLayer : public ConvergenceLayer { 00026 public: 00030 FileConvergenceLayer(); 00031 00033 00034 virtual bool interface_up(Interface* iface, 00035 int argc, const char* argv[]); 00036 virtual bool interface_down(Interface* iface); 00037 virtual bool open_contact(const ContactRef& contact); 00038 virtual bool close_contact(const ContactRef& contact); 00039 virtual void send_bundle(const ContactRef& contact, Bundle* bundle); 00040 00041 protected: 00045 static const int CURRENT_VERSION = 0x1; 00046 00050 struct FileHeader { 00051 u_int8_t version; 00052 u_int8_t pad; 00053 u_int16_t header_length; 00054 u_int32_t bundle_length; 00055 } __attribute__((packed)); 00056 00060 bool extract_dir(const char* nexthop, std::string* dirp); 00061 00066 bool validate_dir(const std::string& dir); 00067 00072 class Scanner : public CLInfo, public oasys::Logger, public oasys::Thread { 00073 public: 00077 Scanner(int secs_per_scan, const std::string& dir); 00078 00082 void stop(); 00083 00087 virtual void serialize( oasys::SerializableObject *) {} 00088 00089 protected: 00093 void run(); 00094 00095 int secs_per_scan_; 00096 std::string dir_; 00097 bool run_; 00098 }; 00099 }; 00100 00101 } // namespace dtn 00102 00103 #endif /* _FILE_CONVERGENCE_LAYER_H_ */