COOPY » Guide  version 0.6.5
/home/paulfitz/cvs/coopy_scm/coopy/src/sslive/sslive.cpp
Go to the documentation of this file.
00001 
00002 #include <stdio.h>
00003 #include <getopt.h>
00004 
00005 #include <coopy/PolyBook.h>
00006 #include <coopy/CsvFile.h>
00007 #include <coopy/CsvTextBook.h>
00008 #include <coopy/PatchParser.h>
00009 #include <coopy/SheetPatcher.h>
00010 #include <coopy/Dbg.h>
00011 
00012 #include <yarp/os/Port.h>
00013 #include <yarp/os/Bottle.h>
00014 #include <yarp/os/Network.h>
00015 
00016 using namespace coopy::store;
00017 using namespace coopy::cmp;
00018 using namespace coopy::format;
00019 
00020 using namespace yarp::os;
00021 
00022 using namespace std;
00023 
00024 int main(int argc, char *argv[]) {
00025   bool verbose = false;
00026   bool help = false;
00027   string formatName = "apply";
00028   string cmd = "";
00029   while (true) {
00030     int option_index = 0;
00031     static struct option long_options[] = {
00032       {"verbose", 0, 0, 'v'},
00033       {"help", 0, 0, 'h'},
00034       {"format", 1, 0, 'f'},
00035       {0, 0, 0, 0}
00036     };
00037 
00038     int c = getopt_long(argc, argv, "",
00039                         long_options, &option_index);
00040     if (c==-1) break;
00041     switch (c) {
00042     case 'v':
00043       verbose = true;
00044       break;
00045     case 'h':
00046       help = true;
00047       break;
00048     case 'f':
00049       formatName = optarg;
00050       break;
00051     default:
00052       fprintf(stderr, "Unrecognized option\n");
00053       return 1;
00054     }
00055   }
00056 
00057   if (optind<argc-1) {
00058     fprintf(stderr, "Options not understood\n");
00059     return 1;
00060   }
00061   argc -= optind;
00062   argv += optind;
00063   if (argc<1 || help) {
00064     printf("Welcome to sslive!\n");
00065     printf("It serves to useful purpose just yet.\n");
00066     printf("It may grow to support a rsync-like protocol.\n");
00067     return 1;
00068   }
00069 
00070   const char *local_name = argv[0];
00071 
00072   PolyBook obook;
00073   if (!obook.attach(local_name)) {
00074     return 1;
00075   }
00076 
00077   Network yarp;
00078   Port p;
00079   p.open("/sslive");
00080   while (true) {
00081     Bottle b;
00082     if (!p.read(b,true)) break;
00083     printf("Got %s\n", b.toString().c_str());
00084     Bottle reply;
00085     ConstString cmd = b.get(0).asString();
00086     if (cmd=="get") {
00087       PolySheet sheet = obook.readSheetByIndex(0);
00088       if (sheet.isValid()) {
00089         int x = b.get(1).asInt();
00090         int y = b.get(2).asInt();
00091         if (x<0 || 
00092             y<0 ||
00093             x >= sheet.width() || 
00094             y>=sheet.height()) {
00095             reply.addString("None");
00096           } else {
00097             SheetCell result = sheet.cellSummary(x,y);
00098             reply.addString(result.toString().c_str());
00099         }
00100       } else {
00101         reply.addString("None");
00102       }
00103     } else if (cmd=="SELECT"||cmd=="Select"||cmd=="select") {
00104       reply.addString("No SQL - if you want SQL, use an SQL database");
00105     }
00106 
00107     printf("Reply %s\n", reply.toString().c_str());
00108     p.reply(reply);
00109   }
00110   
00111   return 0;
00112 }
00113 
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines