Main Page   Class Hierarchy   File List  

Connection.h

00001 #ifndef CONNECTION_H
00002 #define CONNECTION_H
00003 #include <string>
00004 #include <iostream>
00005 #include <vector>
00006 #include "BufferedFile.h"
00007 /*
00008     * 5.1.1.1 Connection Interface
00009 
00010     * disconnect() Disconnect Connection from Connector
00011     * getName(): string Get Connections Name sent from Header.
00012     * readable(): booleanCan this connection be read from. Not to be confused with polling for data.
00013     * writable(): booleanCan this connection be written to? Not to be confused with polling for non blocking writes.
00014     * write(data:byte [],size: int)Writes data out to connection.
00015     * read(data:byte [],maxsize: int)Reads data from a connection. 
00016 
00017 */ 
00018 
00019 template<class SAMPLE>
00020 class Connection {
00021         public:
00022         virtual void   disconnect() {
00023                 file->Close();
00024         }
00025         virtual string getName() {
00026                 return connectionName;
00027         }
00028         virtual bool   readable() {
00029                 return true;
00030         }
00031         virtual bool   writable() {
00032                 return true;
00033         }
00034         virtual int write(const SAMPLE * data, int size) {
00035                 return file->Write((char *)data,sizeof(SAMPLE)*size);
00036         }
00037         virtual int read(SAMPLE * data, int size){
00038                 return file->Read((char *) data,sizeof(SAMPLE)*size);
00039         }
00040         virtual int getFileHandle() {
00041                 return file->getFileHandle();
00042         }
00043         virtual string getType(){
00044                 return type;
00045         }
00046         virtual void setType(string type) {
00047                 this->type = string(type);
00048         }
00049         Connection()  {
00050                 //NO INIT CALLED
00051         }
00052         Connection(BufferedFile * fd) {
00053                 init(fd,string("Unnamed"));
00054         }
00055         Connection(BufferedFile * fd,string name) {
00056                 init(fd,name);
00057         }
00058         virtual ~Connection() { 
00059                 //cout << "~Connection()\n";
00060                 delete file;
00061         }
00062         virtual bool readReady() {
00063                 return file->readReady();
00064         }
00065         virtual int getDataSize() {
00066                 return 1*sizeof(SAMPLE);
00067         }
00068         virtual bool writeReady() {
00069                 return file->writeReady();
00070         }
00071         protected:
00072         string type;
00073         string connectionName;
00074         BufferedFile * file;
00075         void init(BufferedFile * fd,string name){
00076                 connectionName = string(name);
00077                 this->file = fd;
00078                 type = "short";
00079         }
00080 };
00081 #endif

Generated on Sat Dec 7 21:28:09 2002 by doxygen1.2.18