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

configClientToServer.cpp

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 #include "Aria.h"
00027 #include "ArNetworking.h"
00028 
00029 /*
00030   Pass this a file to send to the server (should be made by configClient then modified).
00031 
00032   Takes a file to send, and can take the host to send to too
00033 
00034  */
00035 
00036 ArClientBase *client;
00037 ArClientHandlerConfig *configHandler;
00038 
00039 char *file;
00040 
00041 void saveConfigSucceeded(void)
00042 {
00043   printf("HERE: Save config succeeded\n");
00044 }
00045 
00046 void saveConfigFailed(const char *str)
00047 {
00048   printf("HERE: Save config failed: %s\n", str);
00049 }
00050 
00051 void gotConfig(void)
00052 {
00053   char errorBuffer[1024];
00054   ArConfig *newConfig;
00055   if (!configHandler->getConfig()->parseFile(file, false, false, errorBuffer,
00056                                              sizeof(errorBuffer)))
00057     printf("Error loading file: %s\n", errorBuffer);
00058   
00059   configHandler->saveConfigToServer();
00060   client->loopOnce();
00061   ArUtil::sleep(1000);
00062   client->loopOnce();
00063   ArUtil::sleep(1000);
00064   client->disconnect();
00065   Aria::shutdown();
00066   exit(0);
00067 }
00068 
00069 int main(int argc, char **argv)
00070 {
00071   Aria::init();
00072   //ArLog::init(ArLog::StdOut, ArLog::Verbose);
00073   ArGlobalFunctor gotConfigCB(&gotConfig);
00074   ArGlobalFunctor saveConfigSucceededCB(&saveConfigSucceeded);
00075   ArGlobalFunctor1<const char *> saveConfigFailedCB(&saveConfigFailed);
00076   std::string hostname;
00077 
00078   client = new ArClientBase;
00079   configHandler = new ArClientHandlerConfig(client, true);
00080 
00081   configHandler->addGotConfigCB(&gotConfigCB);
00082   configHandler->addSaveConfigSucceededCB(&saveConfigSucceededCB);
00083   configHandler->addSaveConfigFailedCB(&saveConfigFailedCB);
00084         
00085   if (argc == 1)
00086   {
00087     printf("Usage: %s <file> <host>\n", argv[0]);
00088     exit(1);
00089   }
00090   file = argv[1];
00091   if (argc == 2)
00092     hostname = "localhost";
00093   else
00094     hostname = argv[2];
00095 
00096   
00097   if (!client->blockingConnect(hostname.c_str(), 7272))
00098   {
00099     printf("Could not connect to server, exiting\n");
00100     exit(1);
00101   }
00102   //client->requestOnce("setConfig");
00103   configHandler->requestConfigFromServer();
00104   //client->requestOnce("setConfig");
00105   client->run();
00106   return 0;
00107 }

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