~nobuto/ubuntu/natty/synergy/merge-from-experimental

« back to all changes in this revision

Viewing changes to lib/synergy/CProtocolUtil.h

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Lutz
  • Date: 2003-10-31 19:36:30 UTC
  • Revision ID: james.westby@ubuntu.com-20031031193630-knbv79x5az7qh49y
Tags: upstream-1.0.14
ImportĀ upstreamĀ versionĀ 1.0.14

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * synergy -- mouse and keyboard sharing utility
 
3
 * Copyright (C) 2002 Chris Schoeneman
 
4
 * 
 
5
 * This package is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU General Public License
 
7
 * found in the file COPYING that should have accompanied this file.
 
8
 * 
 
9
 * This package is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 */
 
14
 
 
15
#ifndef CPROTOCOLUTIL_H
 
16
#define CPROTOCOLUTIL_H
 
17
 
 
18
#include "BasicTypes.h"
 
19
#include "XIO.h"
 
20
#include <stdarg.h>
 
21
 
 
22
class IInputStream;
 
23
class IOutputStream;
 
24
 
 
25
//! Synergy protocol utilities
 
26
/*!
 
27
This class provides various functions for implementing the synergy
 
28
protocol.
 
29
*/
 
30
class CProtocolUtil {
 
31
public:
 
32
        //! Write formatted data
 
33
        /*!
 
34
        Write formatted binary data to a stream.  \c fmt consists of
 
35
        regular characters and format specifiers.  Format specifiers
 
36
        begin with \%.  All characters not part of a format specifier
 
37
        are regular and are transmitted unchanged.
 
38
        
 
39
        Format specifiers are:
 
40
        - \%\%   -- literal `\%'
 
41
        - \%1i  -- converts integer argument to 1 byte integer
 
42
        - \%2i  -- converts integer argument to 2 byte integer in NBO
 
43
        - \%4i  -- converts integer argument to 4 byte integer in NBO
 
44
        - \%1I  -- converts std::vector<UInt8>* to 1 byte integers
 
45
        - \%2I  -- converts std::vector<UInt16>* to 2 byte integers in NBO
 
46
        - \%4I  -- converts std::vector<UInt32>* to 4 byte integers in NBO
 
47
        - \%s   -- converts CString* to stream of bytes
 
48
        - \%S   -- converts integer N and const UInt8* to stream of N bytes
 
49
        */
 
50
        static void                     writef(IOutputStream*,
 
51
                                                        const char* fmt, ...);
 
52
 
 
53
        //! Read formatted data
 
54
        /*!
 
55
        Read formatted binary data from a buffer.  This performs the
 
56
        reverse operation of writef().
 
57
        
 
58
        Format specifiers are:
 
59
        - \%\%   -- read (and discard) a literal `\%'
 
60
        - \%1i  -- reads a 1 byte integer; argument is a SInt32* or UInt32*
 
61
        - \%2i  -- reads an NBO 2 byte integer;  arg is SInt32* or UInt32*
 
62
        - \%4i  -- reads an NBO 4 byte integer;  arg is SInt32* or UInt32*
 
63
        - \%1I  -- reads 1 byte integers;  arg is std::vector<UInt8>*
 
64
        - \%2I  -- reads NBO 2 byte integers;  arg is std::vector<UInt16>*
 
65
        - \%4I  -- reads NBO 4 byte integers;  arg is std::vector<UInt32>*
 
66
        - \%s   -- reads bytes;  argument must be a CString*, \b not a char*
 
67
        */
 
68
        static void                     readf(IInputStream*,
 
69
                                                        const char* fmt, ...);
 
70
 
 
71
private:
 
72
        static UInt32           getLength(const char* fmt, va_list);
 
73
        static void                     writef(void*, const char* fmt, va_list);
 
74
        static UInt32           eatLength(const char** fmt);
 
75
        static void                     read(IInputStream*, void*, UInt32);
 
76
};
 
77
 
 
78
//! Mismatched read exception
 
79
/*!
 
80
Thrown by CProtocolUtil::readf() when the data being read does not
 
81
match the format.
 
82
*/
 
83
class XIOReadMismatch : public XIO {
 
84
public:
 
85
        // XBase overrides
 
86
        virtual CString         getWhat() const throw();
 
87
};
 
88
 
 
89
#endif
 
90