Fawkes API  Fawkes Development Version
fuse_client.h
00001 
00002 /***************************************************************************
00003  *  fuse_client.h - FUSE network transport client
00004  *
00005  *  Created: Mon Jan 09 15:33:59 2006
00006  *  Copyright  2005-2007  Tim Niemueller [www.niemueller.de]
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023 
00024 #ifndef __FIREVISION_FVUTILS_NET_FUSE_CLIENT_H_
00025 #define __FIREVISION_FVUTILS_NET_FUSE_CLIENT_H_
00026 
00027 #include <fvutils/net/fuse.h>
00028 #include <core/threading/thread.h>
00029 #include <sys/types.h>
00030 
00031 namespace fawkes {
00032   class StreamSocket;
00033   class WaitCondition;
00034   class Mutex;
00035 }
00036 namespace firevision {
00037 #if 0 /* just to make Emacs auto-indent happy */
00038 }
00039 #endif
00040 
00041 class FuseNetworkMessageQueue;
00042 class FuseNetworkMessage;
00043 class FuseClientHandler;
00044 
00045 class FuseClient : public fawkes::Thread {
00046  public:
00047   FuseClient(const char *hostname, unsigned short int port,
00048              FuseClientHandler *handler);
00049   virtual ~FuseClient();
00050 
00051   void connect();
00052   void disconnect();
00053 
00054   void enqueue(FuseNetworkMessage *m);
00055   void enqueue(FUSE_message_type_t type, void *payload, size_t payload_size);
00056   void enqueue(FUSE_message_type_t type);
00057   void enqueue_and_wait(FuseNetworkMessage *message);
00058   void enqueue_and_wait(FUSE_message_type_t type, void *payload, size_t payload_size);
00059   void enqueue_and_wait(FUSE_message_type_t type);
00060   void wait();
00061   void wait_greeting();
00062 
00063   virtual void loop();
00064 
00065  private:
00066   void send();
00067   void recv();
00068   void sleep();
00069 
00070   char *__hostname;
00071   unsigned short int __port;
00072 
00073   fawkes::StreamSocket *__socket;
00074   unsigned int __wait_timeout;
00075 
00076   fawkes::Mutex         *__mutex;
00077   fawkes::Mutex         *__recv_mutex;
00078   fawkes::WaitCondition *__recv_waitcond;
00079 
00080   FuseNetworkMessageQueue *  __inbound_msgq;
00081   FuseNetworkMessageQueue *  __outbound_msgq;
00082 
00083   FuseClientHandler       *__handler;
00084 
00085   bool __greeting_received;
00086   fawkes::Mutex         *__greeting_mutex;
00087   fawkes::WaitCondition *__greeting_waitcond;
00088 
00089   bool __alive;
00090 };
00091 
00092 } // end namespace firevision
00093 
00094 #endif