HAMcast developers

Changes between Version 10 and Version 11 of documentation/tools/monitoring/rest


Ignore:
Timestamp:
02/18/12 16:50:27 (12 years ago)
Author:
zagaria
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • documentation/tools/monitoring/rest

    v10 v11  
    4141
    4242<method>
    43 hello_client
     43  /hello_client
    4444<\method>
    4545<hello>
     
    5959
    6060}}}
     61
     62== Example method ==
     63
     64This example will show you how to create a method for the rest interface.
     65For this example we add the ''hello_client'' method to the collectors interface.
     66The function_wrapper.hpp and function_wrapper.cpp are where the method has to be defined and implemented.
     67
     68We add {{{std::string hello_client(std::vector<std::strings>);}}} to the header file and implement the method.
     69Note that all arguments are saved into a vector of string, the responsebility of converting the arguments into the right data type is part of the method as well as the creation if the XML document for the reply.
     70
     71
     72{{{
     73
     74std::string function_wrapper::hello_client(std::vector<std::string> args){
     75    if(args.size() > 1){
     76        return std::string();
     77    }
     78    else{
     79        std::stringstream output;
     80        boost::property_tree::ptree pt;
     81        pt.add("method","/hello_client");
     82        try{
     83           int end  = boost::lexical_cast<int>(args.first());
     84           for(int i = 1 ; i <= end; i++){
     85             pt.add("count.num",i);
     86            }
     87        } 
     88        catch(exception &e){
     89          std::cout << e.what() << std::endl;
     90          return std::string();
     91        }
     92        try{
     93            boost::property_tree::xml_parser::xml_writer_settings<char> w(' ', 2);
     94            boost::property_tree::xml_parser::write_xml( output, pt,w );
     95        }
     96        catch (std::exception& e){
     97            std::cout << e.what() << std::endl;
     98            return std::string();
     99        }
     100        return output.str();
     101    }
     102}
     103}}}
     104
     105
     106
     107
     108
     109