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 class FuseNetworkMessageQueue;
00037 class FuseNetworkMessage;
00038 class FuseClientHandler;
00039
00040 class FuseClient : public fawkes::Thread {
00041  public:
00042   FuseClient(const char *hostname, unsigned short int port,
00043              FuseClientHandler *handler);
00044   virtual ~FuseClient();
00045
00046   void connect();
00047   void disconnect();
00048
00049   void enqueue(FuseNetworkMessage *m);
00050   void enqueue(FUSE_message_type_t type, void *payload, size_t payload_size);
00051   void enqueue(FUSE_message_type_t type);
00052   void enqueue_and_wait(FuseNetworkMessage *message);
00053   void enqueue_and_wait(FUSE_message_type_t type, void *payload, size_t payload_size);
00054   void enqueue_and_wait(FUSE_message_type_t type);
00055   void wait();
00056   void wait_greeting();
00057
00058   virtual void loop();
00059
00060  private:
00061   void send();
00062   void recv();
00063   void sleep();
00064
00065   char *__hostname;
00066   unsigned short int __port;
00067
00068   fawkes::StreamSocket *__socket;
00069   unsigned int __wait_timeout;
00070
00071   fawkes::Mutex         *__mutex;
00072   fawkes::Mutex         *__recv_mutex;
00073   fawkes::WaitCondition *__recv_waitcond;
00074
00075   FuseNetworkMessageQueue *  __inbound_msgq;
00076   FuseNetworkMessageQueue *  __outbound_msgq;
00077
00078   FuseClientHandler       *__handler;
00079
00080   bool __greeting_received;
00081   fawkes::Mutex         *__greeting_mutex;
00082   fawkes::WaitCondition *__greeting_waitcond;
00083
00084   bool __alive;
00085 };
00086
00087
00088 #endif