Constantin Kaplinsky | 73fdc8c | 2006-06-03 13:18:37 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2003-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 | |
Constantin Kaplinsky | ce0907d | 2006-09-08 12:55:37 +0000 | [diff] [blame] | 19 | // |
| 20 | // CapsContainer class implementation. |
Constantin Kaplinsky | 56b7fa1 | 2006-09-12 05:15:44 +0000 | [diff] [blame] | 21 | // Member variables and functions are documented in CapsContainer.h. |
Constantin Kaplinsky | ce0907d | 2006-09-08 12:55:37 +0000 | [diff] [blame] | 22 | // |
| 23 | |
Constantin Kaplinsky | 73fdc8c | 2006-06-03 13:18:37 +0000 | [diff] [blame] | 24 | #include <rfb/CapsContainer.h> |
Adam Tkac | 04b7fd2 | 2008-03-19 16:14:48 +0000 | [diff] [blame^] | 25 | #include <string.h> |
Constantin Kaplinsky | 73fdc8c | 2006-06-03 13:18:37 +0000 | [diff] [blame] | 26 | |
| 27 | using namespace rfb; |
| 28 | |
Constantin Kaplinsky | 73fdc8c | 2006-06-03 13:18:37 +0000 | [diff] [blame] | 29 | CapsContainer::CapsContainer(int maxCaps) |
Constantin Kaplinsky | 18076a9 | 2006-06-04 01:59:54 +0000 | [diff] [blame] | 30 | : m_maxSize(maxCaps), m_listSize(0), m_plist(new rdr::U32[m_maxSize]) |
Constantin Kaplinsky | 73fdc8c | 2006-06-03 13:18:37 +0000 | [diff] [blame] | 31 | { |
Constantin Kaplinsky | 73fdc8c | 2006-06-03 13:18:37 +0000 | [diff] [blame] | 32 | } |
| 33 | |
Constantin Kaplinsky | 73fdc8c | 2006-06-03 13:18:37 +0000 | [diff] [blame] | 34 | CapsContainer::~CapsContainer() |
| 35 | { |
| 36 | delete[] m_plist; |
| 37 | |
| 38 | // Remove char[] strings allocated by the new[] operator. |
| 39 | std::map<rdr::U32,char*>::const_iterator iter; |
| 40 | for (iter = m_descMap.begin(); iter != m_descMap.end(); iter++) { |
| 41 | delete[] iter->second; |
| 42 | } |
| 43 | } |
| 44 | |
Constantin Kaplinsky | 73fdc8c | 2006-06-03 13:18:37 +0000 | [diff] [blame] | 45 | void |
| 46 | CapsContainer::add(rdr::U32 code, const char *vendor, const char *name, |
Constantin Kaplinsky | ad9dc71 | 2006-06-03 14:17:43 +0000 | [diff] [blame] | 47 | const char *desc) |
Constantin Kaplinsky | 73fdc8c | 2006-06-03 13:18:37 +0000 | [diff] [blame] | 48 | { |
| 49 | // Fill in an rfbCapabilityInfo structure and pass it to the overloaded |
| 50 | // function. |
| 51 | CapabilityInfo capinfo; |
| 52 | capinfo.code = code; |
| 53 | memcpy(capinfo.vendorSignature, vendor, 4); |
| 54 | memcpy(capinfo.nameSignature, name, 8); |
| 55 | add(&capinfo, desc); |
| 56 | } |
| 57 | |
| 58 | void |
| 59 | CapsContainer::add(const CapabilityInfo *capinfo, const char *desc) |
| 60 | { |
| 61 | m_infoMap[capinfo->code] = *capinfo; |
| 62 | m_enableMap[capinfo->code] = false; |
| 63 | |
| 64 | if (isKnown(capinfo->code)) { |
| 65 | delete[] m_descMap[capinfo->code]; |
| 66 | } |
| 67 | char *desc_copy = 0; |
| 68 | if (desc != 0) { |
| 69 | desc_copy = new char[strlen(desc) + 1]; |
| 70 | strcpy(desc_copy, desc); |
| 71 | } |
| 72 | m_descMap[capinfo->code] = desc_copy; |
| 73 | } |
| 74 | |
Constantin Kaplinsky | 73fdc8c | 2006-06-03 13:18:37 +0000 | [diff] [blame] | 75 | bool |
| 76 | CapsContainer::isKnown(rdr::U32 code) const |
| 77 | { |
| 78 | return (m_descMap.find(code) != m_descMap.end()); |
| 79 | } |
| 80 | |
Constantin Kaplinsky | 73fdc8c | 2006-06-03 13:18:37 +0000 | [diff] [blame] | 81 | bool |
| 82 | CapsContainer::getInfo(rdr::U32 code, CapabilityInfo *capinfo) const |
| 83 | { |
| 84 | if (isKnown(code)) { |
| 85 | *capinfo = m_infoMap.find(code)->second; |
| 86 | return true; |
| 87 | } |
| 88 | |
| 89 | return false; |
| 90 | } |
| 91 | |
Constantin Kaplinsky | 73fdc8c | 2006-06-03 13:18:37 +0000 | [diff] [blame] | 92 | char * |
| 93 | CapsContainer::getDescription(rdr::U32 code) const |
| 94 | { |
| 95 | return (isKnown(code)) ? m_descMap.find(code)->second : 0; |
| 96 | } |
| 97 | |
Constantin Kaplinsky | 73fdc8c | 2006-06-03 13:18:37 +0000 | [diff] [blame] | 98 | bool |
| 99 | CapsContainer::enable(const CapabilityInfo *capinfo) |
| 100 | { |
| 101 | if (!isKnown(capinfo->code)) |
| 102 | return false; |
| 103 | |
| 104 | const CapabilityInfo *known = &(m_infoMap[capinfo->code]); |
| 105 | if ( memcmp(known->vendorSignature, capinfo->vendorSignature, 4) != 0 || |
| 106 | memcmp(known->nameSignature, capinfo->nameSignature, 8) != 0 ) { |
| 107 | m_enableMap[capinfo->code] = false; |
| 108 | return false; |
| 109 | } |
| 110 | |
| 111 | m_enableMap[capinfo->code] = true; |
| 112 | if (m_listSize < m_maxSize) { |
| 113 | m_plist[m_listSize++] = capinfo->code; |
| 114 | } |
| 115 | return true; |
| 116 | } |
| 117 | |
Constantin Kaplinsky | 73fdc8c | 2006-06-03 13:18:37 +0000 | [diff] [blame] | 118 | bool |
| 119 | CapsContainer::isEnabled(rdr::U32 code) const |
| 120 | { |
| 121 | return (isKnown(code)) ? m_enableMap.find(code)->second : false; |
| 122 | } |
| 123 | |
Constantin Kaplinsky | 73fdc8c | 2006-06-03 13:18:37 +0000 | [diff] [blame] | 124 | rdr::U32 |
| 125 | CapsContainer::getByOrder(int idx) const |
| 126 | { |
| 127 | return (idx < m_listSize) ? m_plist[idx] : 0; |
| 128 | } |
| 129 | |