2002-08-02 19:57:46 +00:00
|
|
|
/*
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
|
|
|
* Copyright (C) 2002 Chris Schoeneman
|
|
|
|
*
|
|
|
|
* This package is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* found in the file COPYING that should have accompanied this file.
|
|
|
|
*
|
|
|
|
* This package is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
2001-10-06 14:13:28 +00:00
|
|
|
#ifndef CPROTOCOLUTIL_H
|
|
|
|
#define CPROTOCOLUTIL_H
|
|
|
|
|
|
|
|
#include "BasicTypes.h"
|
|
|
|
#include "XIO.h"
|
2002-06-19 11:23:49 +00:00
|
|
|
#include <stdarg.h>
|
2001-10-06 14:13:28 +00:00
|
|
|
|
|
|
|
class IInputStream;
|
|
|
|
class IOutputStream;
|
|
|
|
|
2002-07-29 16:07:26 +00:00
|
|
|
//! Synergy protocol utilities
|
|
|
|
/*!
|
|
|
|
This class provides various functions for implementing the synergy
|
|
|
|
protocol.
|
|
|
|
*/
|
2001-10-06 14:13:28 +00:00
|
|
|
class CProtocolUtil {
|
2002-04-29 14:40:01 +00:00
|
|
|
public:
|
2002-07-29 16:07:26 +00:00
|
|
|
//! Write formatted data
|
|
|
|
/*!
|
|
|
|
Write formatted binary data to a stream. \c fmt consists of
|
|
|
|
regular characters and format specifiers. Format specifiers
|
|
|
|
begin with \%. All characters not part of a format specifier
|
|
|
|
are regular and are transmitted unchanged.
|
|
|
|
|
|
|
|
Format specifiers are:
|
|
|
|
- \%\% -- literal `\%'
|
|
|
|
- \%1i -- converts integer argument to 1 byte integer
|
|
|
|
- \%2i -- converts integer argument to 2 byte integer in NBO
|
|
|
|
- \%4i -- converts integer argument to 4 byte integer in NBO
|
2002-12-23 13:55:21 +00:00
|
|
|
- \%1I -- converts std::vector<UInt8>* to 1 byte integers
|
|
|
|
- \%2I -- converts std::vector<UInt16>* to 2 byte integers in NBO
|
|
|
|
- \%4I -- converts std::vector<UInt32>* to 4 byte integers in NBO
|
2002-07-29 16:07:26 +00:00
|
|
|
- \%s -- converts CString* to stream of bytes
|
|
|
|
- \%S -- converts integer N and const UInt8* to stream of N bytes
|
|
|
|
*/
|
2001-10-06 14:13:28 +00:00
|
|
|
static void writef(IOutputStream*,
|
2002-06-10 22:06:45 +00:00
|
|
|
const char* fmt, ...);
|
2001-10-06 14:13:28 +00:00
|
|
|
|
2002-07-29 16:07:26 +00:00
|
|
|
//! Read formatted data
|
|
|
|
/*!
|
|
|
|
Read formatted binary data from a buffer. This performs the
|
|
|
|
reverse operation of writef().
|
|
|
|
|
|
|
|
Format specifiers are:
|
|
|
|
- \%\% -- read (and discard) a literal `\%'
|
|
|
|
- \%1i -- reads a 1 byte integer; argument is a SInt32* or UInt32*
|
|
|
|
- \%2i -- reads an NBO 2 byte integer; arg is SInt32* or UInt32*
|
|
|
|
- \%4i -- reads an NBO 4 byte integer; arg is SInt32* or UInt32*
|
2002-12-23 13:55:21 +00:00
|
|
|
- \%1I -- reads 1 byte integers; arg is std::vector<UInt8>*
|
|
|
|
- \%2I -- reads NBO 2 byte integers; arg is std::vector<UInt16>*
|
|
|
|
- \%4I -- reads NBO 4 byte integers; arg is std::vector<UInt32>*
|
2002-07-29 16:07:26 +00:00
|
|
|
- \%s -- reads bytes; argument must be a CString*, \b not a char*
|
|
|
|
*/
|
2001-10-06 14:13:28 +00:00
|
|
|
static void readf(IInputStream*,
|
2002-06-10 22:06:45 +00:00
|
|
|
const char* fmt, ...);
|
2001-10-06 14:13:28 +00:00
|
|
|
|
2002-04-29 14:40:01 +00:00
|
|
|
private:
|
2001-10-14 16:58:01 +00:00
|
|
|
static UInt32 getLength(const char* fmt, va_list);
|
|
|
|
static void writef(void*, const char* fmt, va_list);
|
|
|
|
static UInt32 eatLength(const char** fmt);
|
|
|
|
static void read(IInputStream*, void*, UInt32);
|
2001-10-06 14:13:28 +00:00
|
|
|
};
|
|
|
|
|
2002-07-29 16:07:26 +00:00
|
|
|
//! Mismatched read exception
|
|
|
|
/*!
|
|
|
|
Thrown by CProtocolUtil::readf() when the data being read does not
|
|
|
|
match the format.
|
|
|
|
*/
|
2001-10-06 14:13:28 +00:00
|
|
|
class XIOReadMismatch : public XIO {
|
2002-04-29 14:40:01 +00:00
|
|
|
public:
|
2001-10-06 14:13:28 +00:00
|
|
|
// XBase overrides
|
|
|
|
virtual CString getWhat() const throw();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|