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 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 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 General Public License for more details.
00020 
00021     You should have received a copy of the GNU 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 _PHNETCAPTURE_H
00027 #define _PHNETCAPTURE_H
00028 
00029 /* ---------------------------------------------------------------------- */
00030 #include <phImage.h>
00031 #include <phImageCapture.h>
00032 #include <phSocket.h>
00033 
00034 /* ---------------------------------------------------------------------- */
00035 typedef struct phNetSourceInfo_t *phNetSourceInfo;
00036 
00037 #define phNetTypeUNKNOWN    0
00038 #define phNetTypeTCP        (1<<0)
00039 
00040 /* ---------------------------------------------------------------------- */
00041 class phNetSource : public phImageCapture
00042 {
00043 
00044 protected:
00045     phNetSourceInfo m_info;
00046 
00047     int         m_is_open;
00048 
00049     uint32_t    m_type;
00050     char        *m_temp_path;
00051 
00052     /* used when we connect to store how we should disconnect */
00053     uint32_t    m_connected_type;
00054 
00055     int         m_reconnect;
00056     int         m_server_wait;
00057 
00058     phMutex     m_orig_lock;
00059     uint32_t    m_orig_format;
00060     uint32_t    m_orig_height;
00061     uint32_t    m_orig_width;
00062     uint32_t    m_orig_size;
00063 
00064     /* used to resize/reformat incoming images to user defined output
00065      * values */
00066     uint32_t    m_user_dimensions;
00067    
00068     /* returns the host and port through pointers.
00069      * If the host memory is to be allocated, then (*host) 
00070      * should evaluate to be NULL. That is, the 'char *' being passed
00071      * should be initialized to NULL */
00072     int parsePath( const char *path, 
00073                    char **host, 
00074                    uint32_t *port, 
00075                    uint32_t *type );
00076    
00077     /* -------------------------------------------------------------------- */
00078     /* phNetTypeTCP */
00079     
00080     /* connect to the server; use m_server_wait to wait until the server
00081      * comes up. */
00082     int tcp_connect( phSocket   *comms,
00083                      bool       poll,
00084                      char       *host,
00085                      uint32_t   port,
00086                      uint32_t   *w,
00087                      uint32_t   *h,
00088                      uint32_t   *f,
00089                      char       **title );
00090 
00091     int tcp_init( phSocket     *comms,
00092                   char         **title, 
00093                   uint32_t     *w, 
00094                   uint32_t     *h, 
00095                   uint32_t     *f );
00096 
00097     int tcp_recv( phSocket     *comms,
00098                   phImage      *inputImage,
00099                   uint32_t     *w, 
00100                   uint32_t     *h, 
00101                   uint32_t     *f,
00102                   uint8_t      **data,
00103                   uint32_t     *data_size );
00104 
00105     /* disconnect from the server; reset any necessary information */
00106     int tcp_disconnect( phSocket *comms );
00107     /* -------------------------------------------------------------------- */
00108 
00109     /* on close, the class retains all previous knowledge
00110      * except the device capabilities. */
00111     virtual int open(char *path);
00112     virtual int close();
00113 
00114     int connect( bool poll = true );
00115     int recv(phImage *image,uint8_t **image_buf,uint32_t *image_size );
00116     int disconnect();
00117 
00118     /* phThread overloaded methods */
00119     virtual int run();
00120     virtual int cleanup();
00121     virtual int wakeup();
00122     
00123 public:
00124     phNetSource(char *path = NULL);
00125     ~phNetSource();
00126     
00127     static int makePath( const char  *host, 
00128                          uint32_t    port,
00129                          uint32_t    type,
00130                          char        **path );
00131    
00132     /* Set and get the host name of the server side */
00133     int         setHost( const char *host );
00134     const char  *getHost();
00135     
00136     /* Set and get the port of the server side */
00137     int         setPort( uint32_t port );
00138     uint32_t    getPort();
00139 
00140     const char *getTitle();
00141 
00142     /* This setting will reconnect if disconnected;
00143      * The default is always to reconnect. */
00144     int setReconnect( int reconnect );
00145     int getReconnect( );
00146 
00147     /* This setting will wait for the server to start up.
00148      * The default is to always wait. */
00149     int setServerWait( int wait );
00150     int getServerWait( );
00151 
00152     int      getOriginal(uint32_t *format, 
00153                          uint32_t *height,
00154                          uint32_t *width,
00155                          uint32_t *size );
00156     uint32_t getOriginalFormat();
00157     uint32_t getOriginalHeight();
00158     uint32_t getOriginalWidth();
00159     uint32_t getOriginalSize();
00160 
00161     /* will undo user defined dimension settings */
00162     int resetDimensions();
00163     
00164     /* Called when settings have changed using one of the phCaptureInterface 
00165      * or phImageCapture methods. Or on initialization. */
00166     virtual int onApplySettings();
00167 
00168     virtual int isOpen();
00169     int isConnected();
00170 };
00171 
00172 #endif /* _PHNETCAPTURE_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