first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / octopi / library / tentacles / file_transfer_infoton.h
1 #ifndef FILE_TRANSFER_INFOTON_CLASS
2 #define FILE_TRANSFER_INFOTON_CLASS
3
4 /*****************************************************************************\
5 *                                                                             *
6 *  Name   : file_transfer_infoton                                             *
7 *  Author : Chris Koeritz                                                     *
8 *                                                                             *
9 *******************************************************************************
10 * Copyright (c) 2005-$now By Author.  This program is free software; you can  *
11 * redistribute it and/or modify it under the terms of the GNU General Public  *
12 * License as published by the Free Software Foundation; either version 2 of   *
13 * the License or (at your option) any later version.  This is online at:      *
14 *     http://www.fsf.org/copyleft/gpl.html                                    *
15 * Please send any updates to: fred@gruntose.com                               *
16 \*****************************************************************************/
17
18 #include <basis/byte_array.h>
19 #include <filesystem/directory_tree.h>
20 #include <octopus/infoton.h>
21
22 namespace octopi {
23
24 //! Base objects used by the file transfer tentacle to schedule transfers.
25 /*!
26   Note: this is a fairly heavy-weight header.
27 */
28
29 class file_transfer_infoton : public infoton
30 {
31 public:
32   //! the commands specify what this package is intended to do.
33   enum commands {
34     TREE_COMPARISON = 1,
35       //!< the destination root will be compared with the source root.
36       /*!< the packed data in the request holds a packed symbol tree
37       describing the destination hierarchy.  the packed data in the response
38       is the packed filename list that represents the differences between the
39       two hierarchies.  this is considered to start a file transfer based on
40       those differences. */
41     PLACE_FILE_CHUNKS
42       //!< the destination side requests a new set of chunks.
43       /*!< this is based on the source's memory of where the transfer is at.
44       this will only perform properly when the file transfer was requested to
45       be started by the client using a TREE_COMPARISON request.  the request
46       has an empty data chunk, but the response consists of an arbitrary
47       number of pairs of @code
48       [ file_transfer_header + file chunk described in header ]
49       @endcode */
50   };
51
52   basis::outcome _success;  //!< reports what kind of result occurred.
53   bool _request;  //!< if it's not a request, then it's a response.
54   basis::abyte _command;  //!< one of the commands above.
55   basis::astring _src_root;  //!< the top-level directory of the source.
56   basis::astring _dest_root;  //!< the top-level directory of the destination.
57   basis::byte_array _packed_data;  //!< the packed headers and file chunks.
58
59   file_transfer_infoton();
60
61   file_transfer_infoton(const basis::outcome &success, bool request, commands command,
62           const basis::astring &source, const basis::astring &destination,
63           const basis::byte_array &packed_data);
64
65   virtual ~file_transfer_infoton();
66
67   virtual void pack(basis::byte_array &packed_form) const;
68   virtual bool unpack(basis::byte_array &packed_form);
69
70   void package_tree_info(const filesystem::directory_tree &tree,
71           const structures::string_array &includes);
72     //!< prepares the packed data from the "tree" and "includes" list.
73
74   virtual basis::clonable *clone() const { return cloner<file_transfer_infoton>(*this); }
75
76   virtual void text_form(basis::base_string &fill) const;
77
78   virtual int packed_size() const;
79
80   static const structures::string_array &file_transfer_classifier();
81     //!< returns the classifier for this type of infoton.
82 };
83
84 } //namespace.
85
86 #endif
87