DataSink Class Reference

<class description="" goes="" here=""> <short description=""> More...

#include <DataSink.hpp>

List of all members.


Public Member Functions

 DataSink (u32 id, IO *out, const char *address, int port=0, Adaptor *adaptor=NULL)
 ideally address should be a stringPresentation of the form "127.0.0.1".
const char * getAddress () const
IOgetOutput () const
int getPort () const
bool send (Frame *frm)
 inserts the frame into the sendqueue of the client.
bool close (bool immediate=false)
 closes the output, sends buffered frames if
AdaptorgetAdaptor ()
u32 getDataSinkId () const
void pauseOutput ()
void muteOutput ()
void playOutput (double prefetch)

Protected Attributes

char * adr
u32 clientId
 use the binary ip address
IOoutput
int port
list< Frame * > sendQueue
AdaptorlocalAdaptor
 a client can have a local Adaptor/-Chain that adapts the result from the global common Adaptor (in DataChannel) to its specific needs
FramelastFrm

Detailed Description

<class description="" goes="" here=""> <short description="">

Author:
Michael Kropfberger and Peter Schojer
Version:
Id
DataSink.hpp,v 1.4 2006/01/20 15:37:17 mkropfbe Exp

Definition at line 63 of file DataSink.hpp.


Constructor & Destructor Documentation

DataSink::DataSink u32  id,
IO out,
const char *  address,
int  port = 0,
Adaptor adaptor = NULL
 

ideally address should be a stringPresentation of the form "127.0.0.1".

If the address is a name ("hurra.itec.uni-klu.ac.at"), a dns lookup has to be performed. FIXME: implement this lookup

Parameters:
id: use a binary representation of the ip address
address is deep-copied
out is shallow-copied and freed in the destructor
adaptor is shallow-copied and freed in the destructor
Definition at line 47 of file DataSink.cpp.

References clientId, and localAdaptor.

00048 { 00049 // try to set the address 00050 // if this fails we have a name not an ip-address 00051 // perform a dns lookup, but don't use qt -> signals 00052 if (addr) { 00053 adr = new char[strlen(addr) + 1]; 00054 strcpy(adr, addr); 00055 } else { 00056 adr = NULL; 00057 } 00058 if (adaptor == NULL) 00059 localAdaptor = new Forwarder(); 00060 else 00061 localAdaptor = adaptor; 00062 port = prt; 00063 output = out; 00064 lastFrm = NULL; 00065 clientId=id; 00066 }


Member Function Documentation

bool DataSink::close bool  immediate = false  ) 
 

closes the output, sends buffered frames if

Parameters:
immediate is false
Definition at line 174 of file DataSink.cpp.

References IO::close(), Adaptor::close(), localAdaptor, and IO::writeFrame().

00174 { 00175 list < Frame * >lFrm2 = localAdaptor->close(); 00176 list < Frame * >::iterator lFrm2I; 00177 int i; 00178 00179 dprintf_full("DataSink::close\n"); 00180 while (!lFrm2.empty()) { 00181 lFrm2I = lFrm2.begin(); 00182 if (output && !immediate) { 00183 i = output->writeFrame((*lFrm2I)); 00184 } 00185 if (*lFrm2I != lastFrm) 00186 delete *lFrm2I; 00187 lFrm2.pop_front(); 00188 } 00189 if (output) 00190 return output->close(immediate); 00191 return false; 00192 }

bool DataSink::send Frame frm  ) 
 

inserts the frame into the sendqueue of the client.

blocking the local adaptor is called and then the result is sent Do not forget to delete the input-frm :-)Definition at line 92 of file DataSink.cpp.

References Adaptor::adapt(), Adaptor::getName(), IO::getState(), localAdaptor, IO::open(), and IO::writeFrame().

Referenced by DataChannel::run().

00092 { 00093 #ifdef VITOOKI_DEBUG 00094 double start_dtime, now_dtime; 00095 struct timeval now_tv; 00096 #endif 00097 00098 lastFrm = frm; 00099 bool retVal = true; 00100 if (output) { 00101 assert(frm != NULL); 00102 assert(frm->getAU() != NULL); 00103 dprintf_full("DataSink::send: Output is set at client. Got frame with CTS %i prio %i size %i\n", 00104 frm->getAU()->cts, frm->getAU()->prio, frm->getAU()->size); 00105 if (output->getState() != IO::OPEN && 00106 output->getState() != IO::MUTED && 00107 output->getState() != IO::PAUSED) 00108 output->open(); 00109 //first, output should always be set to IO::OPEN 00110 if (output->getState() != IO::OPEN && 00111 output->getState() != IO::MUTED && 00112 output->getState() != IO::PAUSED) { 00113 dprintf_err("DataSink::send: State = %i failed to open OUTPUT\n", output->getState()); 00114 return false; 00115 } 00116 00117 00118 if (output->getState() != IO::MUTED) { 00119 // everything ok, 00120 // now adapt the data 00121 00122 #ifdef VITOOKI_DEBUG 00123 gettimeofday(&now_tv,NULL); 00124 start_dtime = now_tv.tv_sec + now_tv.tv_usec/1000000.0; 00125 #endif 00126 00127 list < Frame * >fr; 00128 fr = localAdaptor->adapt(frm); 00129 00130 #ifdef VITOOKI_DEBUG 00131 gettimeofday(&now_tv,NULL); 00132 now_dtime = now_tv.tv_sec + now_tv.tv_usec/1000000.0; 00133 00134 if (localAdaptor != NULL) 00135 dprintf_full("DataSink::send(): local adaptation (%s) worked for %2.0f msecs\n",localAdaptor->getName(), 00136 (now_dtime-start_dtime)*1000.0); 00137 #endif 00138 00139 list < Frame * >::iterator fI; 00140 while (!fr.empty()) { 00141 // now write the data 00142 fI = fr.begin(); 00143 int i = output->writeFrame((*fI)); 00144 if (*fI != frm) 00145 delete *fI; 00146 fr.pop_front(); 00147 if (i <= 0) { 00148 dprintf_small("DataSink: Failed to write frame? %i\n", i); 00149 retVal = false; 00150 } 00151 } 00152 }//not MUTED 00153 else { 00154 //completely ignore frame, since no output could handle still encoded frame! 00155 /* 00156 // give the un-adapted frame to output, so CTS might still be 00157 //used for synchronization, but the frame cannot be viewed!!! 00158 int i = output->writeFrame(frm); 00159 //still encoded frm will deleted within DataChannel 00160 if (i <= 0) { 00161 dprintf_small("DataSink: Failed to write muted frame? %i\n", i); 00162 retVal = false; 00163 } 00164 */ 00165 } 00166 00167 return retVal; 00168 } 00169 return false; // no output is set 00170 }


The documentation for this class was generated from the following files: