• R/O
  • SSH
  • HTTPS

qrobosdk: コミット


コミットメタ情報

リビジョン1836 (tree)
日時2010-05-26 20:23:08
作者satofumi

ログメッセージ

fixed indent

変更サマリ

差分

--- trunk/doxes/urg_dox/Makefile (revision 1835)
+++ trunk/doxes/urg_dox/Makefile (revision 1836)
@@ -17,7 +17,7 @@
1717 all : $(TARGET)
1818 mkdir -p ../urg_programs/
1919 mkdir -p ../urg_programs/samples/
20- cd ../../libs/packages/urg && $(MAKE) zip && mv urg-*.zip ../../../doxes/urg_programs/
20+ cp urg-0.8.11.zip ../urg_programs/ #cd ../../libs/packages/urg && $(MAKE) zip && mv urg-*.zip ../../../doxes/urg_programs/
2121 -cp SDL_devel.zip ../urg_programs/
2222 -cp mConnection_0_recv.txt ../urg_programs/
2323 -cp UrgViewer.zip ../urg_programs/
--- trunk/libs/lua/luabindGui.cpp (revision 1835)
+++ trunk/libs/lua/luabindGui.cpp (revision 1836)
@@ -57,6 +57,7 @@
5757
5858 class_<CallbackEvent, Event>("CallbackEvent")
5959 .def(constructor<>())
60+ .def("setEventAcceptable", &CallbackEvent::setEventAcceptable)
6061 .def("clearEvent", &CallbackEvent::clearEvent)
6162 .def("key", &CallbackEvent::key)
6263 .def("click", &CallbackEvent::click)
--- trunk/libs/gui/Makefile (revision 1835)
+++ trunk/libs/gui/Makefile (revision 1836)
@@ -85,7 +85,7 @@
8585 CallbackEvent.o: CallbackEvent.h Event.h ../geometry/Point.h
8686 CallbackEvent.o: ../geometry/Rect.h ../geometry/RectUtils.h
8787 CanvasSurface.o: CanvasSurface.h Surface.h ../geometry/Rect.h
88-CanvasSurface.o: ../geometry/Point.h ../common/Color.h Font.h
88+CanvasSurface.o: ../geometry/Point.h ../common/Color.h Font.h TextSurface.h
8989 ChatMessage.o: ChatMessage.h Component.h ../geometry/Rect.h
9090 ChatMessage.o: ../geometry/Point.h Font.h ../common/Color.h TextSurface.h
9191 ChatMessage.o: Surface.h ../system/StopWatch.h
--- trunk/libs/gui/Menu.cpp (revision 1835)
+++ trunk/libs/gui/Menu.cpp (revision 1836)
@@ -57,6 +57,7 @@
5757 CallbackEvent decide_release_event_;
5858 CallbackEvent up_event_;
5959 CallbackEvent down_event_;
60+ bool event_acceptable_;
6061
6162 Label* icon_label_;
6263 bool icon_draw_front_;
@@ -70,7 +71,7 @@
7071 step_specified_(false), key_decided_(false),
7172 prev_cursor_(layer_manager_.cursor()), cursor_(prev_cursor_),
7273 enable_no_select_(false), enable_rotate_(false),
73- icon_label_(NULL), icon_draw_front_(true)
74+ event_acceptable_(true), icon_label_(NULL), icon_draw_front_(true)
7475 {
7576 setAilgnBase(align);
7677
@@ -338,7 +339,7 @@
338339 }
339340 // 配置直後の押下に反応しないための処理
340341 // これがないと、ウィンドウ配置用の押下に反応する
341- decide_press_event_.setEventAcceptable(true);
342+ decide_press_event_.setEventAcceptable(event_acceptable_);
342343
343344 size_t n = button_order_.size();
344345 bool decided = decide_release_event_.isActive();
@@ -353,8 +354,6 @@
353354 return;
354355 }
355356
356- // !!! align によってキーの役割を変更すること
357- // !!! left_event_, right_event_ を定義して使うようにする
358357 bool up = up_event_.isActive();
359358 bool down = down_event_.isActive();
360359
@@ -501,10 +500,17 @@
501500
502501 void setEventAcceptable(bool acceptable)
503502 {
503+ event_acceptable_ = acceptable;
504504 decide_press_event_.setEventAcceptable(acceptable);
505505 decide_release_event_.setEventAcceptable(acceptable);
506506 up_event_.setEventAcceptable(acceptable);
507507 down_event_.setEventAcceptable(acceptable);
508+
509+#if 0
510+ for (Items::iterator it = items_.begin(); it != items_.end(); ++it) {
511+ it->second->setEventAcceptable(acceptable);
512+ }
513+#endif
508514 }
509515
510516
--- trunk/libs/connection/sdl/SdlNetInit.h (revision 1835)
+++ trunk/libs/connection/sdl/SdlNetInit.h (revision 1836)
@@ -15,21 +15,19 @@
1515
1616 namespace qrk
1717 {
18- /*!
19- \brief SDL_net の初期化
20- */
21- class SdlNetInit
22- {
23- SdlNetInit(const SdlNetInit& rhs);
24- SdlNetInit& operator = (const SdlNetInit& rhs);
18+ //! SDL_net の初期化
19+ class SdlNetInit
20+ {
21+ SdlNetInit(const SdlNetInit& rhs);
22+ SdlNetInit& operator = (const SdlNetInit& rhs);
2523
26- struct pImpl;
27- std::auto_ptr<pImpl> pimpl;
24+ struct pImpl;
25+ std::auto_ptr<pImpl> pimpl;
2826
29- protected:
30- SdlNetInit(void);
31- ~SdlNetInit(void);
32- };
27+ protected:
28+ SdlNetInit(void);
29+ ~SdlNetInit(void);
30+ };
3331 }
3432
3533 #endif /* !QRK_SDL_NET_INIT_H */
--- trunk/libs/connection/sdl/SocketSet.cpp (revision 1835)
+++ trunk/libs/connection/sdl/SocketSet.cpp (revision 1836)
@@ -19,21 +19,21 @@
1919 */
2020 struct SocketSet::pImpl : private SdlNetInit
2121 {
22- size_t max_num;
23- size_t hold_num;
24- SDLNet_SocketSet socket_set;
22+ size_t max_num;
23+ size_t hold_num;
24+ SDLNet_SocketSet socket_set;
2525
26- pImpl(size_t size)
27- : max_num(size), hold_num(0),
28- socket_set(SDLNet_AllocSocketSet(static_cast<int>(max_num)))
29- {
30- }
26+ pImpl(size_t size)
27+ : max_num(size), hold_num(0),
28+ socket_set(SDLNet_AllocSocketSet(static_cast<int>(max_num)))
29+ {
30+ }
3131
3232
33- ~pImpl(void)
34- {
35- SDLNet_FreeSocketSet(socket_set);
36- }
33+ ~pImpl(void)
34+ {
35+ SDLNet_FreeSocketSet(socket_set);
36+ }
3737 };
3838
3939
@@ -49,26 +49,26 @@
4949
5050 bool SocketSet::add(TCPsocket socket)
5151 {
52- if (pimpl->hold_num < pimpl->max_num) {
53- if (SDLNet_TCP_AddSocket(pimpl->socket_set, socket) >= 0) {
54- ++(pimpl->hold_num);
55- return true;
52+ if (pimpl->hold_num < pimpl->max_num) {
53+ if (SDLNet_TCP_AddSocket(pimpl->socket_set, socket) >= 0) {
54+ ++(pimpl->hold_num);
55+ return true;
56+ }
5657 }
57- }
58- return false;
58+ return false;
5959 }
6060
6161
6262 void SocketSet::del(TCPsocket socket)
6363 {
64- if ((pimpl->hold_num > 0) &&
65- (SDLNet_TCP_DelSocket(pimpl->socket_set, socket) >= 0)) {
66- --(pimpl->hold_num);
67- }
64+ if ((pimpl->hold_num > 0) &&
65+ (SDLNet_TCP_DelSocket(pimpl->socket_set, socket) >= 0)) {
66+ --(pimpl->hold_num);
67+ }
6868 }
6969
7070
7171 size_t SocketSet::check(int timeout)
7272 {
73- return SDLNet_CheckSockets(pimpl->socket_set, timeout);
73+ return SDLNet_CheckSockets(pimpl->socket_set, timeout);
7474 }
--- trunk/libs/connection/sdl/TcpipAccepter.cpp (revision 1835)
+++ trunk/libs/connection/sdl/TcpipAccepter.cpp (revision 1836)
@@ -23,116 +23,117 @@
2323
2424 struct TcpipAccepter::pImpl : private SdlNetInit
2525 {
26- string error_message_;
27- IPaddress ip_address_;
28- TCPsocket accept_socket_;
29- SDLNet_SocketSet accept_set_;
30- bool is_activated_;
31- string server_name_;
26+ string error_message_;
27+ IPaddress ip_address_;
28+ TCPsocket accept_socket_;
29+ SDLNet_SocketSet accept_set_;
30+ bool is_activated_;
31+ string server_name_;
3232
3333
34- pImpl(void)
35- : error_message_("no error."),
36- accept_socket_(NULL), accept_set_(NULL), is_activated_(false),
37- server_name_("unknown")
38- {
39- }
34+ pImpl(void)
35+ : error_message_("no error."),
36+ accept_socket_(NULL), accept_set_(NULL), is_activated_(false),
37+ server_name_("unknown")
38+ {
39+ }
4040
4141
42- bool activate(long port)
43- {
44- if (is_activated_) {
45- deactivate();
46- }
42+ bool activate(long port)
43+ {
44+ if (is_activated_) {
45+ deactivate();
46+ }
4747
48- enum { BufferSize = 256 };
49- char buffer[BufferSize];
50- snprintf(buffer, BufferSize - 1, "%ld", port);
51- if (SDLNet_ResolveHost(&ip_address_, NULL, static_cast<Uint16>(port)) < 0) {
52- error_message_ =
53- string("activate(): can not assign port ")
54- + buffer + " :" + SDLNet_GetError();
55- return false;
56- }
48+ enum { BufferSize = 256 };
49+ char buffer[BufferSize];
50+ snprintf(buffer, BufferSize - 1, "%ld", port);
51+ if (SDLNet_ResolveHost(&ip_address_,
52+ NULL, static_cast<Uint16>(port)) < 0) {
53+ error_message_ =
54+ string("activate(): can not assign port ")
55+ + buffer + " :" + SDLNet_GetError();
56+ return false;
57+ }
5758
58- accept_socket_ = SDLNet_TCP_Open(&ip_address_);
59- if (accept_socket_ == NULL) {
60- error_message_ = string(SDLNet_GetError()) + " (" + buffer + ")";
61- return false;
62- }
59+ accept_socket_ = SDLNet_TCP_Open(&ip_address_);
60+ if (accept_socket_ == NULL) {
61+ error_message_ = string(SDLNet_GetError()) + " (" + buffer + ")";
62+ return false;
63+ }
6364
64- accept_set_ = SDLNet_AllocSocketSet(1);
65- if (accept_set_ == NULL) {
66- error_message_ = string("accept(): could not allock socket set.")
67- + ": " + SDLNet_GetError();
68- return false;
69- }
65+ accept_set_ = SDLNet_AllocSocketSet(1);
66+ if (accept_set_ == NULL) {
67+ error_message_ = string("accept(): could not allock socket set.")
68+ + ": " + SDLNet_GetError();
69+ return false;
70+ }
7071
71- if (SDLNet_TCP_AddSocket(accept_set_, accept_socket_) < 0) {
72- error_message_ = string("accept(): could not add socket.")
73- + " :" + SDLNet_GetError();
74- return false;
75- }
72+ if (SDLNet_TCP_AddSocket(accept_set_, accept_socket_) < 0) {
73+ error_message_ = string("accept(): could not add socket.")
74+ + " :" + SDLNet_GetError();
75+ return false;
76+ }
7677
77- is_activated_ = true;
78+ is_activated_ = true;
7879
79- // サーバ名の取得
80+ // サーバ名の取得
8081 #if defined(LINUX_OS)
81- char host[BufferSize];
82- if (gethostname(host, BufferSize) == 0) {
83- host[BufferSize - 1] = '\0';
84- server_name_ = host;
85- }
82+ char host[BufferSize];
83+ if (gethostname(host, BufferSize) == 0) {
84+ host[BufferSize - 1] = '\0';
85+ server_name_ = host;
86+ }
8687 #else
87- // !!! Windows 用の実装
88+ // !!! Windows 用の実装
8889 #endif
8990
90- return true;
91- }
92-
93-
94- void deactivate(void)
95- {
96- if (! is_activated_) {
97- return;
91+ return true;
9892 }
9993
100- if (SDLNet_TCP_DelSocket(accept_set_, accept_socket_) < 0) {
101- error_message_ = "deactivate(): SDLNet_GetError()";
102- return;
103- }
10494
105- SDLNet_FreeSocketSet(accept_set_);
106- accept_set_ = NULL;
95+ void deactivate(void)
96+ {
97+ if (! is_activated_) {
98+ return;
99+ }
107100
108- SDLNet_TCP_Close(accept_socket_);
109- accept_socket_ = NULL;
101+ if (SDLNet_TCP_DelSocket(accept_set_, accept_socket_) < 0) {
102+ error_message_ = "deactivate(): SDLNet_GetError()";
103+ return;
104+ }
110105
111- is_activated_ = false;
112- server_name_ = "unknown";
113- }
106+ SDLNet_FreeSocketSet(accept_set_);
107+ accept_set_ = NULL;
114108
109+ SDLNet_TCP_Close(accept_socket_);
110+ accept_socket_ = NULL;
115111
116- TcpipSocket* accept(int timeout)
117- {
118- if (is_activated_ == false) {
119- error_message_ = "call activate() before accept() called.";
120- return NULL;
112+ is_activated_ = false;
113+ server_name_ = "unknown";
121114 }
122115
123- int n = SDLNet_CheckSockets(accept_set_, timeout);
124- if ((n <= 0) || (! SDLNet_SocketReady(accept_socket_))) {
125- // 接続なし
126- return NULL;
127- }
128116
129- TCPsocket socket = SDLNet_TCP_Accept(accept_socket_);
130- if (! socket) {
131- return NULL;
117+ TcpipSocket* accept(int timeout)
118+ {
119+ if (is_activated_ == false) {
120+ error_message_ = "call activate() before accept() called.";
121+ return NULL;
122+ }
123+
124+ int n = SDLNet_CheckSockets(accept_set_, timeout);
125+ if ((n <= 0) || (! SDLNet_SocketReady(accept_socket_))) {
126+ // 接続なし
127+ return NULL;
128+ }
129+
130+ TCPsocket socket = SDLNet_TCP_Accept(accept_socket_);
131+ if (! socket) {
132+ return NULL;
133+ }
134+
135+ return new TcpipSocket(socket);
132136 }
133-
134- return new TcpipSocket(socket);
135- }
136137 };
137138
138139
@@ -148,29 +149,29 @@
148149
149150 const char* TcpipAccepter::what(void) const
150151 {
151- return pimpl->error_message_.c_str();
152+ return pimpl->error_message_.c_str();
152153 }
153154
154155
155156 bool TcpipAccepter::activate(long port)
156157 {
157- return pimpl->activate(port);
158+ return pimpl->activate(port);
158159 }
159160
160161
161162 void TcpipAccepter::deactivate(void)
162163 {
163- pimpl->deactivate();
164+ pimpl->deactivate();
164165 }
165166
166167
167168 TcpipSocket* TcpipAccepter::accept(int timeout)
168169 {
169- return pimpl->accept(timeout);
170+ return pimpl->accept(timeout);
170171 }
171172
172173
173174 const char* TcpipAccepter::name(void)
174175 {
175- return pimpl->server_name_.c_str();
176+ return pimpl->server_name_.c_str();
176177 }
--- trunk/libs/connection/sdl/TcpipServer.cpp (revision 1835)
+++ trunk/libs/connection/sdl/TcpipServer.cpp (revision 1836)
@@ -28,126 +28,128 @@
2828
2929 struct TcpipServer::pImpl : private SdlNetInit
3030 {
31- string error_message_;
32- IPaddress ip_address_;
33- TCPsocket accept_socket_;
34- SDLNet_SocketSet accept_set_;
35- bool is_activated_;
31+ string error_message_;
32+ IPaddress ip_address_;
33+ TCPsocket accept_socket_;
34+ SDLNet_SocketSet accept_set_;
35+ bool is_activated_;
3636
37- TcpipSocket* con_;
37+ TcpipSocket* con_;
3838
3939
40- pImpl(void)
41- : error_message_("no error."),
42- accept_socket_(NULL), accept_set_(NULL), is_activated_(false), con_(NULL)
43- {
44- }
45-
46-
47- ~pImpl(void)
48- {
49- if (con_) {
50- delete con_;
40+ pImpl(void)
41+ : error_message_("no error."),
42+ accept_socket_(NULL), accept_set_(NULL),
43+ is_activated_(false), con_(NULL)
44+ {
5145 }
52- }
5346
5447
55- bool activate(long port)
56- {
57- if (is_activated_) {
58- disconnect();
59- deactivate();
48+ ~pImpl(void)
49+ {
50+ if (con_) {
51+ delete con_;
52+ }
6053 }
6154
62- if (SDLNet_ResolveHost(&ip_address_, NULL, static_cast<Uint16>(port)) < 0) {
63- enum { BufferSize = 256 };
64- char buffer[BufferSize];
65- snprintf(buffer, BufferSize - 1, "%ld", port);
6655
67- error_message_ =
68- string("activate(): can not assign port ")
69- + buffer + " :" + SDLNet_GetError();
70- return false;
71- }
56+ bool activate(long port)
57+ {
58+ if (is_activated_) {
59+ disconnect();
60+ deactivate();
61+ }
7262
73- accept_socket_ = SDLNet_TCP_Open(&ip_address_);
74- if (accept_socket_ == NULL) {
75- error_message_ = string("activate(): could not open socket.")
76- + " :" + SDLNet_GetError();
77- return false;
78- }
63+ if (SDLNet_ResolveHost(&ip_address_, NULL,
64+ static_cast<Uint16>(port)) < 0) {
65+ enum { BufferSize = 256 };
66+ char buffer[BufferSize];
67+ snprintf(buffer, BufferSize - 1, "%ld", port);
7968
80- accept_set_ = SDLNet_AllocSocketSet(1);
81- if (accept_set_ == NULL) {
82- error_message_ = string("accept(): could not allock socket set.")
83- + ": " + SDLNet_GetError();
84- return false;
85- }
69+ error_message_ =
70+ string("activate(): can not assign port ")
71+ + buffer + " :" + SDLNet_GetError();
72+ return false;
73+ }
8674
87- if (SDLNet_TCP_AddSocket(accept_set_, accept_socket_) < 0) {
88- error_message_ = string("accept(): could not add socket.")
89- + " :" + SDLNet_GetError();
90- return false;
91- }
75+ accept_socket_ = SDLNet_TCP_Open(&ip_address_);
76+ if (accept_socket_ == NULL) {
77+ error_message_ = string("activate(): could not open socket.")
78+ + " :" + SDLNet_GetError();
79+ return false;
80+ }
9281
93- is_activated_ = true;
94- return true;
95- }
82+ accept_set_ = SDLNet_AllocSocketSet(1);
83+ if (accept_set_ == NULL) {
84+ error_message_ = string("accept(): could not allock socket set.")
85+ + ": " + SDLNet_GetError();
86+ return false;
87+ }
9688
89+ if (SDLNet_TCP_AddSocket(accept_set_, accept_socket_) < 0) {
90+ error_message_ = string("accept(): could not add socket.")
91+ + " :" + SDLNet_GetError();
92+ return false;
93+ }
9794
98- void deactivate(void)
99- {
100- if (! is_activated_) {
101- return;
95+ is_activated_ = true;
96+ return true;
10297 }
10398
104- if (SDLNet_TCP_DelSocket(accept_set_, accept_socket_) < 0) {
105- error_message_ = "deactivate(): SDLNet_GetError()";
106- return;
107- }
10899
109- SDLNet_FreeSocketSet(accept_set_);
110- accept_set_ = NULL;
100+ void deactivate(void)
101+ {
102+ if (! is_activated_) {
103+ return;
104+ }
111105
112- SDLNet_TCP_Close(accept_socket_);
113- accept_socket_ = NULL;
106+ if (SDLNet_TCP_DelSocket(accept_set_, accept_socket_) < 0) {
107+ error_message_ = "deactivate(): SDLNet_GetError()";
108+ return;
109+ }
114110
115- is_activated_ = false;
116- }
111+ SDLNet_FreeSocketSet(accept_set_);
112+ accept_set_ = NULL;
117113
114+ SDLNet_TCP_Close(accept_socket_);
115+ accept_socket_ = NULL;
118116
119- bool accept(int timeout)
120- {
121- if (is_activated_ == false) {
122- error_message_ = "call activate() before accept() called.";
123- return false;
117+ is_activated_ = false;
124118 }
125119
126- int n = SDLNet_CheckSockets(accept_set_, timeout);
127- if ((n <= 0) || (! SDLNet_SocketReady(accept_socket_))) {
128- // 接続なし
129- return false;
130- }
131120
132- TCPsocket socket = SDLNet_TCP_Accept(accept_socket_);
133- if (socket == NULL) {
134- return false;
135- }
121+ bool accept(int timeout)
122+ {
123+ if (is_activated_ == false) {
124+ error_message_ = "call activate() before accept() called.";
125+ return false;
126+ }
136127
137- if (con_) {
138- delete con_;
128+ int n = SDLNet_CheckSockets(accept_set_, timeout);
129+ if ((n <= 0) || (! SDLNet_SocketReady(accept_socket_))) {
130+ // 接続なし
131+ return false;
132+ }
133+
134+ TCPsocket socket = SDLNet_TCP_Accept(accept_socket_);
135+ if (socket == NULL) {
136+ return false;
137+ }
138+
139+ if (con_) {
140+ delete con_;
141+ }
142+ con_ = new TcpipSocket(socket);
143+ return true;
139144 }
140- con_ = new TcpipSocket(socket);
141- return true;
142- }
143145
144146
145- void disconnect(void)
146- {
147- if (con_) {
148- con_->disconnect();
147+ void disconnect(void)
148+ {
149+ if (con_) {
150+ con_->disconnect();
151+ }
149152 }
150- }
151153 };
152154
153155
@@ -158,126 +160,126 @@
158160
159161 TcpipServer::~TcpipServer(void)
160162 {
161- deactivate();
163+ deactivate();
162164 }
163165
164166
165167 const char* TcpipServer::what(void) const
166168 {
167- return pimpl->error_message_.c_str();
169+ return pimpl->error_message_.c_str();
168170 }
169171
170172
171173 bool TcpipServer::activate(long port)
172174 {
173- return pimpl->activate(port);
175+ return pimpl->activate(port);
174176 }
175177
176178
177179 void TcpipServer::deactivate(void)
178180 {
179- pimpl->deactivate();
181+ pimpl->deactivate();
180182 }
181183
182184
183185 bool TcpipServer::accept(int timeout)
184186 {
185- return pimpl->accept(timeout);
187+ return pimpl->accept(timeout);
186188 }
187189
188190
189191 bool TcpipServer::connect(const char* host, long port)
190192 {
191- if (! isConnected()) {
192- return false;
193- }
193+ if (! isConnected()) {
194+ return false;
195+ }
194196
195- return pimpl->con_->connect(host, port);
197+ return pimpl->con_->connect(host, port);
196198 }
197199
198200
199201 void TcpipServer::disconnect(void)
200202 {
201- pimpl->disconnect();
203+ pimpl->disconnect();
202204 }
203205
204206
205207 bool TcpipServer::setBaudrate(long baudrate)
206208 {
207- if (! isConnected()) {
208- return false;
209- }
210- return pimpl->con_->setBaudrate(baudrate);
209+ if (! isConnected()) {
210+ return false;
211+ }
212+ return pimpl->con_->setBaudrate(baudrate);
211213 }
212214
213215
214216 long TcpipServer::baudrate(void) const
215217 {
216- if (! isConnected()) {
217- return -1;
218- }
219- return pimpl->con_->baudrate();
218+ if (! isConnected()) {
219+ return -1;
220+ }
221+ return pimpl->con_->baudrate();
220222 }
221223
222224
223225 bool TcpipServer::isConnected(void) const
224226 {
225- if (! pimpl->con_) {
226- return false;
227- }
228- return pimpl->con_->isConnected();
227+ if (! pimpl->con_) {
228+ return false;
229+ }
230+ return pimpl->con_->isConnected();
229231 }
230232
231233
232234 int TcpipServer::send(const char* data, size_t count)
233235 {
234- if (! pimpl->con_) {
235- return -1;
236- }
237- return pimpl->con_->send(data, count);
236+ if (! pimpl->con_) {
237+ return -1;
238+ }
239+ return pimpl->con_->send(data, count);
238240 }
239241
240242
241243 int TcpipServer::receive(char* data, size_t count, int timeout)
242244 {
243- if (! pimpl->con_) {
244- return -1;
245- }
246- return pimpl->con_->receive(data, count, timeout);
245+ if (! pimpl->con_) {
246+ return -1;
247+ }
248+ return pimpl->con_->receive(data, count, timeout);
247249 }
248250
249251
250252 size_t TcpipServer::size(void) const
251253 {
252- if (! pimpl->con_) {
253- return 0;
254- }
255- return pimpl->con_->size();
254+ if (! pimpl->con_) {
255+ return 0;
256+ }
257+ return pimpl->con_->size();
256258 }
257259
258260
259261 void TcpipServer::flush(void)
260262 {
261- if (! pimpl->con_) {
262- return;
263- }
264- return pimpl->con_->flush();
263+ if (! pimpl->con_) {
264+ return;
265+ }
266+ return pimpl->con_->flush();
265267 }
266268
267269
268270 void TcpipServer::clear(void)
269271 {
270- if (! pimpl->con_) {
271- return;
272- }
273- return pimpl->con_->clear();
272+ if (! pimpl->con_) {
273+ return;
274+ }
275+ return pimpl->con_->clear();
274276 }
275277
276278
277279 void TcpipServer::ungetc(const char ch)
278280 {
279- if (! pimpl->con_) {
280- return;
281- }
282- return pimpl->con_->ungetc(ch);
281+ if (! pimpl->con_) {
282+ return;
283+ }
284+ return pimpl->con_->ungetc(ch);
283285 }
--- trunk/libs/connection/sdl/TcpipSocket.cpp (revision 1835)
+++ trunk/libs/connection/sdl/TcpipSocket.cpp (revision 1836)
@@ -24,101 +24,103 @@
2424
2525 struct TcpipSocket::pImpl : private SdlNetInit
2626 {
27- string error_message_;
28- TCPsocket socket_;
29- SocketSet* socket_set_;
30- SDLNet_SocketSet own_set_;
31- RingBuffer<char> ring_buffer_;
32- bool have_data_;
33- long dummy_baudrate_;
27+ string error_message_;
28+ TCPsocket socket_;
29+ SocketSet* socket_set_;
30+ SDLNet_SocketSet own_set_;
31+ RingBuffer<char> ring_buffer_;
32+ bool have_data_;
33+ long dummy_baudrate_;
3434
3535
36- pImpl(TCPsocket socket, SocketSet* socket_set)
37- : error_message_("no error."), socket_(socket),
38- socket_set_(socket_set), own_set_(NULL), have_data_(false),
39- dummy_baudrate_(0)
40- {
41- if (socket_set_ == NULL) {
42- own_set_ = SDLNet_AllocSocketSet(1);
43- if (socket_ != NULL) {
44- addSocket(socket_);
45- }
46- } else {
47- socket_set_->add(socket_);
36+ pImpl(TCPsocket socket, SocketSet* socket_set)
37+ : error_message_("no error."), socket_(socket),
38+ socket_set_(socket_set), own_set_(NULL), have_data_(false),
39+ dummy_baudrate_(0)
40+ {
41+ if (socket_set_ == NULL) {
42+ own_set_ = SDLNet_AllocSocketSet(1);
43+ if (socket_ != NULL) {
44+ addSocket(socket_);
45+ }
46+ } else {
47+ socket_set_->add(socket_);
48+ }
4849 }
49- }
5050
5151
52- ~pImpl(void)
53- {
54- disconnect();
55- if (own_set_) {
56- SDLNet_FreeSocketSet(own_set_);
52+ ~pImpl(void)
53+ {
54+ disconnect();
55+ if (own_set_) {
56+ SDLNet_FreeSocketSet(own_set_);
57+ }
5758 }
58- }
5959
6060
61- void disconnect(void)
62- {
63- if (socket_) {
64- if (socket_set_) {
65- socket_set_->del(socket_);
66- } else {
67- deleteSocket(socket_);
68- }
61+ void disconnect(void)
62+ {
63+ if (socket_) {
64+ if (socket_set_) {
65+ socket_set_->del(socket_);
66+ } else {
67+ deleteSocket(socket_);
68+ }
6969
70- SDLNet_TCP_Close(socket_);
71- socket_ = NULL;
70+ SDLNet_TCP_Close(socket_);
71+ socket_ = NULL;
72+ }
73+ error_message_ = "disconnected.";
7274 }
73- error_message_ = "disconnected.";
74- }
7575
7676
77- void addSocket(TCPsocket socket)
78- {
79- SDLNet_TCP_AddSocket(own_set_, socket);
80- }
77+ void addSocket(TCPsocket socket)
78+ {
79+ SDLNet_TCP_AddSocket(own_set_, socket);
80+ }
8181
8282
83- void deleteSocket(TCPsocket socket)
84- {
85- SDLNet_TCP_DelSocket(own_set_, socket);
86- }
83+ void deleteSocket(TCPsocket socket)
84+ {
85+ SDLNet_TCP_DelSocket(own_set_, socket);
86+ }
8787
8888
89- int update(int timeout, int size = 0)
90- {
91- enum { BufferSize = 1024 };
92- int require_size = (size > 0) ? size : BufferSize;
93- int filled = 0;
94- while (filled < require_size) {
95- if (socket_set_ == NULL) {
96- if (SDLNet_CheckSockets(own_set_, (size == 0) ? 0 : timeout) <= 0) {
97- break;
89+ int update(int timeout, int size = 0)
90+ {
91+ enum { BufferSize = 1024 };
92+ int require_size = (size > 0) ? size : BufferSize;
93+ int filled = 0;
94+ while (filled < require_size) {
95+ if (socket_set_ == NULL) {
96+ if (SDLNet_CheckSockets(own_set_,
97+ (size == 0) ? 0 : timeout) <= 0) {
98+ break;
99+ }
100+ }
101+ if (! SDLNet_SocketReady(socket_)) {
102+ break;
103+ }
104+ char data[BufferSize];
105+ int read_n = require_size - filled;
106+ int n =
107+ SDLNet_TCP_Recv(socket_, data,
108+ (read_n > BufferSize) ? BufferSize : read_n);
109+ if (n <= 0) {
110+ disconnect();
111+ return -1;
112+ }
113+ ring_buffer_.put(data, n);
114+ have_data_ = true;
115+ filled += n;
116+
117+ if (socket_set_ != NULL) {
118+ // SocketSet を使ったチェックの関係で、読み込みは1回のみ
119+ break;
120+ }
98121 }
99- }
100- if (! SDLNet_SocketReady(socket_)) {
101- break;
102- }
103- char data[BufferSize];
104- int read_n = require_size - filled;
105- int n = SDLNet_TCP_Recv(socket_, data,
106- (read_n > BufferSize) ? BufferSize : read_n);
107- if (n <= 0) {
108- disconnect();
109- return -1;
110- }
111- ring_buffer_.put(data, n);
112- have_data_ = true;
113- filled += n;
114-
115- if (socket_set_ != NULL) {
116- // SocketSet を使ったチェックの関係で、読み込みを行うのは1回のみ
117- break;
118- }
122+ return 0;
119123 }
120- return 0;
121- }
122124 };
123125
124126
@@ -128,13 +130,13 @@
128130
129131
130132 TcpipSocket::TcpipSocket(void* socket)
131- : pimpl(new pImpl(static_cast<TCPsocket>(socket), NULL))
133+ : pimpl(new pImpl(static_cast<TCPsocket>(socket), NULL))
132134 {
133135 }
134136
135137
136138 TcpipSocket::TcpipSocket(SocketSet* socket_set, void* socket)
137- : pimpl(new pImpl(static_cast<TCPsocket>(socket), socket_set))
139+ : pimpl(new pImpl(static_cast<TCPsocket>(socket), socket_set))
138140 {
139141 }
140142
@@ -146,142 +148,143 @@
146148
147149 const char* TcpipSocket::what(void) const
148150 {
149- return pimpl->error_message_.c_str();
151+ return pimpl->error_message_.c_str();
150152 }
151153
154+
152155 bool TcpipSocket::connect(const char* host, long port)
153156 {
154- IPaddress ip;
155- int ret = SDLNet_ResolveHost(&ip, host, static_cast<short>(port));
156- if (ret < 0) {
157- pimpl->error_message_ =
158- string("SDLNet_ResolveHost(): ") + SDLNet_GetError();
159- return false;
160- }
157+ IPaddress ip;
158+ int ret = SDLNet_ResolveHost(&ip, host, static_cast<short>(port));
159+ if (ret < 0) {
160+ pimpl->error_message_ =
161+ string("SDLNet_ResolveHost(): ") + SDLNet_GetError();
162+ return false;
163+ }
161164
162- TCPsocket socket = SDLNet_TCP_Open(&ip);
163- if (socket == NULL) {
164- char strnum[13];
165- sprintf(strnum, "%ld", port);
166- pimpl->error_message_ =
167- string(SDLNet_GetError()) + " (" + host + ", " + strnum + ")";
168- return false;
169- }
170- disconnect();
171- swap(socket, pimpl->socket_);
165+ TCPsocket socket = SDLNet_TCP_Open(&ip);
166+ if (socket == NULL) {
167+ char strnum[13];
168+ sprintf(strnum, "%ld", port);
169+ pimpl->error_message_ =
170+ string(SDLNet_GetError()) + " (" + host + ", " + strnum + ")";
171+ return false;
172+ }
173+ disconnect();
174+ swap(socket, pimpl->socket_);
172175
173- // ソケットを登録
174- if (pimpl->socket_set_) {
175- pimpl->socket_set_->add(pimpl->socket_);
176- } else {
177- pimpl->addSocket(pimpl->socket_);
178- }
179- pimpl->error_message_ = "connected.";
180- return true;
176+ // ソケットを登録
177+ if (pimpl->socket_set_) {
178+ pimpl->socket_set_->add(pimpl->socket_);
179+ } else {
180+ pimpl->addSocket(pimpl->socket_);
181+ }
182+ pimpl->error_message_ = "connected.";
183+ return true;
181184 }
182185
183186
184187 void TcpipSocket::disconnect(void)
185188 {
186- pimpl->disconnect();
189+ pimpl->disconnect();
187190 }
188191
189192
190193 bool TcpipSocket::setBaudrate(long baudrate)
191194 {
192- pimpl->dummy_baudrate_ = baudrate;
193- return true;
195+ pimpl->dummy_baudrate_ = baudrate;
196+ return true;
194197 }
195198
196199
197200 long TcpipSocket::baudrate(void) const
198201 {
199- return pimpl->dummy_baudrate_;
202+ return pimpl->dummy_baudrate_;
200203 }
201204
202205
203206 bool TcpipSocket::isConnected(void) const
204207 {
205- return (pimpl->socket_ == NULL) ? false : true;
208+ return (pimpl->socket_ == NULL) ? false : true;
206209 }
207210
208211
209212 int TcpipSocket::send(const char* data, size_t count)
210213 {
211- if (! isConnected()) {
212- return -1;
213- }
214- return SDLNet_TCP_Send(pimpl->socket_,
215- const_cast<char*>(data), static_cast<int>(count));
214+ if (! isConnected()) {
215+ return -1;
216+ }
217+ return SDLNet_TCP_Send(pimpl->socket_,
218+ const_cast<char*>(data), static_cast<int>(count));
216219 }
217220
218221
219222 int TcpipSocket::receive(char* data, size_t count, int timeout)
220223 {
221- if (! isConnected()) {
222- return -1;
223- } else if (count == 0) {
224- return 0;
225- }
224+ if (! isConnected()) {
225+ return -1;
226+ } else if (count == 0) {
227+ return 0;
228+ }
226229
227- // 受信データの更新
228- if ((pimpl->update(timeout) < 0) && (! pimpl->have_data_)) {
229- // 切断を検出
230- return -1;
231- }
230+ // 受信データの更新
231+ if ((pimpl->update(timeout) < 0) && (! pimpl->have_data_)) {
232+ // 切断を検出
233+ return -1;
234+ }
232235
233- // 要求分だけ受信データがあれば、返す
234- size_t filled = pimpl->ring_buffer_.size();
235- if (filled >= count) {
236- pimpl->ring_buffer_.get(data, static_cast<int>(count));
237- pimpl->have_data_ = ! pimpl->ring_buffer_.empty();
238- return static_cast<int>(count);
239- }
236+ // 要求分だけ受信データがあれば、返す
237+ size_t filled = pimpl->ring_buffer_.size();
238+ if (filled >= count) {
239+ pimpl->ring_buffer_.get(data, static_cast<int>(count));
240+ pimpl->have_data_ = ! pimpl->ring_buffer_.empty();
241+ return static_cast<int>(count);
242+ }
240243
241- // 受信できたデータを返す
242- int left = static_cast<int>(count - filled);
243- if ((pimpl->own_set_ != NULL) && (pimpl->update(timeout, left) < 0)
244- && (! pimpl->have_data_)) {
245- // 切断を検出
246- return -1;
247- }
244+ // 受信できたデータを返す
245+ int left = static_cast<int>(count - filled);
246+ if ((pimpl->own_set_ != NULL) && (pimpl->update(timeout, left) < 0)
247+ && (! pimpl->have_data_)) {
248+ // 切断を検出
249+ return -1;
250+ }
248251
249- // size() を呼ぶと update(0) が呼ばれるため
250- filled = pimpl->ring_buffer_.size();
251- pimpl->ring_buffer_.get(data, filled);
252- pimpl->have_data_ = ! pimpl->ring_buffer_.empty();
252+ // size() を呼ぶと update(0) が呼ばれるため
253+ filled = pimpl->ring_buffer_.size();
254+ pimpl->ring_buffer_.get(data, filled);
255+ pimpl->have_data_ = ! pimpl->ring_buffer_.empty();
253256
254- return static_cast<int>(filled);
257+ return static_cast<int>(filled);
255258 }
256259
257260
258261 size_t TcpipSocket::size(void) const
259262 {
260- if ((pimpl->update(0) < 0) && (! pimpl->have_data_)) {
261- return 0;
262- }
263- return pimpl->ring_buffer_.size();
263+ if ((pimpl->update(0) < 0) && (! pimpl->have_data_)) {
264+ return 0;
265+ }
266+ return pimpl->ring_buffer_.size();
264267 }
265268
266269
267270 void TcpipSocket::flush(void)
268271 {
269- // 実装方法、不明
272+ // 実装方法、不明
270273 }
271274
272275
273276 void TcpipSocket::clear(void)
274277 {
275- pimpl->ring_buffer_.clear();
278+ pimpl->ring_buffer_.clear();
276279 }
277280
278281
279282 void TcpipSocket::ungetc(const char ch)
280283 {
281- if (! isConnected()) {
282- pimpl->error_message_ = "no connection.";
283- return;
284- }
284+ if (! isConnected()) {
285+ pimpl->error_message_ = "no connection.";
286+ return;
287+ }
285288
286- pimpl->ring_buffer_.ungetc(ch);
289+ pimpl->ring_buffer_.ungetc(ch);
287290 }
--- trunk/libs/connection/sdl/SocketSet.h (revision 1835)
+++ trunk/libs/connection/sdl/SocketSet.h (revision 1836)
@@ -15,59 +15,57 @@
1515
1616 namespace qrk
1717 {
18- class TcpipCtrl;
18+ class TcpipCtrl;
1919
2020
21- /*!
22- \brief 通信ソケット管理
23- */
24- class SocketSet
25- {
26- public:
27- /*!
28- \brief コンストラクタ
21+ //! 通信ソケット管理
22+ class SocketSet
23+ {
24+ public:
25+ /*!
26+ \brief コンストラクタ
2927
30- \param size [i] 初期状態でのソケット許容数
31- */
32- explicit SocketSet(size_t size = 1);
33- ~SocketSet(void);
28+ \param size [i] 初期状態でのソケット許容数
29+ */
30+ explicit SocketSet(size_t size = 1);
31+ ~SocketSet(void);
3432
3533
36- /*!
37- \brief ソケットの登録
34+ /*!
35+ \brief ソケットの登録
3836
39- \param socket [i] 登録するソケット
37+ \param socket [i] 登録するソケット
4038
41- \retval true 登録に成功
42- \retval false 登録に失敗
43- */
44- bool add(TCPsocket socket);
39+ \retval true 登録に成功
40+ \retval false 登録に失敗
41+ */
42+ bool add(TCPsocket socket);
4543
4644
47- /*!
48- \brief ソケットの削除
45+ /*!
46+ \brief ソケットの削除
4947
50- \param socket [i] 削除するソケット
51- */
52- void del(TCPsocket socket);
48+ \param socket [i] 削除するソケット
49+ */
50+ void del(TCPsocket socket);
5351
5452
55- /*!
56- \brief 受信データがあるかの確認
53+ /*!
54+ \brief 受信データがあるかの確認
5755
58- \param timeout [i] タイムアウト時間 [msec]
56+ \param timeout [i] タイムアウト時間 [msec]
5957
60- \return 受信データのあるソケット数
61- */
62- size_t check(int timeout);
58+ \return 受信データのあるソケット数
59+ */
60+ size_t check(int timeout);
6361
64- private:
65- SocketSet(const SocketSet& rhs);
66- SocketSet& operator = (const SocketSet& rhs);
62+ private:
63+ SocketSet(const SocketSet& rhs);
64+ SocketSet& operator = (const SocketSet& rhs);
6765
68- struct pImpl;
69- const std::auto_ptr<pImpl> pimpl;
70- };
66+ struct pImpl;
67+ const std::auto_ptr<pImpl> pimpl;
68+ };
7169 }
7270
7371 #endif /* !QRK_SOCKET_SET_H */
--- trunk/libs/connection/sdl/TcpipServer.h (revision 1835)
+++ trunk/libs/connection/sdl/TcpipServer.h (revision 1836)
@@ -16,41 +16,41 @@
1616
1717 namespace qrk
1818 {
19- //! TCP/IP サーバ
20- class TcpipServer : public Connection
21- {
22- public:
23- enum {
24- NoTimeout = -1,
25- };
26- TcpipServer(void);
27- ~TcpipServer(void);
19+ //! TCP/IP サーバ
20+ class TcpipServer : public Connection
21+ {
22+ public:
23+ enum {
24+ NoTimeout = -1,
25+ };
26+ TcpipServer(void);
27+ ~TcpipServer(void);
2828
29- const char* what(void) const;
29+ const char* what(void) const;
3030
31- bool activate(long port);
32- void deactivate(void);
33- bool accept(int timeout = NoTimeout);
31+ bool activate(long port);
32+ void deactivate(void);
33+ bool accept(int timeout = NoTimeout);
3434
35- bool connect(const char* host, long port);
36- void disconnect(void);
37- bool setBaudrate(long baudrate);
38- long baudrate(void) const;
39- bool isConnected(void) const;
40- int send(const char* data, size_t count);
41- int receive(char* data, size_t count, int timeout);
42- size_t size(void) const;
43- void flush(void);
44- void clear(void);
45- void ungetc(const char ch);
35+ bool connect(const char* host, long port);
36+ void disconnect(void);
37+ bool setBaudrate(long baudrate);
38+ long baudrate(void) const;
39+ bool isConnected(void) const;
40+ int send(const char* data, size_t count);
41+ int receive(char* data, size_t count, int timeout);
42+ size_t size(void) const;
43+ void flush(void);
44+ void clear(void);
45+ void ungetc(const char ch);
4646
47- private:
48- TcpipServer(const TcpipServer& rhs);
49- TcpipServer& operator = (const TcpipServer& rhs);
47+ private:
48+ TcpipServer(const TcpipServer& rhs);
49+ TcpipServer& operator = (const TcpipServer& rhs);
5050
51- struct pImpl;
52- const std::auto_ptr<pImpl> pimpl;
53- };
51+ struct pImpl;
52+ const std::auto_ptr<pImpl> pimpl;
53+ };
5454 }
5555
5656 #endif /* !QRK_TCPIP_SERVER_H */
--- trunk/libs/connection/sdl/TestTcpipServer.h (revision 1835)
+++ trunk/libs/connection/sdl/TestTcpipServer.h (revision 1836)
@@ -18,14 +18,14 @@
1818 */
1919 class TestTcpipServer : public CppUnit::TestFixture
2020 {
21- CPPUNIT_TEST_SUITE(TestTcpipServer);
22- CPPUNIT_TEST(connectTest);
23- CPPUNIT_TEST(timeoutTest);
24- CPPUNIT_TEST_SUITE_END();
21+ CPPUNIT_TEST_SUITE(TestTcpipServer);
22+ CPPUNIT_TEST(connectTest);
23+ CPPUNIT_TEST(timeoutTest);
24+ CPPUNIT_TEST_SUITE_END();
2525
2626 public:
27- void connectTest(void);
28- void timeoutTest(void);
27+ void connectTest(void);
28+ void timeoutTest(void);
2929 };
3030
3131 #endif /* !TEST_TCPIP_SERVER_H */
--- trunk/libs/connection/sdl/SdlNetInit.cpp (revision 1835)
+++ trunk/libs/connection/sdl/SdlNetInit.cpp (revision 1836)
@@ -16,7 +16,7 @@
1616
1717 struct SdlNetInit::pImpl : private SdlInit
1818 {
19- static bool initialized;
19+ static bool initialized;
2020 };
2121 bool SdlNetInit::pImpl::initialized = false;
2222
@@ -23,15 +23,15 @@
2323
2424 SdlNetInit::SdlNetInit(void) : pimpl(new pImpl)
2525 {
26- if (pimpl->initialized) {
27- return;
28- }
26+ if (pimpl->initialized) {
27+ return;
28+ }
2929
30- if (SDLNet_Init() < 0) {
31- return;
32- }
33- atexit(SDLNet_Quit);
34- pimpl->initialized = true;
30+ if (SDLNet_Init() < 0) {
31+ return;
32+ }
33+ atexit(SDLNet_Quit);
34+ pimpl->initialized = true;
3535 }
3636
3737
旧リポジトリブラウザで表示