file_transfer_infoton.cpp

Go to the documentation of this file.
00001 #ifndef FILE_TRANSFER_INFOTON_IMPLEMENTATION_FILE
00002 #define FILE_TRANSFER_INFOTON_IMPLEMENTATION_FILE
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : file_transfer_infoton                                             *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 2005-$now By Author.  This program is free software; you can  *
00011 * redistribute it and/or modify it under the terms of the GNU General Public  *
00012 * License as published by the Free Software Foundation; either version 2 of   *
00013 * the License or (at your option) any later version.  This is online at:      *
00014 *     http://www.fsf.org/copyleft/gpl.html                                    *
00015 * Please send any updates to: fred@gruntose.com                               *
00016 \*****************************************************************************/
00017 
00018 #include "file_transfer_infoton.h"
00019 
00020 #include <basis/mutex.h>
00021 #include <basis/string_array.h>
00022 #include <data_struct/static_memory_gremlin.h>
00023 #include <opsystem/directory_tree.h>
00024 
00025 using namespace basis;
00026 
00027 file_transfer_infoton::file_transfer_infoton()
00028 : infoton(file_transfer_classifier()),
00029   _success(common::OKAY),
00030   _request(false),
00031   _command(TREE_COMPARISON),
00032   _src_root(),
00033   _dest_root(),
00034   _packed_data()
00035 {}
00036 
00037 file_transfer_infoton::file_transfer_infoton(const outcome &success,
00038     bool request, commands command,
00039     const istring &source, const istring &destination,
00040     const byte_array &packed_data)
00041 : infoton(file_transfer_classifier()),
00042   _success(success),
00043   _request(request),
00044   _command(byte(command)),
00045   _src_root(source),
00046   _dest_root(destination),
00047   _packed_data(packed_data)
00048 {}
00049 
00050 file_transfer_infoton::~file_transfer_infoton()
00051 {
00052 }
00053 
00054 const char *file_transfer_constant = "#ftran";
00055 
00056 SAFE_STATIC_CONST(string_array,
00057     file_transfer_infoton::file_transfer_classifier,
00058     (1, &file_transfer_constant))
00059 
00060 int file_transfer_infoton::packed_size() const
00061 {
00062   return sizeof(int)
00063       + sizeof(byte) * 2
00064       + _src_root.length() + 1
00065       + _dest_root.length() + 1
00066       + _packed_data.length() + sizeof(int);
00067 }
00068 
00069 void file_transfer_infoton::package_tree_info(const directory_tree &tree,
00070     const string_array &includes)
00071 {
00072   _packed_data.reset();
00073   tree.pack(_packed_data);
00074   includes.pack(_packed_data);
00075 }
00076 
00077 void file_transfer_infoton::pack(byte_array &packed_form) const
00078 {
00079   attach(packed_form, _success.value());
00080   attach(packed_form, byte(_request));
00081   attach(packed_form, _command);
00082   _src_root.pack(packed_form);
00083   _dest_root.pack(packed_form);
00084   attach(packed_form, _packed_data);
00085 }
00086 
00087 bool file_transfer_infoton::unpack(byte_array &packed_form)
00088 {
00089   int temp_o;
00090   if (!detach(packed_form, temp_o)) return false;
00091   _success = temp_o;
00092   byte temp;
00093   if (!detach(packed_form, temp)) return false;
00094   _request = temp;
00095   if (!detach(packed_form, _command)) return false;
00096   if (!_src_root.unpack(packed_form)) return false;
00097   if (!_dest_root.unpack(packed_form)) return false;
00098   if (!detach(packed_form, _packed_data)) return false;
00099   return true;
00100 }
00101 
00102 
00103 #endif //FILE_TRANSFER_INFOTON_IMPLEMENTATION_FILE
00104 

Generated on Tue Aug 19 04:29:50 2008 for HOOPLE Libraries by  doxygen 1.5.1