3 // (C) Copyright Seb Wills 2005
5 // Abstract base class for socket input: parent of non-abstract classes in each implementation (Windows, Linux, ...),
7 #ifndef __socketinputbase_h__
8 #define __socketinputbase_h__
10 #include "DasherInput.h"
11 #include "SettingsStore.h"
16 #define DASHER_SOCKET_INPUT_MAX_COORDINATE_COUNT 2 // just X and Y for now
17 #define DASHER_SOCKET_INPUT_MAX_COORDINATE_LABEL_LENGTH 128
20 class CSocketInputBase
;
25 class CSocketInputBase
: public CScreenCoordInput
, public CSettingsUserObserver
{
29 CSocketInputBase(CSettingsUser
*pCreator
, CMessageDisplay
*pMsgs
);
31 virtual ~CSocketInputBase();
33 virtual void HandleEvent(int iParameter
);
35 virtual void SetDebug(bool _debug
);
37 virtual bool StartListening();
39 virtual void StopListening();
41 virtual bool isListening() {
45 virtual void SetReaderPort(int port
);
47 virtual int GetPort() {
51 void SetCoordinateCount(int _coordinateCount
) {
52 DASHER_ASSERT(_coordinateCount
<= DASHER_SOCKET_INPUT_MAX_COORDINATE_COUNT
);
53 coordinateCount
= _coordinateCount
;
56 /// Gets the last coordinates received; if only one coordinate is being read, this is put
57 /// into iDasherY (and iDasherX set to 0).
58 bool GetScreenCoords(screenint
&iScreenX
, screenint
&iScreenY
, CDasherView
*pView
) {
60 //update max values for reader thread...(note any changes here won't be incorporated
61 // until values are next received over socket, but never mind)
62 dasherMaxCoordinateValues
[0] = pView
->Screen()->GetWidth();
63 dasherMaxCoordinateValues
[1] = pView
->Screen()->GetHeight();
65 if (coordinateCount
==1) {
67 iScreenY
= dasherCoordinates
[0];
68 } else if (coordinateCount
==2) {
69 iScreenX
= dasherCoordinates
[0];
70 iScreenY
= dasherCoordinates
[1];
72 //Aiieee, we're receiving >2 coords? Don't know what to do...
86 // Defines the label used in the input stream for a particular coordinate.
87 // We make our own copy of the label, in our own buffer. This should ensure thread-safety.
88 // Even if this method is called while our other thread is doing a strcmp on the label,
89 // the buffer will always be null-terminated somewhere (even if the last byte of the buffer, which is
90 // never overwritten), so won't segfault.
91 virtual void SetCoordinateLabel(int iWhichCoordinate
, const char *Label
);
93 virtual void SetRawRange(int iWhich
, double dMin
, double dMax
);
95 bool GetSettings(SModuleSettings
**pSettings
, int *iCount
);
99 myint dasherCoordinates
[DASHER_SOCKET_INPUT_MAX_COORDINATE_COUNT
];
100 myint dasherMaxCoordinateValues
[DASHER_SOCKET_INPUT_MAX_COORDINATE_COUNT
];
101 double rawMinValues
[DASHER_SOCKET_INPUT_MAX_COORDINATE_COUNT
];
102 double rawMaxValues
[DASHER_SOCKET_INPUT_MAX_COORDINATE_COUNT
];
104 char coordinateNames
[DASHER_SOCKET_INPUT_MAX_COORDINATE_COUNT
][DASHER_SOCKET_INPUT_MAX_COORDINATE_LABEL_LENGTH
+ 1];
107 bool debug_socket_input
;
115 virtual bool LaunchReaderThread() =0;
117 virtual void CancelReaderThread() =0;
119 virtual void ReadForever();
121 virtual void ParseMessage(char *message
);
123 //Reports an error by appending an error message obtained from strerror(errno) onto the provided prefix
124 void ReportErrnoError(const std::string
&prefix
);
126 virtual void SocketDebugMsg(const char *pszFormat
, ...);
128 CMessageDisplay
*const m_pMsgs
;