irods  4.2.8
About: iRODS (the integrated Rule Oriented Data System) is a distributed data-management system for creating data grids, digital libraries, persistent archives, and real-time data systems.
  Fossies Dox: irods-4.2.8.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

irods_ms_plugin.hpp
Go to the documentation of this file.
1 #ifndef __IRODS_MS_PLUGIN_HPP__
2 #define __IRODS_MS_PLUGIN_HPP__
3 
4 // =-=-=-=-=-=-=-
5 // STL Includes
6 #include <string>
7 
8 // =-=-=-=-=-=-=-
9 // dlopen, etc
10 #include <dlfcn.h>
11 
12 // =-=-=-=-=-=-=-
13 // My Includes
14 #include "irods_lookup_table.hpp"
15 #include "irods_plugin_base.hpp"
16 
17 namespace irods {
18 
19 // =-=-=-=-=-=-=-
28  class ms_table_entry : public plugin_base {
29  public:
30 
31  typedef int ( *ms_func_ptr )( ... );
32 
33  // =-=-=-=-=-=-=-
34  // Attributes
35 
36  // =-=-=-=-=-=-=-
37  // Constructors
38  ms_table_entry( );
39 
40  // =-=-=-=-=-=-=-
41  // NOTE :: this ctor should be called by plugin authors
43  int ); // num ms args
44 
45  // =-=-=-=-=-=-=-
46  // NOTE :: called internally for static plugins
47  // with no type checking
49  const std::string&, // ms name
50  unsigned int, // num ms args
51  boost::any ); // function pointer
52 
53  // =-=-=-=-=-=-=-
54  // copy ctor
55  ms_table_entry( const ms_table_entry& _rhs );
56 
57  // =-=-=-=-=-=-=-
58  // Assignment Operator - necessary for stl containers
59  ms_table_entry& operator=( const ms_table_entry& _rhs );
60 
61  // =-=-=-=-=-=-=-
62  // Destructor
63  virtual ~ms_table_entry();
64 
67  template<typename... types_t>
69  const std::string& _op,
70  std::function<int(types_t...)> _f ) {
71 
72  // =-=-=-=-=-=-=-
73  // check params
74  if ( _op.empty() ) {
75  std::stringstream msg;
76  msg << "empty operation key [" << _op << "]";
77  return ERROR(
79  msg.str() );
80  }
81 
82  operation_name_ = _op;
84 
85  return SUCCESS();
86 
87  } // add_operation
88 
89  template<typename... types_t>
90  int call_handler(types_t... _t ) {
92  rodsLog(
93  LOG_ERROR,
94  "missing microservice operation [%s]",
95  operation_name_.c_str() );
97  }
98 
99  try {
100  typedef std::function<int(types_t...)> fcn_t;
101  fcn_t fcn = boost::any_cast<fcn_t>( operations_[ operation_name_ ] );
102  return fcn(_t...);
103  }
104  catch( const boost::bad_any_cast& ) {
105  std::string msg( "failed for call - " );
106  msg += operation_name_;
107  irods::log( ERROR(
109  msg ) );
110  return INVALID_ANY_CAST;
111  }
112 
113  return 0;
114 
115  } // call_handler
116 
117  int call(ruleExecInfo_t*,std::vector<msParam_t*>&);
118  unsigned int num_args() { return num_args_; }
119 
120  private:
121  std::string operation_name_;
122  unsigned int num_args_;
123 
124  }; // class ms_table_entry
125 
126 // =-=-=-=-=-=-=-
127 // create a lookup table for ms_table_entry value type
129 
130 // =-=-=-=-=-=-=-
131 // given the name of a microservice, try to load the shared object
132 // and then register that ms with the table
133  error load_microservice_plugin( ms_table& _table, const std::string _ms );
134 
135 
136 }; // namespace irods
137 
138 #endif // __IRODS_MS_PLUGIN_HPP__
rodsLog
void rodsLog(int level, const char *formatStr,...)
Definition: rodsLog.cpp:86
irods::ms_table_entry::ms_func_ptr
int(* ms_func_ptr)(...)
Definition: irods_ms_plugin.hpp:31
irods::lookup_table
Definition: irods_lookup_table.hpp:24
irods::ms_table
lookup_table< ms_table_entry * > ms_table
Definition: irods_ms_plugin.hpp:128
irods::ms_table_entry::ms_table_entry
ms_table_entry()
Definition: irods_ms_plugin.cpp:15
irods_plugin_base.hpp
irods::ms_table_entry::~ms_table_entry
virtual ~ms_table_entry()
Definition: irods_ms_plugin.cpp:57
LOG_ERROR
#define LOG_ERROR
Definition: rodsLog.h:43
SYS_INVALID_INPUT_PARAM
@ SYS_INVALID_INPUT_PARAM
Definition: rodsErrorTable.h:195
SUCCESS
#define SUCCESS()
Definition: irods_error.hpp:121
irods::ms_table_entry::call_handler
int call_handler(types_t... _t)
Definition: irods_ms_plugin.hpp:90
irods
Definition: apiHandler.hpp:35
irods::plugin_base
Definition: irods_plugin_base.hpp:48
irods::ms_table_entry::num_args
unsigned int num_args()
Definition: irods_ms_plugin.hpp:118
INVALID_ANY_CAST
@ INVALID_ANY_CAST
Definition: rodsErrorTable.h:771
irods::ms_table_entry::add_operation
error add_operation(const std::string &_op, std::function< int(types_t...)> _f)
Definition: irods_ms_plugin.hpp:68
irods::lookup_table::has_entry
bool has_entry(KeyType _k) const
Definition: irods_lookup_table.hpp:41
irods::log
void log(const error &)
Definition: irods_log.cpp:13
ERROR
#define ERROR(code_, message_)
Definition: irods_error.hpp:117
irods::error
Definition: irods_error.hpp:23
int
typedef int((*funcPtr)())
irods::ms_table_entry
Definition: irods_ms_plugin.hpp:28
irods::ms_table_entry::operation_name_
std::string operation_name_
Definition: irods_ms_plugin.hpp:121
irods::ms_table_entry::call
int call(ruleExecInfo_t *, std::vector< msParam_t * > &)
Definition: irods_ms_plugin.cpp:60
RuleExecInfo
Definition: irods_re_structs.hpp:18
irods::ms_table_entry::operator=
ms_table_entry & operator=(const ms_table_entry &_rhs)
Definition: irods_ms_plugin.cpp:49
irods::ms_table_entry::num_args_
unsigned int num_args_
Definition: irods_ms_plugin.hpp:122
irods_lookup_table.hpp
irods::plugin_base::operations_
lookup_table< boost::any > operations_
Definition: irods_plugin_base.hpp:340
irods::load_microservice_plugin
error load_microservice_plugin(ms_table &_table, const std::string _ms)
Definition: irods_ms_plugin.cpp:242