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_re_plugin.cpp
Go to the documentation of this file.
1 #include "irods_re_plugin.hpp"
2 #include "region.h"
3 #include "irods_hashtable.h"
5 #include "irods_exception.hpp"
6 #include "irods_ms_plugin.hpp"
7 
8 #include <vector>
9 
10 #include <boost/any.hpp>
11 int actionTableLookUp( irods::ms_table_entry& _entry, char* _action );
12 
13 namespace irods{
14 
15  // extern variable for the re plugin globals
16  std::unique_ptr<struct global_re_plugin_mgr> re_plugin_globals;
17 
18  void var_arg_to_list(std::list<boost::any>& _l) {
19  (void) _l;
20  }
21 
22  error list_to_var_arg(std::list<boost::any>& _l) {
23  if(! _l.empty()) {
24  return ERROR(-1, "arg list mismatch");
25  } else {
26  return SUCCESS();
27  }
28  }
29 
30  unpack::unpack(std::list<boost::any> &_l) : l_(_l) {};
31 
32  std::vector<re_pack_inp<default_re_ctx> > init_global_re_packs() {
33  std::vector<re_pack_inp<default_re_ctx> > ret;
34  const auto& re_plugin_configs = irods::get_server_property<const std::vector<boost::any>>(std::vector<std::string>{irods::CFG_PLUGIN_CONFIGURATION_KW, irods::PLUGIN_TYPE_RULE_ENGINE});
35  for(const auto& el : re_plugin_configs ) {
36  const auto& map = boost::any_cast<const std::unordered_map<std::string, boost::any>&>(el);
37  ret.emplace_back(
38  boost::any_cast<const std::string&> (map.at("instance_name")),
39  boost::any_cast<const std::string&> (map.at("plugin_name")),
40  UNIT);
41  }
42  return ret;
43  }
44 
46 
47  error convertToMsParam(boost::any &itr, msParam_t *t) {
48  if(itr.type() == typeid(std::string)) {
49  fillStrInMsParam( t, const_cast<char*>( boost::any_cast<std::string>(itr).c_str() ));
50  } else if(itr.type() == typeid(std::string *)) {
51  fillStrInMsParam( t, const_cast<char*>( (*(boost::any_cast<std::string *>(itr))).c_str() ));
52  } else if(itr.type() == typeid(msParam_t*)) {
53  memset(t, 0, sizeof(*t));
54  replMsParam(boost::any_cast<msParam_t*>(itr), t);
55  } else {
56  return ERROR(-1, "cannot convert parameter");
57  }
58 
59  return SUCCESS();
60  }
61 
62  error convertFromMsParam(boost::any& itr, msParam_t *t) {
63  if(std::string(t->type).compare(STR_MS_T) == 0) {
64  if(itr.type() == typeid(std::string *)) {
65  *(boost::any_cast<std::string *>(itr)) = std::string(reinterpret_cast<char*>( t->inOutStruct) );
66  }
67  } else if (t->type) {
68  replMsParam(t, boost::any_cast<msParam_t*>(itr));
69  } else {
70  return ERROR(-1, "type was null, cannot convert type");
71  }
72 
73  return SUCCESS();
74  }
75 
77  if(msName == std::string("unsafe_ms_ctx")) {
79  error err;
80  if(!(err = list_to_var_arg(l, p)).ok()) {
81  return err;
82  }
83  *p = rei;
84  return SUCCESS();
85  }
86 
87  unsigned int nargs = l.size();
88 
89  error err;
90  struct all_resources {
91  all_resources() {
92  rNew = make_region(0, NULL);
93  memset(msParams,0 ,sizeof(msParam_t[10]));
94  }
95  ~all_resources() {
96  for(auto itr= begin(myArgv);itr != end(myArgv); ++itr) {
97  clearMsParam(*itr, 1);
98  }
99  region_free(rNew);
100  }
101 
102  std::vector<msParam_t *> myArgv;
103  Region *rNew;
104  msParam_t msParams[10];
105  } ar;
106 
107  irods::ms_table_entry ms_entry;
108  int actionInx;
109  actionInx = actionTableLookUp( ms_entry,const_cast<char*>( msName .c_str()));
110  if ( actionInx < 0 ) {
111  return ERROR( NO_MICROSERVICE_FOUND_ERR, "default_microservice_manager: no microservice found " + msName);
112  }
113 
114  int i = 0;
115  for(auto itr = begin(l); itr != end(l); ++itr) {
116  msParam_t* p = &(ar.msParams[i]);
117  if(!(err = convertToMsParam(*itr, p)).ok()) {
118  return err;
119  }
120  ar.myArgv.push_back(p);
121  i++;
122  }
123 
124  unsigned int numOfStrArgs = ms_entry.num_args();
125  if ( nargs != numOfStrArgs ) {
126  return ERROR( ACTION_ARG_COUNT_MISMATCH, "execMicroService3: wrong number of arguments");
127  }
128 
129  std::vector<msParam_t *> &myArgv = ar.myArgv;
130  int status = ms_entry.call( rei, myArgv );
131  if ( status < 0 ) {
132  return ERROR(status,"exec_microservice_adapter failed");
133  }
134 
135  i = 0;
136  for(auto itr = begin(l); itr != end(l); ++itr) {
137  if(!(err = convertFromMsParam(*itr, ar.myArgv[i])).ok()) {
138  return err;
139  }
140  i++;
141  }
142 
143  return SUCCESS();
144 
145  }
146 
147 }
NULL
#define NULL
Definition: rodsDef.h:70
ACTION_ARG_COUNT_MISMATCH
@ ACTION_ARG_COUNT_MISMATCH
Definition: rodsErrorTable.h:597
NO_MICROSERVICE_FOUND_ERR
@ NO_MICROSERVICE_FOUND_ERR
Definition: rodsErrorTable.h:676
irods_ms_plugin.hpp
irods_server_properties.hpp
irods::default_microservice_manager
Definition: irods_re_plugin.hpp:117
run_tests.nargs
nargs
Definition: run_tests.py:125
irods::convertFromMsParam
error convertFromMsParam(boost::any &itr, msParam_t *t)
Definition: irods_re_plugin.cpp:62
irods_exception.hpp
irods::var_arg_to_list
void var_arg_to_list(std::list< boost::any > &_l)
Definition: irods_re_plugin.cpp:18
irods::CFG_PLUGIN_CONFIGURATION_KW
const std::string CFG_PLUGIN_CONFIGURATION_KW("plugin_configuration")
pid_age.p
p
Definition: pid_age.py:13
irods::PLUGIN_TYPE_RULE_ENGINE
const std::string PLUGIN_TYPE_RULE_ENGINE("rule_engines")
make_region
Region * make_region(size_t is, jmp_buf *label)
Definition: region.cpp:85
UNIT
#define UNIT
Definition: irods_re_plugin.hpp:737
irods::init_global_re_packs
std::vector< re_pack_inp< default_re_ctx > > init_global_re_packs()
Definition: irods_re_plugin.cpp:32
irods::convertToMsParam
error convertToMsParam(boost::any &itr, msParam_t *t)
Definition: irods_re_plugin.cpp:47
irods::pluggable_rule_engine
Definition: irods_re_plugin.hpp:169
MsParam::type
char * type
Definition: msParam.h:78
region.h
STR_MS_T
#define STR_MS_T
Definition: msParam.h:21
irods_re_plugin.hpp
irods::experimental::filesystem::client::end
auto end(const collection_iterator &) noexcept -> const collection_iterator
Definition: collection_iterator.hpp:88
SUCCESS
#define SUCCESS()
Definition: irods_error.hpp:121
irods::experimental::filesystem::client::begin
auto begin(collection_iterator _iter) noexcept -> collection_iterator
Definition: collection_iterator.hpp:83
clearMsParam
int clearMsParam(msParam_t *msParam, int freeStruct)
Definition: msParam.cpp:468
irods
Definition: apiHandler.hpp:35
irods::ms_table_entry::num_args
unsigned int num_args()
Definition: irods_ms_plugin.hpp:118
irods_hashtable.h
irods.pypyodbc.status
status
Definition: pypyodbc.py:467
MsParam
Definition: msParam.h:76
ERROR
#define ERROR(code_, message_)
Definition: irods_error.hpp:117
region
Definition: region.h:45
irods::error
Definition: irods_error.hpp:23
irods::ms_table_entry
Definition: irods_ms_plugin.hpp:28
get_db_schema_version.l
l
Definition: get_db_schema_version.py:19
irods::list_to_var_arg
error list_to_var_arg(std::list< boost::any > &_l)
Definition: irods_re_plugin.cpp:22
irods::unpack::unpack
unpack(std::list< boost::any > &_l)
Definition: irods_re_plugin.cpp:30
fillStrInMsParam
void fillStrInMsParam(msParam_t *msParam, const char *myStr)
Definition: msParam.cpp:278
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
actionTableLookUp
int actionTableLookUp(irods::ms_table_entry &_entry, char *_action)
Definition: irods_re_structs.cpp:34
region_free
void region_free(Region *r)
Definition: region.cpp:146
replMsParam
int replMsParam(msParam_t *msParam, msParam_t *outMsParam)
Definition: msParam.cpp:156
MsParam::inOutStruct
void * inOutStruct
Definition: msParam.h:80
irods::re_plugin_globals
std::unique_ptr< struct irods::global_re_plugin_mgr > re_plugin_globals
Definition: irods_re_plugin.cpp:16