blob: 11977b2e9c1c763ff486c67e9a684ed3f886f1dd [file] [log] [blame]
Constantin Kaplinskyce0907d2006-09-08 12:55:37 +00001/* Copyright (C) 2006 Constantin Kaplinsky. All Rights Reserved.
2 *
3 * This is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This software is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 * USA.
17 */
18
19//
20// CapsList class implementation.
Constantin Kaplinsky99637aa2006-09-12 05:46:34 +000021// Member functions are documented in CapsList.h.
Constantin Kaplinskyce0907d2006-09-08 12:55:37 +000022//
23
24#include <rfb/CapsList.h>
25#include <rdr/OutStream.h>
26
27using namespace rfb;
28
29const char *const CapsList::VENDOR_STD = "STDV";
30const char *const CapsList::VENDOR_TIGHT = "TGHT";
31
32CapsList::CapsList(int maxCaps)
33 : CapsContainer(maxCaps)
34{
35}
36
37CapsList::~CapsList()
38{
39}
40
41void
42CapsList::addStandard(rdr::U32 code, const char *name)
43{
44 add3rdParty(code, name, VENDOR_STD);
45}
46
47void
48CapsList::addTightExt(rdr::U32 code, const char *name)
49{
50 add3rdParty(code, name, VENDOR_TIGHT);
51}
52
53void
54CapsList::add3rdParty(rdr::U32 code, const char *name, const char *vendor)
55{
56 add(code, vendor, name);
57
58 // NOTE: This code is a bit tricky and not the most efficient. However,
59 // that's not a problem as we prefer simplicity to performance here.
60 // Here we need to "enable capability" but that requires comparing
61 // name and vendor strings. So we just make CapsContainer compare
62 // the same strings with themselves.
63 CapabilityInfo tmp;
64 if (getInfo(code, &tmp))
65 enable(&tmp);
66}
67
68void
69CapsList::write(rdr::OutStream* os) const
70{
71 int count = getSize();
72 CapabilityInfo cap;
73
74 for (int i = 0; i < count; i++) {
75 getInfo(getByOrder(i), &cap);
76 os->writeU32(cap.code);
77 os->writeBytes(&cap.vendorSignature, 4);
78 os->writeBytes(&cap.nameSignature, 8);
79 }
80}
81