general/channel.h

Go to the documentation of this file.
00001 /* $Id: channel.h jjs $ */
00002 /*
00003    Copyright (C) 2007 by Jurjen Stellingwerff <jurjen@stwerff.xs4all.nl>
00004    Part of the Moros Project http://moros.sourceforge.net/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License.
00008    This program is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY.
00010 
00011    See the COPYING file for more details.
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


Generated on Tue Jan 1 17:30:00 2008 for general/channel.h Source File by  doxygen   Visit the project page on SourceForge.net Logo