Subversion Repositories DevTools

Rev

Blame | Last modification | View Log | RSS feed

//---------------------------------------------------------------------------

#ifndef DeviceSimulatorThreadH
#define DeviceSimulatorThreadH
//---------------------------------------------------------------------------
#include <Classes.hpp>

#define DEVSIM_OBSERVER 1 
#include "IDevice.h"

#include <vector>

class IDeviceFactory;

//---------------------------------------------------------------------------
class DeviceSimulatorThread : public TThread, public IDeviceListener
{
  typedef struct tagTHREADNAME_INFO
  {
    DWORD dwType;     // must be 0x1000
    LPCSTR szName;    // pointer to name (in user addr space)
    DWORD dwThreadID; // thread ID (-1=caller thread)
    DWORD dwFlags;    // reserved for future use, must be zero
  } THREADNAME_INFO;
private:
    void SetName();
    void Reconnect();
    bool TransferUdFiles();

protected:
    void __fastcall Execute();
public:
    __fastcall DeviceSimulatorThread( IDevice * device,
                                      IDeviceFactory * factory,
                                      const AnsiString & hostname );

    void __fastcall UploadUDFile( const AnsiString & filename );

    const bool __fastcall IsRunning() { return m_running; }
    
    const bool __fastcall IsConnected() { return (IsRunning() && m_device->isConnected()); }

    void __fastcall Stop();

    const AnsiString __fastcall GetErrorMessage() { return m_error; }

    // IDeviceListener interface

    virtual void DS_STDCALL onEvent( const unsigned short type,
                                     const char * msg,
                                     const unsigned char status );

    virtual void DS_STDCALL detach();

private:
    IDevice *           m_device;
    IDeviceFactory *    m_factory;
    AnsiString          m_address;

    bool                m_running;
    AnsiString          m_error;

    HANDLE              m_semaphore;
    std::vector< AnsiString > m_udFiles;

};
//---------------------------------------------------------------------------
#endif