00001 /**************************************************************************** 00002 * $Id: urbisend.cpp,v 1.6 2005/09/21 06:45:36 nottale Exp $ 00003 * 00004 * Sample urbi client that sends commands contained in a file. 00005 * 00006 * Copyright (C) 2004, 2006 Jean-Christophe Baillie. All rights reserved. 00007 * 00008 * This program is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU General Public License 00010 * as published by the Free Software Foundation; either version 2 00011 * of the License, or (at your option) any later version. 00012 * 00013 * This program is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with this program; if not, write to the Free Software 00020 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00021 **********************************************************************/ 00022 00023 00024 /* This is a trivial demonstration program that send commands contained in a file to an urbi server */ 00025 00026 #include "libport/cstdio" 00027 #include "urbi/uclient.hh" 00028 00029 urbi::UCallbackAction 00030 dump(const urbi::UMessage & msg) 00031 { 00032 // FIXME: This is absolutely not completely migrated. 00033 // To be finished -- Akim. 00034 switch (msg.type) 00035 { 00036 case urbi::MESSAGE_DATA: 00037 std::cerr << *msg.value << std::endl; 00038 break; 00039 00040 case urbi::MESSAGE_ERROR: 00041 case urbi::MESSAGE_SYSTEM: 00042 std::cerr << msg.timestamp << " " << msg.tag.c_str() << " " 00043 << msg.message.c_str() << std::endl; 00044 break; 00045 } 00046 return urbi::URBI_CONTINUE; 00047 } 00048 00049 00050 int main(int argc, char *argv[]) 00051 { 00052 if (argc != 3) 00053 { 00054 fprintf (stderr, 00055 "Missing file name\nUsage: urbisend robotname filename\n"); 00056 exit(1); 00057 } 00058 00059 urbi::UClient client (argv[1]); 00060 if (client.error()) 00061 exit(0); 00062 client.setWildcardCallback(callback(&dump)); 00063 client.sendFile(argv[2]); 00064 fprintf(stdout, "File sent, hit Ctrl-C to terminate.\n"); 00065 urbi::execute(); 00066 return 0; 00067 }