24 #include <core/exceptions/software.h>
25 #include <core/threading/mutex.h>
26 #include <core/threading/wait_condition.h>
27 #include <fvutils/net/fuse_client.h>
28 #include <fvutils/net/fuse_client_handler.h>
29 #include <fvutils/net/fuse_message.h>
30 #include <fvutils/net/fuse_message_queue.h>
31 #include <fvutils/net/fuse_transceiver.h>
32 #include <netcomm/socket/stream.h>
33 #include <netcomm/utils/exceptions.h>
34 #include <netinet/in.h>
42 namespace firevision {
59 FuseClient::FuseClient(
const char *hostname,
unsigned short int port,
FuseClientHandler *handler)
62 hostname_ = strdup(hostname);
72 recv_mutex_ =
new Mutex();
75 greeting_mutex_ =
new Mutex();
79 greeting_received_ =
false;
87 while (!inbound_msgq_->empty()) {
94 while (!outbound_msgq_->empty()) {
97 outbound_msgq_->pop();
99 delete outbound_msgq_;
103 delete recv_waitcond_;
105 delete greeting_mutex_;
106 delete greeting_waitcond_;
113 socket_->
connect(hostname_, port_);
117 greetmsg->
version = htonl(FUSE_CURRENT_VERSION);
118 outbound_msgq_->push(
211 recv_waitcond_->
wait();
227 recv_waitcond_->
wait();
241 recv_waitcond_->
wait();
254 socket_->
poll(wait_timeout_ , Socket::POLL_IN);
281 inbound_msgq_->
lock();
282 while (!inbound_msgq_->empty()) {
285 if (m->
type() == FUSE_MT_GREETING) {
287 if (ntohl(gm->
version) != FUSE_CURRENT_VERSION) {
291 greeting_mutex_->
lock();
292 greeting_received_ =
true;
294 greeting_mutex_->
unlock();
303 inbound_msgq_->pop();
321 recv_waitcond_->
wait();
335 greeting_mutex_->
lock();
336 while (!greeting_received_) {
337 greeting_waitcond_->
wait();
339 greeting_mutex_->
unlock();