Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:02:33

0001 #pragma once
0002 
0003 #include <iostream>
0004 #include <map>
0005 #include <nopayloadclient/nopayloadclient.hpp>
0006 #include <nopayloadclient/exception.hpp>
0007 
0008 #include <functional>
0009 #include <string>
0010 #include <iostream>
0011 #include <map>
0012 #include <vector>
0013 #include <typeinfo>
0014 #include <typeindex>
0015 #include <cassert>
0016 #include <tuple>
0017 
0018 
0019 namespace nopayloadclient {
0020 
0021 using nlohmann::json;
0022 using std::string;
0023 
0024 class CLI {
0025 typedef json (CLI::*voidFunctionType) ();
0026 public:
0027     CLI();
0028     virtual json getSize(NoPayloadClient& c);
0029     virtual json getConfDict(NoPayloadClient& c);
0030     virtual json getPayloadTypes(NoPayloadClient& c);
0031     virtual json getGlobalTags(NoPayloadClient& c);
0032     virtual json checkConnection(NoPayloadClient& c);
0033     virtual json createPayloadType(NoPayloadClient& c, int& argc, char* argv[]);
0034     virtual json deletePayloadType(NoPayloadClient& c, int& argc, char* argv[]);
0035     virtual json createGlobalTag(NoPayloadClient& c, int& argc, char* argv[]);
0036     virtual json deleteGlobalTag(NoPayloadClient& c, int& argc, char* argv[]);
0037     virtual json lockGlobalTag(NoPayloadClient& c, int& argc, char* argv[]);
0038     virtual json unlockGlobalTag(NoPayloadClient& c, int& argc, char* argv[]);
0039     virtual json getUrlDict(NoPayloadClient& c, int& argc, char* argv[]);
0040     virtual json insertPayload(NoPayloadClient& c, int& argc, char* argv[]);
0041     virtual json deletePayloadIOV(NoPayloadClient& c, int& argc, char* argv[]);
0042 
0043     template<typename T>
0044     void insertCommand(const string& name, T func){
0045         command_map_[name] = (voidFunctionType)func;
0046     }
0047 
0048     template<typename... Args>
0049     json callCommand(const string& name, Args&&... args){
0050         if (!command_map_.count(name)) {
0051             return BaseException("command <" + name + "> not found").jsonify();
0052         }
0053         auto func = command_map_[name];
0054         auto casted_func = (json (CLI::*)(Args...))func;
0055         return (this->*casted_func)(std::forward<Args>(args)...);
0056     }
0057 
0058 private:
0059     std::map<string, voidFunctionType> command_map_;
0060 
0061 };
0062 
0063 }