Constantin Kaplinsky | ce0907d | 2006-09-08 12:55:37 +0000 | [diff] [blame^] | 1 | /* 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. |
| 21 | // FIXME: Extend the comment. |
| 22 | // |
| 23 | |
| 24 | #include <rfb/CapsList.h> |
| 25 | #include <rdr/OutStream.h> |
| 26 | |
| 27 | using namespace rfb; |
| 28 | |
| 29 | const char *const CapsList::VENDOR_STD = "STDV"; |
| 30 | const char *const CapsList::VENDOR_TIGHT = "TGHT"; |
| 31 | |
| 32 | CapsList::CapsList(int maxCaps) |
| 33 | : CapsContainer(maxCaps) |
| 34 | { |
| 35 | } |
| 36 | |
| 37 | CapsList::~CapsList() |
| 38 | { |
| 39 | } |
| 40 | |
| 41 | void |
| 42 | CapsList::addStandard(rdr::U32 code, const char *name) |
| 43 | { |
| 44 | add3rdParty(code, name, VENDOR_STD); |
| 45 | } |
| 46 | |
| 47 | void |
| 48 | CapsList::addTightExt(rdr::U32 code, const char *name) |
| 49 | { |
| 50 | add3rdParty(code, name, VENDOR_TIGHT); |
| 51 | } |
| 52 | |
| 53 | void |
| 54 | CapsList::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 | |
| 68 | void |
| 69 | CapsList::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 | |