Skip to content

Commit 52ebf15

Browse files
author
Kelven Yang
committed
Console proxy refactoring incremental check-in - new VNC protocol implementation
1 parent 8fb378a commit 52ebf15

32 files changed

Lines changed: 3029 additions & 857 deletions

‎console-proxy/.classpath‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
2-
<classpath>
3-
<classpathentry kind="src" path="src"/>
4-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
5-
<classpathentry combineaccessrules="false" kind="src" path="/deps"/>
6-
<classpathentry combineaccessrules="false" kind="src" path="/console"/>
7-
<classpathentry kind="output" path="bin"/>
8-
</classpath>
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
5+
<classpathentry combineaccessrules="false" kind="src" path="/deps"/>
6+
<classpathentry combineaccessrules="false" kind="src" path="/console"/>
7+
<classpathentry kind="output" path="bin"/>
8+
</classpath>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
3+
*
4+
* This software is licensed under the GNU General Public License v3 or later.
5+
*
6+
* It is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or any later version.
9+
* This program 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+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*
17+
*/
18+
19+
package com.cloud.consoleproxy.util;
20+
21+
import java.awt.Rectangle;
22+
import java.util.List;
23+
24+
public interface ITileScanListener {
25+
boolean onTileChange(Rectangle rowMergedRect, int row, int col);
26+
void onRegionChange(List<Region> regionList);
27+
}
Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
/**
2+
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
3+
*
4+
* This software is licensed under the GNU General Public License v3 or later.
5+
*
6+
* It is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or any later version.
9+
* This program 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+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*
17+
*/
18+
19+
package com.cloud.consoleproxy.util;
20+
21+
// logger facility for dynamic switch between console logger used in Applet and log4j based logger
22+
public class Logger {
23+
private static LoggerFactory factory = null;
24+
25+
public static final int LEVEL_TRACE = 1;
26+
public static final int LEVEL_DEBUG = 2;
27+
public static final int LEVEL_INFO = 3;
28+
public static final int LEVEL_WARN = 4;
29+
public static final int LEVEL_ERROR = 5;
30+
31+
private Class<?> clazz;
32+
private Logger logger;
33+
34+
private static int level = LEVEL_INFO;
35+
36+
public static Logger getLogger(Class<?> clazz) {
37+
return new Logger(clazz);
38+
}
39+
40+
public static void setFactory(LoggerFactory f) {
41+
factory = f;
42+
}
43+
44+
public static void setLevel(int l) {
45+
level = l;
46+
}
47+
48+
public Logger(Class<?> clazz) {
49+
this.clazz = clazz;
50+
}
51+
52+
protected Logger() {
53+
}
54+
55+
public boolean isTraceEnabled() {
56+
if(factory != null) {
57+
if(logger == null)
58+
logger = factory.getLogger(clazz);
59+
60+
return logger.isTraceEnabled();
61+
}
62+
return level <= LEVEL_TRACE;
63+
}
64+
65+
public boolean isDebugEnabled() {
66+
if(factory != null) {
67+
if(logger == null)
68+
logger = factory.getLogger(clazz);
69+
70+
return logger.isDebugEnabled();
71+
}
72+
return level <= LEVEL_DEBUG;
73+
}
74+
75+
public boolean isInfoEnabled() {
76+
if(factory != null) {
77+
if(logger == null)
78+
logger = factory.getLogger(clazz);
79+
80+
return logger.isInfoEnabled();
81+
}
82+
return level <= LEVEL_INFO;
83+
}
84+
85+
public void trace(Object message) {
86+
87+
if(factory != null) {
88+
if(logger == null)
89+
logger = factory.getLogger(clazz);
90+
91+
logger.trace(message);
92+
} else {
93+
if(level <= LEVEL_TRACE)
94+
System.out.println(message);
95+
}
96+
}
97+
98+
public void trace(Object message, Throwable exception) {
99+
if(factory != null) {
100+
if(logger == null)
101+
logger = factory.getLogger(clazz);
102+
103+
logger.trace(message, exception);
104+
} else {
105+
if(level <= LEVEL_TRACE) {
106+
System.out.println(message);
107+
if (exception != null) {
108+
exception.printStackTrace(System.out);
109+
}
110+
}
111+
}
112+
}
113+
114+
public void info(Object message) {
115+
if(factory != null) {
116+
if(logger == null)
117+
logger = factory.getLogger(clazz);
118+
119+
logger.info(message);
120+
} else {
121+
if(level <= LEVEL_INFO)
122+
System.out.println(message);
123+
}
124+
}
125+
126+
public void info(Object message, Throwable exception) {
127+
if(factory != null) {
128+
if(logger == null)
129+
logger = factory.getLogger(clazz);
130+
131+
logger.info(message, exception);
132+
} else {
133+
if(level <= LEVEL_INFO) {
134+
System.out.println(message);
135+
if (exception != null) {
136+
exception.printStackTrace(System.out);
137+
}
138+
}
139+
}
140+
}
141+
142+
public void debug(Object message) {
143+
if(factory != null) {
144+
if(logger == null)
145+
logger = factory.getLogger(clazz);
146+
147+
logger.debug(message);
148+
} else {
149+
if(level <= LEVEL_DEBUG)
150+
System.out.println(message);
151+
}
152+
}
153+
154+
public void debug(Object message, Throwable exception) {
155+
if(factory != null) {
156+
if(logger == null)
157+
logger = factory.getLogger(clazz);
158+
159+
logger.debug(message, exception);
160+
} else {
161+
if(level <= LEVEL_DEBUG) {
162+
System.out.println(message);
163+
if (exception != null) {
164+
exception.printStackTrace(System.out);
165+
}
166+
}
167+
}
168+
}
169+
170+
public void warn(Object message) {
171+
if(factory != null) {
172+
if(logger == null)
173+
logger = factory.getLogger(clazz);
174+
175+
logger.warn(message);
176+
} else {
177+
if(level <= LEVEL_WARN)
178+
System.out.println(message);
179+
}
180+
}
181+
182+
public void warn(Object message, Throwable exception) {
183+
if(factory != null) {
184+
if(logger == null)
185+
logger = factory.getLogger(clazz);
186+
187+
logger.warn(message, exception);
188+
} else {
189+
if(level <= LEVEL_WARN) {
190+
System.out.println(message);
191+
if (exception != null) {
192+
exception.printStackTrace(System.out);
193+
}
194+
}
195+
}
196+
}
197+
198+
public void error(Object message) {
199+
if(factory != null) {
200+
if(logger == null)
201+
logger = factory.getLogger(clazz);
202+
203+
logger.error(message);
204+
} else {
205+
if(level <= LEVEL_ERROR)
206+
System.out.println(message);
207+
}
208+
}
209+
210+
public void error(Object message, Throwable exception) {
211+
if(factory != null) {
212+
if(logger == null)
213+
logger = factory.getLogger(clazz);
214+
215+
logger.error(message, exception);
216+
} else {
217+
if(level <= LEVEL_ERROR) {
218+
System.out.println(message);
219+
if (exception != null) {
220+
exception.printStackTrace(System.out);
221+
}
222+
}
223+
}
224+
}
225+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
3+
*
4+
* This software is licensed under the GNU General Public License v3 or later.
5+
*
6+
* It is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or any later version.
9+
* This program 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+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*
17+
*/
18+
19+
package com.cloud.consoleproxy.util;
20+
21+
public interface LoggerFactory {
22+
Logger getLogger(Class<?> clazz);
23+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/**
2+
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
3+
*
4+
* This software is licensed under the GNU General Public License v3 or later.
5+
*
6+
* It is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or any later version.
9+
* This program 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+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*
17+
*/
18+
19+
package com.cloud.consoleproxy.util;
20+
21+
import java.awt.Rectangle;
22+
import java.util.ArrayList;
23+
import java.util.List;
24+
25+
public class Region {
26+
private Rectangle bound;
27+
private List<Rectangle> rectList;
28+
29+
public Region() {
30+
bound = new Rectangle(0, 0, 0, 0);
31+
rectList = new ArrayList<Rectangle>();
32+
}
33+
34+
public Region(Rectangle rect) {
35+
bound = new Rectangle(rect.x, rect.y, rect.width, rect.height);
36+
rectList = new ArrayList<Rectangle>();
37+
rectList.add(rect);
38+
}
39+
40+
public Rectangle getBound() {
41+
return bound;
42+
}
43+
44+
public void clearBound() {
45+
assert(rectList.size() == 0);
46+
bound.x = bound.y = bound.width = bound.height = 0;
47+
}
48+
49+
public List<Rectangle> getRectangles() {
50+
return rectList;
51+
}
52+
53+
public boolean add(Rectangle rect) {
54+
if(bound.isEmpty()) {
55+
assert(rectList.size() == 0);
56+
bound.x = rect.x;
57+
bound.y = rect.y;
58+
bound.width = rect.width;
59+
bound.height = rect.height;
60+
61+
rectList.add(rect);
62+
return true;
63+
}
64+
65+
Rectangle rcInflated = new Rectangle(rect.x - 1, rect.y- 1, rect.width + 2, rect.height + 2);
66+
if(!bound.intersects(rcInflated))
67+
return false;
68+
69+
for(Rectangle r : rectList) {
70+
if(r.intersects(rcInflated)) {
71+
if(!r.contains(rect)) {
72+
enlargeBound(rect);
73+
rectList.add(rect);
74+
return true;
75+
}
76+
}
77+
}
78+
return false;
79+
}
80+
81+
private void enlargeBound(Rectangle rect) {
82+
int boundLeft = Math.min(bound.x, rect.x);
83+
int boundTop = Math.min(bound.y, rect.y);
84+
int boundRight = Math.max(bound.x + bound.width, rect.x + rect.width);
85+
int boundBottom = Math.max(bound.y + bound.height, rect.y + rect.height);
86+
87+
bound.x = boundLeft;
88+
bound.y = boundTop;
89+
bound.width = boundRight - boundLeft;
90+
bound.height = boundBottom - boundTop;
91+
}
92+
}

0 commit comments

Comments
 (0)