All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines
Public Member Functions | Static Public Member Functions
GpCoreTools::ScreenClient Class Reference

Brief description of class still missing. More...

#include <ScreenClient.h>

Inheritance diagram for GpCoreTools::ScreenClient:
GpCoreTools::TcpClientStream GpCoreTools::Stream

List of all members.

Public Member Functions

void connect ()
virtual void hungUp ()
 ScreenClient (const Address &host, uint16_t port)

Static Public Member Functions

static ScreenClientinstance ()
static void write (unsigned char x, unsigned char y, const char *cformat,...)

Detailed Description

Brief description of class still missing.

Full description of class still missing


Constructor & Destructor Documentation

GpCoreTools::ScreenClient::ScreenClient ( const Address host,
uint16_t  port 
)

Description of constructor still missing

References connect(), and TRACE.

    : TcpClientStream(host)
  {
    TRACE;
    assert(!_self);
    _self=this;
    assert(pthread_mutex_init(&_mutex, 0)==0);
    _port=port;
    _connected=false;
    connect();
  }

Member Function Documentation

References GpCoreTools::TcpClientStream::connect(), GpCoreTools::EventLoop::instance(), GpCoreTools::Timer::start(), and TRACE.

Referenced by GpCoreTools::ScreenClientConnect::exec(), and ScreenClient().

  {
    TRACE;
    pthread_mutex_lock(&_mutex);
    if(!TcpClientStream::connect(_port)) {
      if(EventLoop::instance()) {
        ScreenClientConnect * t=new ScreenClientConnect(this);
        t->start(); // Retry in ten seconds
      }
    } else {
      _connected=true;
    }
    pthread_mutex_unlock(&_mutex);
  }

Reimplemented from GpCoreTools::TcpClientStream.

References GpCoreTools::Stream::fileDescriptor(), GpCoreTools::Stream::setFileDescriptor(), GpCoreTools::Timer::start(), TRACE, and write().

  {
    TRACE;
    pthread_mutex_lock(&_mutex);
    // Sets new socket
    setFileDescriptor(socket(AF_INET, SOCK_STREAM, 0));
    if(fileDescriptor()<=0) {
      Log::write(0, "%s\n", strerror(errno));
    }
    _connected=false;
    pthread_mutex_unlock(&_mutex);
    ScreenClientConnect * t=new ScreenClientConnect(this);
    t->start(); // Retry in ten seconds
  }
static ScreenClient* GpCoreTools::ScreenClient::instance ( ) [inline, static]
{return _self;}
void GpCoreTools::ScreenClient::write ( unsigned char  x,
unsigned char  y,
const char *  cformat,
  ... 
) [static]

References GpCoreTools::FletcherChecksum::add(), GpCoreTools::MessageRawHeader::HeaderSize, GpCoreTools::MessageRawHeader::littleEndianValues(), TRACE, and GpCoreTools::TcpClientStream::writePartial().

Referenced by hungUp(), and main().

  {
    TRACE;
    pthread_mutex_lock(&_self->_mutex);
    if(_self->_connected) {
      char buf[32]; // No more than 20 characters at a time
      buf[0]=17;
      buf[1]=x;
      buf[2]=y;
      va_list argptr;
      va_start(argptr, cformat);
      char * msgBuf=buf+3;
      vsnprintf(msgBuf, 28, cformat, argptr);
      va_end(argptr);
      int n=strlen(msgBuf);
      if(n>20) {
        Log::write(0, "More than 20 characters\n");
        Log::write(0, "'%s'\n", msgBuf);
        n=20;
      }
      n+=3;
      MessageRawHeader * hdr=new MessageRawHeader(n);
      hdr->littleEndianValues();
      if(_self->writePartial((const char *)hdr, sizeof(MessageRawHeader)) &&
         _self->writePartial(buf, n)) {
        FletcherChecksum chk;
        chk.add(hdr->header(), MessageRawHeader::HeaderSize);
        chk.add(buf, n);
        _self->TcpClientStream::write((const char *)&chk, sizeof(chk));
      }
      delete hdr;
    }
    pthread_mutex_unlock(&_self->_mutex);
  }

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines