Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages | Examples

ArServerFileUtils.h

Go to the documentation of this file.
00001 /*
00002 MobileRobots Advanced Robotics Interface for Applications (ARIA)
00003 Copyright (C) 2004, 2005 ActivMedia Robotics LLC
00004 Copyright (C) 2006, 2007 MobileRobots Inc.
00005 
00006      This program is free software; you can redistribute it and/or modify
00007      it under the terms of the GNU General Public License as published by
00008      the Free Software Foundation; either version 2 of the License, or
00009      (at your option) any later version.
00010 
00011      This program is distributed in the hope that it will be useful,
00012      but WITHOUT ANY WARRANTY; without even the implied warranty of
00013      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014      GNU General Public License for more details.
00015 
00016      You should have received a copy of the GNU General Public License
00017      along with this program; if not, write to the Free Software
00018      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00020 If you wish to redistribute ARIA under different terms, contact 
00021 MobileRobots for information about a commercial version of ARIA at 
00022 robots@mobilerobots.com or 
00023 MobileRobots Inc, 19 Columbia Drive, Amherst, NH 03031; 800-639-9481
00024 */
00025 
00026 #ifndef ARSERVERFILEUTILS_H
00027 #define ARSERVERFILEUTILS_H
00028 
00029 #include "Aria.h"
00030 #include "ArServerBase.h"
00031 
00034 
00035 class ArServerFileUtil
00036 {
00037 public:
00039   AREXPORT static bool squashCase(const char *baseDir, const char *fileName, 
00040                            char * result, size_t resultLen);
00042   AREXPORT static bool getDirectory(const char *fileName, 
00043                                      char * result, size_t resultLen);
00045   AREXPORT static bool getFileName(const char *fileName, 
00046                                      char * result, size_t resultLen);
00047 
00048 protected:
00050   static std::list<std::string> splitFileName(const char *fileName);
00051 
00052 };
00053 
00055 
00066 class ArServerFileLister
00067 {
00068 public:
00070   AREXPORT ArServerFileLister(ArServerBase *server, const char *topDir);
00072   AREXPORT virtual ~ArServerFileLister();
00074   AREXPORT void getDirListing(ArServerClient *client,
00075                               ArNetPacket *packet);
00076 protected:
00077   char myBaseDir[2048];
00078   ArServerBase *myServer;
00079   ArFunctor2C<ArServerFileLister, ArServerClient *, 
00080       ArNetPacket *> myGetDirListingCB;
00081 };
00082 
00083 
00085 
00095 class ArServerFileToClient
00096 {
00097 public:
00099   AREXPORT ArServerFileToClient(ArServerBase *server, const char *topDir);
00101   AREXPORT virtual ~ArServerFileToClient();
00103   AREXPORT void getFile(ArServerClient *client,
00104                         ArNetPacket *packet);
00105 protected:
00106   
00107   char myBaseDir[2048];
00108   ArServerBase *myServer;
00109   ArFunctor2C<ArServerFileToClient, ArServerClient *, 
00110       ArNetPacket *> myGetFileCB;
00111 };
00112 
00114 
00126 class ArServerFileFromClient
00127 {
00128 public:
00130   AREXPORT ArServerFileFromClient(ArServerBase *server, const char *topDir, 
00131                                   const char *tempDir);
00133   AREXPORT virtual ~ArServerFileFromClient();
00135   AREXPORT void putFile(ArServerClient *client, ArNetPacket *packet);
00137   AREXPORT void putFileInterleaved(ArServerClient *client, 
00138                                    ArNetPacket *packet);
00139 
00141   AREXPORT void addPreMoveCallback(
00142           ArFunctor *functor, ArListPos::Pos position = ArListPos::LAST);
00144   AREXPORT void remPreMoveCallback(ArFunctor *functor);
00146   AREXPORT void addPostMoveCallback(
00147           ArFunctor *functor, ArListPos::Pos position = ArListPos::LAST);
00149   AREXPORT void remPostMoveCallback(ArFunctor *functor);  
00151   const char *getMovingFileName(void) { return myMovingFileName.c_str(); }
00152 protected:
00153   AREXPORT void internalPutFile(ArServerClient *client, ArNetPacket *packet,
00154                                 bool interleaved);
00155   char myBaseDir[2048];
00156   char myTempDir[2048];
00157   ArServerBase *myServer;
00158   std::list<ArFunctor *> myPreMoveCallbacks;
00159   std::list<ArFunctor *> myPostMoveCallbacks;
00160   ArFunctor2C<ArServerFileFromClient, ArServerClient *, 
00161       ArNetPacket *> myPutFileCB;
00162   ArFunctor2C<ArServerFileFromClient, ArServerClient *, 
00163       ArNetPacket *> myPutFileInterleavedCB;
00164 
00165   std::string myMovingFileName;
00166 
00167   int myFileNumber;
00168   class FileInfo
00169   {
00170   public:
00171     FileInfo() { myFile = NULL; }
00172     virtual ~FileInfo() {}
00173     std::string myRealFileName;
00174     std::string myTempFileName;
00175     FILE *myFile;
00176     ArTime myStartedTransfer;
00177     ArTime myLastActivity;
00178   };
00179   // map of raw filenames to FileInfo (so we don't have to walk it all the time)
00180   std::map<std::string, FileInfo *> myMap;
00181 };
00182 
00183 
00185 
00195 class ArServerDeleteFileOnServer
00196 {
00197 public:
00199   AREXPORT ArServerDeleteFileOnServer(ArServerBase *server, 
00200                                       const char *topDir);
00202   AREXPORT virtual ~ArServerDeleteFileOnServer();
00204   AREXPORT void deleteFile(ArServerClient *client,
00205                            ArNetPacket *packet);
00207   AREXPORT void addPreDeleteCallback(
00208           ArFunctor *functor, ArListPos::Pos position = ArListPos::LAST);
00210   AREXPORT void remPreDeleteCallback(ArFunctor *functor);
00212   AREXPORT void addPostDeleteCallback(
00213           ArFunctor *functor, ArListPos::Pos position = ArListPos::LAST);
00215   AREXPORT void remPostDeleteCallback(ArFunctor *functor);  
00217   const char *getDeletingFileName(void) { return myDeletingFileName.c_str(); }
00218 protected:
00219   char myBaseDir[2048];
00220   ArServerBase *myServer;
00221   ArFunctor2C<ArServerDeleteFileOnServer, ArServerClient *, 
00222       ArNetPacket *> myDeleteFileCB;
00223   std::string myDeletingFileName;
00224   std::list<ArFunctor *> myPreDeleteCallbacks;
00225   std::list<ArFunctor *> myPostDeleteCallbacks;
00226 
00227 };
00228 
00229 #endif // ARSERVERFILEUTILS_H

Generated on Tue Feb 20 10:51:50 2007 for ArNetworking by  doxygen 1.4.0