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)  

helloworld.cpp
Go to the documentation of this file.
1 // =-=-=-=-=-=-=-
2 // irods includes
3 #include "apiHandler.hpp"
4 #include "api_plugin_number.h"
5 #include "irods_stacktrace.hpp"
8 #include "boost/lexical_cast.hpp"
9 
10 #include "objStat.h"
11 #include "client_api_whitelist.hpp"
12 
13 // =-=-=-=-=-=-=-
14 // stl includes
15 #include <sstream>
16 #include <string>
17 #include <iostream>
18 
19 typedef struct {
20  int _this;
21  char _that [64];
22 } helloInp_t;
23 
24 typedef struct {
25  double _value;
26 } otherOut_t;
27 
28 typedef struct {
29  int _this;
30  char _that [64];
32 } helloOut_t;
33 
34 #define HelloInp_PI "int _this; str _that[64];"
35 #define OtherOut_PI "double _value;"
36 #define HelloOut_PI "int _this; str _that[64]; struct OtherOut_PI;"
37 
39  irods::api_entry* _api,
40  rsComm_t* _comm,
41  helloInp_t* _inp,
42  helloOut_t** _out ) {
43  return _api->call_handler<
44  helloInp_t*,
45  helloOut_t** >(
46  _comm,
47  _inp,
48  _out );
49 }
50 
51 #ifdef RODS_SERVER
52 static irods::error serialize_helloInp_ptr(
53  boost::any _p,
55  try {
56  helloInp_t* tmp = boost::any_cast<helloInp_t*>(_p);
57  if(tmp) {
58  _out["this"] = boost::lexical_cast<std::string>(tmp->_this);
59  _out["that"] = boost::lexical_cast<std::string>(tmp->_that);
60  }
61  else {
62  _out["null_value"] = "null_value";
63  }
64  }
65  catch ( std::exception& ) {
66  return ERROR(
68  "failed to cast helloInp ptr" );
69  }
70 
71  return SUCCESS();
72 } // serialize_helloInp_ptr
73 
74 static irods::error serialize_helloOut_ptr_ptr(
75  boost::any _p,
77  try {
78  helloOut_t** tmp = boost::any_cast<helloOut_t**>(_p);
79  if(tmp && *tmp ) {
80  helloOut_t* l = *tmp;
81  _out["this"] = boost::lexical_cast<std::string>(l->_this);
82  _out["that"] = boost::lexical_cast<std::string>(l->_that);
83  _out["value"] = boost::lexical_cast<std::string>(l->_other._value);
84  }
85  else {
86  _out["null_value"] = "null_value";
87  }
88  }
89  catch ( std::exception& ) {
90  return ERROR(
92  "failed to cast helloOut ptr ptr" );
93  }
94 
95  return SUCCESS();
96 } // serialize_helloOut_ptr_ptr
97 #endif
98 
99 
100 #ifdef RODS_SERVER
101  #define CALL_HELLOINP_HELLO_OUT call_helloInp_helloOut
102 #else
103  #define CALL_HELLOINP_HELLO_OUT NULL
104 #endif
105 
106 // =-=-=-=-=-=-=-
107 // api function to be referenced by the entry
109  rodsLog( LOG_NOTICE, "Dynamic API - HELLO WORLD" );
110 
111  ( *_out ) = ( helloOut_t* )malloc( sizeof( helloOut_t ) );
112  ( *_out )->_this = 42;
113  strncpy( ( *_out )->_that, "hello, world.", 63 );
114  ( *_out )->_other._value = 128.0;
115 
116  rodsLog( LOG_NOTICE, "Dynamic API - this [%d] that [%s]", _inp->_this, _inp->_that );
117  rodsLog( LOG_NOTICE, "Dynamic API - DONE" );
118 
119  return 0;
120 }
121 
122 extern "C" {
123  // =-=-=-=-=-=-=-
124  // factory function to provide instance of the plugin
125  irods::api_entry* plugin_factory(const std::string&, //_inst_name
126  const std::string&) // _context
127  {
128 #ifdef RODS_SERVER
129  irods::client_api_whitelist::instance().add(HELLO_WORLD_APN);
130 #endif // RODS_SERVER
131 
132  // =-=-=-=-=-=-=-
133  // create a api def object
134  irods::apidef_t def = {HELLO_WORLD_APN, // api number
135  RODS_API_VERSION, // api version
136  NO_USER_AUTH, // client auth
137  NO_USER_AUTH, // proxy auth
138  "HelloInp_PI", 0, // in PI / bs flag
139  "HelloOut_PI", 0, // out PI / bs flag
140  std::function<int(rsComm_t*, helloInp_t*, helloOut_t**)>(rs_hello_world), // operation
141  "api_hello_world", // operation name
142  0, // null clear fcn
143  (funcPtr)CALL_HELLOINP_HELLO_OUT};
144  // =-=-=-=-=-=-=-
145  // create an api object
146  irods::api_entry* api = new irods::api_entry( def );
147 
148 #ifdef RODS_SERVER
150  typeid(helloInp_t*),
151  serialize_helloInp_ptr );
152 
154  typeid(helloOut_t**),
155  serialize_helloOut_ptr_ptr );
156 #endif
157 
158  // =-=-=-=-=-=-=-
159  // assign the pack struct key and value
160  api->in_pack_key = "HelloInp_PI";
161  api->in_pack_value = HelloInp_PI;
162 
163  api->out_pack_key = "HelloOut_PI";
165 
166  api->extra_pack_struct[ "OtherOut_PI" ] = OtherOut_PI;
167 
168  return api;
169 
170  } // plugin_factory
171 
172 }; // extern "C"
rodsLog
void rodsLog(int level, const char *formatStr,...)
Definition: rodsLog.cpp:86
rsComm_t
Definition: rcConnect.h:145
irods::re_serialization::serialized_parameter_t
std::map< std::string, std::string > serialized_parameter_t
Definition: irods_re_serialization.hpp:21
HelloOut_PI
#define HelloOut_PI
Definition: helloworld.cpp:36
OtherOut_PI
#define OtherOut_PI
Definition: helloworld.cpp:35
plugin_factory
irods::api_entry * plugin_factory(const std::string &, const std::string &)
Definition: helloworld.cpp:125
irods::api_entry::out_pack_key
std::string out_pack_key
Definition: apiHandler.hpp:284
irods::api_entry::out_pack_value
std::string out_pack_value
Definition: apiHandler.hpp:286
objStat.h
irods_stacktrace.hpp
otherOut_t
Definition: helloworld.cpp:24
irods_re_serialization.hpp
apiHandler.hpp
irods::api_entry::in_pack_key
std::string in_pack_key
Definition: apiHandler.hpp:283
helloInp_t::_this
int _this
Definition: helloworld.cpp:20
NO_USER_AUTH
#define NO_USER_AUTH
Definition: rodsUser.h:31
irods::apidef_t
Definition: apiHandler.hpp:39
helloInp_t
Definition: helloworld.cpp:19
helloInp_t::_that
char _that[64]
Definition: helloworld.cpp:21
rs_hello_world
int rs_hello_world(rsComm_t *, helloInp_t *_inp, helloOut_t **_out)
Definition: helloworld.cpp:108
helloOut_t::_other
otherOut_t _other
Definition: helloworld.cpp:31
SUCCESS
#define SUCCESS()
Definition: irods_error.hpp:121
client_api_whitelist.hpp
otherOut_t::_value
double _value
Definition: helloworld.cpp:25
irods::api_entry::call_handler
int call_handler(rsComm_t *_comm, types_t... _t)
Definition: apiHandler.hpp:127
irods::re_serialization::add_operation
error add_operation(const index_t &_index, operation_t _operation)
Definition: irods_re_serialization.cpp:980
helloOut_t
Definition: helloworld.cpp:28
CALL_HELLOINP_HELLO_OUT
#define CALL_HELLOINP_HELLO_OUT
Definition: helloworld.cpp:103
INVALID_ANY_CAST
@ INVALID_ANY_CAST
Definition: rodsErrorTable.h:771
irods::api_entry::extra_pack_struct
lookup_table< std::string > extra_pack_struct
Definition: apiHandler.hpp:289
api_plugin_number.h
irods::client_api_whitelist::instance
static auto instance() -> client_api_whitelist &
Definition: client_api_whitelist.cpp:29
LOG_NOTICE
#define LOG_NOTICE
Definition: rodsLog.h:33
ERROR
#define ERROR(code_, message_)
Definition: irods_error.hpp:117
irods::error
Definition: irods_error.hpp:23
helloOut_t::_this
int _this
Definition: helloworld.cpp:29
get_db_schema_version.l
l
Definition: get_db_schema_version.py:19
HelloInp_PI
#define HelloInp_PI
Definition: helloworld.cpp:34
irods_server_api_call.hpp
call_helloInp_helloOut
int call_helloInp_helloOut(irods::api_entry *_api, rsComm_t *_comm, helloInp_t *_inp, helloOut_t **_out)
Definition: helloworld.cpp:38
irods::api_entry
Definition: apiHandler.hpp:104
irods::api_entry::in_pack_value
std::string in_pack_value
Definition: apiHandler.hpp:285