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 <fvutils/net/fuse.h>
28 #include <core/threading/thread.h>
29 #include <sys/types.h>
30 
31 namespace fawkes {
32  class StreamSocket;
33  class WaitCondition;
34  class Mutex;
35 }
36 namespace firevision {
37 #if 0 /* just to make Emacs auto-indent happy */
38 }
39 #endif
40 
41 class FuseNetworkMessageQueue;
42 class FuseNetworkMessage;
43 class FuseClientHandler;
44 
45 class FuseClient : public fawkes::Thread {
46  public:
47  FuseClient(const char *hostname, unsigned short int port,
48  FuseClientHandler *handler);
49  virtual ~FuseClient();
50 
51  void connect();
52  void disconnect();
53 
54  void enqueue(FuseNetworkMessage *m);
55  void enqueue(FUSE_message_type_t type, void *payload, size_t payload_size);
56  void enqueue(FUSE_message_type_t type);
57  void enqueue_and_wait(FuseNetworkMessage *message);
58  void enqueue_and_wait(FUSE_message_type_t type, void *payload, size_t payload_size);
59  void enqueue_and_wait(FUSE_message_type_t type);
60  void wait();
61  void wait_greeting();
62 
63  virtual void loop();
64 
65  private:
66  void send();
67  void recv();
68  void sleep();
69 
70  char *__hostname;
71  unsigned short int __port;
72 
73  fawkes::StreamSocket *__socket;
74  unsigned int __wait_timeout;
75 
76  fawkes::Mutex *__mutex;
77  fawkes::Mutex *__recv_mutex;
78  fawkes::WaitCondition *__recv_waitcond;
79 
80  FuseNetworkMessageQueue * __inbound_msgq;
81  FuseNetworkMessageQueue * __outbound_msgq;
82 
83  FuseClientHandler *__handler;
84 
85  bool __greeting_received;
86  fawkes::Mutex *__greeting_mutex;
87  fawkes::WaitCondition *__greeting_waitcond;
88 
89  bool __alive;
90 };
91 
92 } // end namespace firevision
93 
94 #endif
Wait until a given condition holds.
Fawkes library namespace.
Thread class encapsulation of pthreads.
Definition: thread.h:42
TCP stream socket over IP.
Definition: stream.h:31
FUSE Network Message.
Definition: fuse_message.h:41
A LockQueue of FuseNetworkMessage to hold messages in inbound and outbound queues.
Mutex mutual exclusion lock.
Definition: mutex.h:32