Mercurial > hg > Applications > tvnjviewer
comparison src/main/java/com/glavsoft/rfb/CapabilityContainer.java @ 0:daa24f8a557b
TightVNC original
author | YU |
---|---|
date | Thu, 11 Sep 2014 07:30:03 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:daa24f8a557b |
---|---|
1 // Copyright (C) 2010, 2011, 2012, 2013 GlavSoft LLC. | |
2 // All rights reserved. | |
3 // | |
4 //------------------------------------------------------------------------- | |
5 // This file is part of the TightVNC software. Please visit our Web site: | |
6 // | |
7 // http://www.tightvnc.com/ | |
8 // | |
9 // This program is free software; you can redistribute it and/or modify | |
10 // it under the terms of the GNU General Public License as published by | |
11 // the Free Software Foundation; either version 2 of the License, or | |
12 // (at your option) any later version. | |
13 // | |
14 // This program is distributed in the hope that it will be useful, | |
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 // GNU General Public License for more details. | |
18 // | |
19 // You should have received a copy of the GNU General Public License along | |
20 // with this program; if not, write to the Free Software Foundation, Inc., | |
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
22 //------------------------------------------------------------------------- | |
23 // | |
24 | |
25 package com.glavsoft.rfb; | |
26 | |
27 import java.util.Collection; | |
28 import java.util.HashMap; | |
29 import java.util.LinkedList; | |
30 import java.util.Map; | |
31 import java.util.logging.Logger; | |
32 | |
33 import com.glavsoft.exceptions.TransportException; | |
34 import com.glavsoft.rfb.encoding.EncodingType; | |
35 import com.glavsoft.transport.Reader; | |
36 | |
37 /** | |
38 * Container for Tight extention protocol capabilities | |
39 * | |
40 * Needed to set what capabilities we support, which of them supported | |
41 * by server and for enabling/disabling ops on them. | |
42 */ | |
43 public class CapabilityContainer { | |
44 public CapabilityContainer() { } | |
45 | |
46 private final Map<Integer, RfbCapabilityInfo> caps = new HashMap<Integer, RfbCapabilityInfo>(); | |
47 | |
48 public void add(RfbCapabilityInfo capabilityInfo) { | |
49 caps.put(capabilityInfo.getCode(), capabilityInfo); | |
50 } | |
51 | |
52 public void add(int code, String vendor, String name) { | |
53 caps.put(code, new RfbCapabilityInfo(code, vendor, name)); | |
54 } | |
55 | |
56 public void addEnabled(int code, String vendor, String name) { | |
57 RfbCapabilityInfo capability = new RfbCapabilityInfo(code, vendor, name); | |
58 capability.setEnable(true); | |
59 caps.put(code, capability); | |
60 } | |
61 | |
62 public void setEnable(int id, boolean enable) { | |
63 RfbCapabilityInfo c = caps.get(id); | |
64 if (c != null) { | |
65 c.setEnable(enable); | |
66 } | |
67 } | |
68 | |
69 public void setAllEnable(boolean enable) { | |
70 for (RfbCapabilityInfo c : caps.values()) { | |
71 c.setEnable(enable); | |
72 } | |
73 } | |
74 | |
75 public Collection<EncodingType> getEnabledEncodingTypes() { | |
76 Collection<EncodingType> types = new LinkedList<EncodingType>(); | |
77 for (RfbCapabilityInfo c : caps.values()) { | |
78 if (c.isEnabled()) { | |
79 types.add(EncodingType.byId(c.getCode())); | |
80 } | |
81 } | |
82 return types; | |
83 } | |
84 | |
85 public void read(Reader reader, int count) throws TransportException { | |
86 while (count-- > 0) { | |
87 RfbCapabilityInfo capInfoReceived = new RfbCapabilityInfo(reader); | |
88 Logger.getLogger("com.glavsoft.rfb").fine(capInfoReceived.toString()); | |
89 RfbCapabilityInfo myCapInfo = caps.get(capInfoReceived.getCode()); | |
90 if (myCapInfo != null) { | |
91 myCapInfo.setEnable(true); | |
92 } | |
93 } | |
94 } | |
95 | |
96 public boolean isSupported(int code) { | |
97 RfbCapabilityInfo myCapInfo = caps.get(code); | |
98 if (myCapInfo != null) | |
99 return myCapInfo.isEnabled(); | |
100 return false; | |
101 } | |
102 | |
103 public boolean isSupported(RfbCapabilityInfo rfbCapabilityInfo) { | |
104 return isSupported(rfbCapabilityInfo.getCode()); | |
105 } | |
106 | |
107 } |