00001
00002
00003
00004
00005 #include "index.h"
00006 #include "reFuncDefs.h"
00007
00008
00009
00010 #include "eirods_operation_rule_execution_manager.h"
00011
00012 namespace eirods {
00013
00014
00015 operation_rule_execution_manager::operation_rule_execution_manager(
00016 const std::string& _instance,
00017 const std::string& _op_name ) :
00018 operation_rule_execution_manager_base(
00019 _instance,
00020 _op_name ) {
00021 rule_name_ = "pep_" + op_name_;
00022
00023 }
00024
00025
00026
00027 error operation_rule_execution_manager::exec_pre_op(
00028 keyValPair_t& _kvp,
00029 std::string& _res ) {
00030
00031
00032 std::string pre_name = rule_name_ + "_pre";
00033
00034
00035
00036 return exec_op( _kvp, pre_name, _res );
00037
00038 }
00039
00040
00041
00042 error operation_rule_execution_manager::exec_post_op(
00043 keyValPair_t& _kvp,
00044 std::string& _res ) {
00045
00046
00047 std::string post_name = rule_name_ + "_post";
00048
00049
00050
00051 return exec_op( _kvp, post_name, _res );
00052
00053 }
00054
00055
00056
00057 error operation_rule_execution_manager::exec_op(
00058 keyValPair_t& _kvp,
00059 const std::string& _name,
00060 std::string& _res ) {
00061
00062
00063 rodsLog(
00064 LOG_DEBUG,
00065 "operation_rule_execution_manager exec_op [%s]",
00066 _name.c_str() );
00067
00068
00069
00070 RuleIndexListNode* re_node = 0;
00071 if( findNextRule2( const_cast<char*>( _name.c_str() ), 0, &re_node ) < 0 ) {
00072 return ERROR( SYS_RULE_NOT_FOUND, "no rule found" );
00073 }
00074
00075
00076
00077 ruleExecInfo_t rei;
00078 memset ((char*)&rei, 0, sizeof (ruleExecInfo_t));
00079 rei.condInputData = &_kvp;
00080 rstrcpy( rei.pluginInstanceName, instance_.c_str(), MAX_NAME_LEN );
00081
00082
00083
00084 msParamArray_t params;
00085 memset( ¶ms, 0, sizeof( msParamArray_t ) );
00086 char out_param[ MAX_NAME_LEN ] = {"EMPTY_PARAM"};
00087 if( _res.empty() ) {
00088 addMsParamToArray( ¶ms, "*OUT", STR_MS_T, out_param, NULL, 0 );
00089 } else {
00090 addMsParamToArray( ¶ms, "*OUT", STR_MS_T, const_cast<char*>( _res.c_str() ), NULL, 0 );
00091 }
00092
00093
00094
00095 std::string arg_name = _name + "(*OUT)";
00096 int ret = applyRuleUpdateParams(
00097 const_cast<char*>( arg_name.c_str() ),
00098 ¶ms,
00099 &rei,
00100 NO_SAVE_REI );
00101 if( 0 != ret ) {
00102 return ERROR( ret, "failed in call to applyRuleUpdateParams" );
00103 }
00104
00105
00106
00107 msParam_t* out_ms_param = getMsParamByLabel( ¶ms, "*OUT" );
00108 if( out_ms_param ) {
00109 _res = reinterpret_cast< char* >( out_ms_param->inOutStruct );
00110
00111 } else {
00112 return ERROR( SYS_INVALID_INPUT_PARAM, "null out parameter" );
00113
00114 }
00115
00116 return SUCCESS();
00117
00118 }
00119
00120 };
00121
00122
00123