Changeset 10347


Ignore:
Timestamp:
Apr 10, 2011, 10:24:08 AM (10 years ago)
Author:
tbretz
Message:
Removed printing of command list from constructor; added help2man conform help-output.
Location:
trunk/FACT++/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/dclient5.cc

    r10292 r10347  
    267267
    268268        AddTransition(kSM_SetUrl, "SETURL", "C");
    269 
    270         T::PrintListOfEvents();
    271269    }
    272270
     
    498496}
    499497
     498/*
     499 Extract usage clause(s) [if any] for SYNOPSIS.
     500 Translators: "Usage" and "or" here are patterns (regular expressions) which
     501 are used to match the usage synopsis in program output.  An example from cp
     502 (GNU coreutils) which contains both strings:
     503  Usage: cp [OPTION]... [-T] SOURCE DEST
     504    or:  cp [OPTION]... SOURCE... DIRECTORY
     505    or:  cp [OPTION]... -t DIRECTORY SOURCE...
     506 */
     507void PrintUsage()
     508{
     509    cout << "\n"
     510        "The console connects to all available Dim Servers and allows to "
     511        "easily access all of their commands.\n"
     512        "\n"
     513        "Usage: test3 [-c type] [OPTIONS]\n"
     514        "  or:  test3 [OPTIONS]\n"
     515        "\n"
     516        "Options:\n"
     517        "The following describes the available commandline options. "
     518        "For further details on how command line option are parsed "
     519        "and in which order which configuration sources are accessed "
     520        "please refer to the class reference of the Configuration class.";
     521    cout << endl;
     522
     523}
     524
     525void PrintHelp()
     526{
     527    cout << "\n"
     528        "The default is that the program is started without user interaction. "
     529        "All actions are supposed to arrive as DimCommands. Using the -c "
     530        "option, a local shell can be initialized. With h or help a short "
     531        "help message about the usuage can be brought to the screen."
     532        << endl;
     533
     534    /*
     535     cout << "bla bla bla" << endl << endl;
     536     cout << endl;
     537     cout << "Environment:" << endl;
     538     cout << "environment" << endl;
     539     cout << endl;
     540     cout << "Examples:" << endl;
     541     cout << "test exam" << endl;
     542     cout << endl;
     543     cout << "Files:" << endl;
     544     cout << "files" << endl;
     545     cout << endl;
     546     */
     547}
     548
     549/*
     550 The first line of the --version information is assumed to be in one
     551 of the following formats:
     552
     553   <version>
     554   <program> <version>
     555   {GNU,Free} <program> <version>
     556   <program> ({GNU,Free} <package>) <version>
     557   <program> - {GNU,Free} <package> <version>
     558
     559 and separated from any copyright/author details by a blank line.
     560
     561 Handle multi-line bug reporting sections of the form:
     562
     563   Report <program> bugs to <addr>
     564   GNU <package> home page: <url>
     565   ...
     566*/
     567void PrintVersion(const char *name)
     568{
     569    cout <<
     570        name << " - FACT++ 1.0\n"
     571        "\n"
     572        "Written by Thomas Bretz <thomas.bretz@epfl.ch> et al.\n"
     573        "\n"
     574        "Report bugs to Thomas Bretz <thomas.bretz@epfl.ch>\n"
     575        "FACT++ home page: http://www.xxx.com\n"
     576        "\n"
     577        "Copyright (C) 2011 by the FACT Collaboration.\n"
     578        "This is free software; see the source for copying conditions.\n"
     579        << endl;
     580}
     581
     582
    500583void SetupConfiguration(Configuration &conf)
    501584{
     
    518601{
    519602    Configuration conf(argv[0]);
     603    conf.SetPrintUsage(PrintUsage);
    520604    SetupConfiguration(conf);
    521605
     
    539623    }
    540624
    541     if (conf.HasHelp() || conf.HasPrint())
     625    if (conf.HasPrint())
    542626        return -1;
     627
     628    if (conf.HasVersion())
     629    {
     630        PrintVersion(argv[0]);
     631        return -1;
     632    }
     633
     634    if (conf.HasHelp())
     635    {
     636        PrintHelp();
     637        return -1;
     638    }
    543639
    544640    // To allow overwriting of DIM_DNS_NODE set 0 to 1
  • trunk/FACT++/src/logtime.cc

    r10183 r10347  
    66#include <iostream>
    77
     8class DimDescriptionService
     9{
     10    static int         fCount;
     11    static DimService *fService;
     12    static std::string fFormat;
     13
     14    std::string fFmt;
     15
     16public:
     17    DimDescriptionService(const std::string &name, const std::string &format)
     18    {
     19        // FIXME: throw is DimServer::itsName==0
     20
     21        std::string n = std::string(DimServer::itsName)+"/SERVICE_DESC";
     22
     23        if (!fService)
     24            fService = new DimService(n.c_str(), const_cast<char*>(""));
     25
     26        fCount++;
     27
     28        fFmt = name + '=' + format + '\n';
     29
     30        if (fFormat.find(fFmt)!=std::string::npos)
     31            return;
     32
     33        fFormat += fFmt;
     34
     35        fService->setData(const_cast<char*>(fFormat.c_str()));
     36        fService->updateService();
     37
     38    }
     39    ~DimDescriptionService()
     40    {
     41        const size_t pos = fFormat.find(fFmt);
     42        if (pos!=std::string::npos)
     43            fFormat.replace(pos, fFmt.size(), "");
     44
     45        if (--fCount>0)
     46            return;
     47
     48        delete fService;
     49        fService=0;
     50    }
     51};
     52
     53class DimDescribedService : public DimDescriptionService, public DimService
     54{
     55public:
     56    template<typename T>
     57        DimDescribedService(const char *name, T &val, const char *desc)
     58        : DimDescriptionService(name, desc), DimService(name, val)
     59    {
     60    }
     61
     62    DimDescribedService(const char *name, const char *val, const char *desc)
     63        : DimDescriptionService(name, desc), DimService(name, const_cast<char*>(val)) { }
     64
     65    DimDescribedService(const char *name, char *format, void *structure, int size, const char *desc)
     66        : DimDescriptionService(name, desc), DimService(name, format, structure, size)
     67    {
     68        // FIXME: compare number of ; with number of |
     69    }
     70};
     71
     72DimService *DimDescriptionService::fService = 0;
     73int DimDescriptionService::fCount = 0;
     74std::string DimDescriptionService::fFormat;
     75
     76
    877int main(int, const char **)
    978{
    10    // We could use putenv to make the Configure class change the value...
     79    // We could use putenv to make the Configure class change the value...
    1180    setenv("DIM_DNS_NODE", "localhost", 0);
    1281
     
    1786    std::cout << "Offering TIME/MESSAGE...\n" << std::endl;
    1887
     88    short s;
     89    int i;
     90    long long ll;
     91    float f;
     92    DimDescribedService servt("TIME/TEST", "C:1;I:1;C", NULL, 0,
     93                              "Char[c]:This is a char|   Int This is an int|String[s]:This is a string");
     94
     95    DimDescribedService servs("TIME/SHORT",     s,  "[a]");
     96    DimDescribedService servx("TIME/LONGLONG",  ll, ": This is my long long");
     97    DimDescribedService servi("TIME/INT",       i,  "MyInt{mi}");
     98    DimDescribedService servf("TIME/FLOAT",     f,  "   MyFloat  :   This is my float");
     99    DimDescribedService servc("TIME/TIME", const_cast<char*>(""), "MyTime[T]:This is my time");
     100
     101    DimCommand cmd("TIME/CMD", "I:2;F:2");
     102
     103    DimDescriptionService des("TIME/CMD", "range[addr]:From DAC to DAC|values[DAC]:DAC values to be set");
     104
    19105    // Setup a DimService called TIME/MESSAGE
    20106    MessageDimTX msg("TIME");
     
    23109        // Send current time
    24110        msg.Message(Time().GetAsStr());
    25 
     111//        servx.Update();
     112        /*
     113        servs.updateService();
     114        servi.updateService();
     115        servf.updateService();
     116        servc.updateService();
     117         */
    26118        // wait approximately one second
    27         usleep(1000000);
     119        usleep(100000);
    28120    }
    29121
  • trunk/FACT++/src/test3.cc

    r10325 r10347  
    6060void PrintUsage()
    6161{
    62     cout <<
     62    cout << "\n"
    6363        "The console connects to all available Dim Servers and allows to "
    6464        "easily access all of their commands.\n"
Note: See TracChangeset for help on using the changeset viewer.