Fawkes API  Fawkes Development Version
fuse_client.h
1 
2 /***************************************************************************
3  * fuse_client.h - FUSE network transport client
4  *
5  * Created: Mon Jan 09 15:33:59 2006
6  * Copyright 2005-2007 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #ifndef _FIREVISION_FVUTILS_NET_FUSE_CLIENT_H_
25 #define _FIREVISION_FVUTILS_NET_FUSE_CLIENT_H_
26 
27 #include <core/threading/thread.h>
28 #include <fvutils/net/fuse.h>
29 #include <sys/types.h>
30 
31 namespace fawkes {
32 class StreamSocket;
33 class WaitCondition;
34 class Mutex;
35 } // namespace fawkes
36 namespace firevision {
37 
38 class FuseNetworkMessageQueue;
39 class FuseNetworkMessage;
40 class FuseClientHandler;
41 
42 class FuseClient : public fawkes::Thread
43 {
44 public:
45  FuseClient(const char *hostname, unsigned short int port, FuseClientHandler *handler);
46  virtual ~FuseClient();
47 
48  void connect();
49  void disconnect();
50 
51  void enqueue(FuseNetworkMessage *m);
52  void enqueue(FUSE_message_type_t type, void *payload, size_t payload_size);
53  void enqueue(FUSE_message_type_t type);
54  void enqueue_and_wait(FuseNetworkMessage *message);
55  void enqueue_and_wait(FUSE_message_type_t type, void *payload, size_t payload_size);
56  void enqueue_and_wait(FUSE_message_type_t type);
57  void wait();
58  void wait_greeting();
59 
60  virtual void loop();
61 
62 private:
63  void send();
64  void recv();
65  void sleep();
66 
67  char * hostname_;
68  unsigned short int port_;
69 
70  fawkes::StreamSocket *socket_;
71  unsigned int wait_timeout_;
72 
73  fawkes::Mutex * mutex_;
74  fawkes::Mutex * recv_mutex_;
75  fawkes::WaitCondition *recv_waitcond_;
76 
77  FuseNetworkMessageQueue *inbound_msgq_;
78  FuseNetworkMessageQueue *outbound_msgq_;
79 
80  FuseClientHandler *handler_;
81 
82  bool greeting_received_;
83  fawkes::Mutex * greeting_mutex_;
84  fawkes::WaitCondition *greeting_waitcond_;
85 
86  bool alive_;
87 };
88 
89 } // end namespace firevision
90 
91 #endif
void connect()
Connect.
Wait until a given condition holds.
void enqueue_and_wait(FuseNetworkMessage *message)
Enqueue message and wait for reply.
void disconnect()
Disconnect.
Fawkes library namespace.
void enqueue(FuseNetworkMessage *m)
Enqueue message.
Thread class encapsulation of pthreads.
Definition: thread.h:45
TCP stream socket over IP.
Definition: stream.h:31
void wait()
Wait for messages.
FUSE Network Message.
Definition: fuse_message.h:39
A LockQueue of FuseNetworkMessage to hold messages in inbound and outbound queues.
FuseClient(const char *hostname, unsigned short int port, FuseClientHandler *handler)
Constructor.
Definition: fuse_client.cpp:59
virtual ~FuseClient()
Destructor.
Definition: fuse_client.cpp:83
virtual void loop()
Thread loop.
void wait_greeting()
Wait for greeting message.
Mutex mutual exclusion lock.
Definition: mutex.h:32