Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   Related Pages  

server.hh

00001 /*
00002  * PIAVE - PIAVE Is A Video Editor
00003  *
00004  * Copyright (C) 2002 Rolf Dubitzky, rolf@dubitzky.de
00005  *
00006  * This class is based in the nullcutter.cc example from
00007  * kdenlive by Jason Wood
00008  *
00009  */
00010 
00011 /*
00012  * This program is free software; you can redistribute it and/or modify
00013  * it under the terms of the GNU General Public License as published by
00014  * the Free Software Foundation; either version 2 of the License, or
00015  * (at your option) any later version.
00016  *
00017  * This program is distributed in the hope that it will be useful,
00018  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  * GNU General Public License for more details.
00021  *
00022  * You should have received a copy of the GNU General Public License
00023  * along with this program; if not, write to the Free Software Foundation,
00024  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00025  */
00026 
00027 #if ! defined ( SERVER_HH )
00028 #define SERVER_HH
00029 
00030 // std
00031 #include <sys/types.h>
00032 #include <sys/socket.h>
00033 #include <netinet/in.h>
00034 #include <arpa/inet.h>
00035 #include <unistd.h>
00036 
00037 // std++
00038 #include <iostream>
00039 #include <string>
00040 
00041 // piave
00042 #include "libpiave/piave_base.hh"
00043 #include "libpiave/storybase.hh"
00044 
00045 
00046 namespace PIAVE {
00047 
00069     class Server
00070     {
00071       public:
00072         enum State { 
00073             state_not_initialized, 
00074             state_not_connected, 
00075             state_error_connecting,
00076             state_connected, 
00077             state_process_commands, 
00078             state_shutting_down 
00079         };
00080 
00081       public: 
00082         Server( unsigned short port );
00083         virtual ~Server();
00087         int execute();
00088         
00091         void sendMessage( const std::string & str );
00092         int receiveMessage( std::string & str );
00093 
00094       protected:
00097         virtual void startProcessCommandsLoop() = 0;
00098         void setState( State state ) { _state = state; }
00099         State getState() const { return _state; };
00100 
00101       private: // Private methods
00103         void initListenSocket();
00105         void closeListenSocket();
00107         void closeCommSocket();
00108         
00109       private: 
00111         State _state;
00112 
00113 
00115         unsigned short m_port;
00117         int m_listenSocket;
00119         int m_commSocket;
00121         sockaddr_in m_socketAddress;
00123         std::string m_commandBuffer;
00124         
00127         int m_totalBytesRead;
00128 
00130         std::string m_messageBuffer;
00131 
00132         static std::string whitespace;
00133       public:
00134         static Server * Inst;
00135         static void cleanup_at_exit();
00136     };
00137 
00138 };
00139 
00140 #endif

Generated on Tue Oct 14 20:45:37 2003 for piave by doxygen1.2.18