00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef __CHANNEL_H
00014 #define __CHANNEL_H
00015
00016 #include "buffer.h"
00017 #include <list>
00018 #include <vector>
00019 #include <sigc++/signal.h>
00020
00021 typedef long size;
00022
00023
00024 using namespace std;
00025
00027
00028 class connection {
00029 public:
00031 virtual int read(char *buffer, size length)=0;
00032
00034 virtual int write(const char *buffer, size length)=0;
00035
00037 virtual void close()=0;
00038
00040 virtual size length()=0;
00041 virtual ~connection() {}
00042 };
00043
00044 #define TYPE_SOCKET 1
00045 #define TYPE_FILE 2
00046 #define TYPE_SERVER 3
00047 #define TYPE_IMPORT 4
00048
00050
00051 class channel {
00052 private:
00054 buffer *input_;
00056 size to_input_;
00058 buffer *output_;
00060 long last_;
00067 enum READY_STATE { STATE_CLOSED, STATE_WAITING, STATE_READING, STATE_WRITING};
00069 int state;
00071 bool check_session();
00073 list<std::string> write_files;
00075 int readf;
00077 int writef;
00079 void file_poll(long time);
00081 int errors;
00082
00083
00084 public:
00086 channel(int channeltype, long time);
00087
00089 void *payload;
00090
00092 void close(void);
00094 std::string key;
00096 std::string value;
00098 std::string ip;
00100 int port;
00102 unsigned int id;
00103
00105 bool next();
00107 bool peek(string key);
00109 void write(const std::string key, const std::string value);
00111 void write(const std::string key, const long value);
00113 void send();
00115 void fread(const std::string file);
00117 void fwrite(const std::string file);
00119 void finish();
00120
00122 void poll(long time);
00125 connection *stream;
00128 bool finished;
00130 sigc::signal<void, channel*> handler;
00131
00133 int type;
00134
00136 void send_session(long time);
00138 class communicate *comm;
00140 bool lock;
00141
00142 };
00143
00144 #endif // __CHANNEL_H