Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

phNetSource.h

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------
00002     Phission : 
00003         Realtime Vision Processing System
00004     
00005     Copyright (C) 2003-2006 Philip D.S. Thoren (pthoren@cs.uml.edu)
00006     University of Massachusetts at Lowell,
00007     Laboratory for Artificial Intelligence and Robotics
00008     
00009     This file is part of Phission.
00010 
00011     Phission is free software; you can redistribute it and/or modify
00012     it under the terms of the GNU Lesser General Public License as published by
00013     the Free Software Foundation; either version 2 of the License, or
00014     (at your option) any later version.
00015 
00016     Phission 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 Lesser General Public License for more details.
00020 
00021     You should have received a copy of the GNU Lesser General Public License
00022     along with Phission; if not, write to the Free Software
00023     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024 
00025  ---------------------------------------------------------------------------*/
00026 #ifndef _PHNETSOURCE_H
00027 #define _PHNETSOURCE_H
00028 
00029 /* ---------------------------------------------------------------------- */
00030 #include <phImageCapture.h>
00031 class phImage;
00032 class phSocket;
00033 
00034 /* ---------------------------------------------------------------------- */
00040 /* ---------------------------------------------------------------------- */
00041 typedef struct phNetSourceInfo_t *phNetSourceInfo;
00042 
00043 #define phNetTypeUNKNOWN    0
00044 #define phNetTypeTCP        (1<<0)
00045  /* end \addtogroup Capture */
00047 
00048 /* ---------------------------------------------------------------------- */
00054 PHAPI(class) phNetSource : public phImageCapture
00055 {
00056 
00057 protected:
00058     phNetSourceInfo m_info;
00059 
00060     int         m_is_open;
00061 
00062     uint32_t    m_type;
00063     char        *m_temp_path;
00064 
00065     /* used when we connect to store how we should disconnect */
00066     uint32_t    m_connected_type;
00067 
00068     int         m_reconnect;
00069     int         m_server_wait;
00070 
00071     phMutex     m_orig_lock;
00072     uint32_t    m_orig_format;
00073     uint32_t    m_orig_height;
00074     uint32_t    m_orig_width;
00075     uint32_t    m_orig_size;
00076 
00077     /*
00078      * Returns the host and port through pointers.
00079      * If the host memory is to be allocated, then (*host) 
00080      * should evaluate to be NULL. That is, the 'char *' being passed
00081      * should be initialized to NULL 
00082      */
00083     int parsePath( const char  *path, 
00084                    char       **host, 
00085                    uint32_t    *port, 
00086                    uint32_t    *type );
00087    
00088     /* -------------------------------------------------------------------- */
00089     /* phNetTypeTCP */
00090     
00091     /* connect to the server; use m_server_wait to wait until the server
00092      * comes up. */
00093     int tcp_connect( phSocket   *comms,
00094                      bool       poll,
00095                      char       *host,
00096                      uint32_t   port,
00097                      uint32_t   *w,
00098                      uint32_t   *h,
00099                      uint32_t   *f,
00100                      char       **title );
00101 
00102     int tcp_init( phSocket     *comms,
00103                   char         **title, 
00104                   uint32_t     *w, 
00105                   uint32_t     *h, 
00106                   uint32_t     *f );
00107 
00108     int tcp_recv( phSocket     *comms,
00109                   phImage      *inputImage,
00110                   uint32_t     *w, 
00111                   uint32_t     *h, 
00112                   uint32_t     *f,
00113                   uint8_t      **data,
00114                   uint32_t     *data_size );
00115 
00116     /* disconnect from the server; reset any necessary information */
00117     int tcp_disconnect( phSocket *comms );
00118     /* -------------------------------------------------------------------- */
00119 
00120     /* on close, the class retains all previous knowledge
00121      * except the device capabilities. */
00122     virtual int open(char *path);
00123     virtual int close();
00124 
00125     int connect     ( bool      poll = true );
00126     int getNextFrame( phImage  *image,
00127                       uint8_t **image_buf,
00128                       uint32_t *image_size );
00129     int disconnect  ();
00130 
00131     /* phThread overloaded methods */
00132     virtual int run     ();
00133     virtual int cleanup ();
00134     virtual int wakeup  ();
00135     
00136 public:
00137     phNetSource( char *path = NULL );
00138     ~phNetSource();
00139     
00140     static int makePath( const char *host, 
00141                          uint32_t    port,
00142                          uint32_t    type,
00143                          char      **path );
00144    
00145     /* Set and get the host name of the server side */
00146     int         setHost ( const char *host );
00147     const char  *getHost();
00148     
00149     /* Set and get the port of the server side */
00150     int         setPort( uint32_t port );
00151     uint32_t    getPort();
00152 
00153     const char *getTitle();
00154 
00155     /* This setting will reconnect if disconnected;
00156      * The default is always to reconnect. */
00157     int setReconnect( int reconnect );
00158     int getReconnect( );
00159 
00160     /* This setting will wait for the server to start up.
00161      * The default is to always wait. */
00162     int setServerWait( int wait );
00163     int getServerWait( );
00164 
00172     int      setOriginal();
00179     int      setOriginalSize();
00185     int      setOriginalFormat();
00186     
00187     int      getOriginal( uint32_t *format, 
00188                           uint32_t *height,
00189                           uint32_t *width,
00190                           uint32_t *size );
00191     uint32_t getOriginalFormat  ();
00192     uint32_t getOriginalHeight  ();
00193     uint32_t getOriginalWidth   ();
00194     uint32_t getOriginalSize    ();
00195 
00196     /* will undo user defined dimension settings */
00197     int resetDimensions();
00198     
00199     /* Called when settings have changed using one of the phCaptureInterface 
00200      * or phImageCapture methods. Or on initialization. */
00201     virtual int onApplySettings();
00202 
00203     virtual int isOpen();
00204     int         isConnected();
00205 };
00206 
00207 #endif /* _PHNETSOURCE_H */




Copyright (C) 2002 - 2007 Philip D.S. Thoren ( pthoren@users.sourceforge.net )
University Of Massachusetts at Lowell
Robotics Lab
SourceForge.net Logo

Generated on Sat Jun 16 02:44:03 2007 for phission by  doxygen 1.4.4