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

vos/corelibs/typechain/handlers/externaltypehandler.hh

Go to the documentation of this file.
00001 /* $Id: externaltypehandler.hh,v 1.6 2003/05/29 23:24:47 reed Exp $ */
00002 
00003 /** @file typehandler.hh    defines a basic type handler from which
00004     you may derive specific type handlers.
00005     @author Reed sept 2001
00006 */
00007 
00008 /*
00009     This file is part of the Virtual Object System of
00010     the Interreality project (http://interreality.org).
00011 
00012     Copyright (C) 2001, 2002 Reed Hedges <reed@zerohour.net>
00013 
00014     This library is free software; you can redistribute it and/or
00015     modify it under the terms of the GNU Lesser General Public
00016     License as published by the Free Software Foundation; either
00017     version 2 of the License, or (at your option) any later version.
00018 
00019     This library is distributed in the hope that it will be useful,
00020     but WITHOUT ANY WARRANTY; without even the implied warranty of
00021     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00022     Lesser General Public License for more details.
00023 
00024     You should have received a copy of the GNU Lesser General Public
00025     License along with this library; if not, write to the Free Software
00026     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00027 */
00028 
00029 #ifndef _EXTERNALTYPEHANDLER_HH_
00030 #define _EXTERNALTYPEHANDLER_HH_
00031 
00032 #include <string>
00033 #include <map>
00034 #include <stdio.h>
00035 #include "../typechain.hh"
00036 
00037 
00038 typedef map<string,string> TypeParams;
00039 
00040 
00041 /** This class calls an external program or "helper application" to decode
00042     stuff. The helper program must accept input data via standard input,
00043     and write to standard output.
00044     @bug    If there is an error running the external program, you will receve a SIGPIPE (Broken Pipe) signal.
00045     */
00046 class ExternalTypeHandler : public TypeHandler {
00047 
00048 private:
00049 
00050     char **decoder_command; // stores program name for deconding (element 0) and arguments  (0-terminated)
00051     char **encoder_command; // stores program name and arguments for encoding
00052     bool needtofreecommands;    // decoder_command and encoder_command were malloc'ed by the constructor, and need to be freed in the destructor
00053 
00054 
00055     /* private method for spawning child process and getting some file pointers to talk to it with. */
00056     int exec_child_io(char *cmd, char **argv, FILE **readpipe, FILE **writepipe);
00057 
00058     /* run external command command, pass data as stdin, return stdout. 
00059      * On Windows, a Null implementation.
00060      * On others, implemented as a wrapper around exec_child_io. 
00061      */
00062     void run_external(string& data, char **command) ;
00063 
00064 public:
00065 
00066     /** Constructor:  given a program name and arguments. data to decode is
00067         passed through given command with arguments: program name should be
00068         in decmd[0]. (PATH environment variable will be searched for program
00069         to run)
00070         @param decmd program name and arguments for decoding
00071         @param encmd program name and arguments for encoding
00072         @param file_ext "Filename extension" for this type.
00073     */
00074     ExternalTypeHandler(string name, char **decmd, char **encmd = 0, string file_ext = "?" );
00075 
00076     /** simpler version of ExternalTypeHandler(char *decmd[]);
00077         takes a program name with no arguments.
00078         @param decmd program for decoding.
00079         @param encmd program for encoding.
00080         @param file_ext Filename "extension" for this type.
00081     */
00082     ExternalTypeHandler(string name, char *decmd, char *encmd = 0, string file_ext = "?");
00083 
00084     /** Destructor. Frees internally allocated memory. */
00085     virtual ~ExternalTypeHandler();
00086 
00087 
00088     /** Call the external program to decode the data.
00089         @param data data to pass to external program to decode.
00090         @param params Map of parameters from type identifier.
00091         @return the new data.
00092 
00093     */
00094 
00095     virtual void decode(string& data, TypeParams& params) ;
00096 
00097     /** Call external program to encode data.
00098         @param data data to pass to external program to encode
00099         @param params parameters
00100         @return the new data.
00101     */
00102 
00103     virtual void encode(string& data, TypeParams& params);
00104 
00105 };
00106 
00107 
00108 
00109 
00110 #endif

Generated on Tue Aug 12 03:55:38 2003 for Interreality Project - VOS by doxygen 1.3.2