From 0343a1e1e37d94dac9fca18b39b78aa02333f2ef Mon Sep 17 00:00:00 2001 From: Jan Chrin Date: Thu, 3 Jan 2019 09:52:11 +0100 Subject: [PATCH] reformat mex file --- .gitignore | 1 + macchinettaHelper.h | 2068 ++++--- macchinettaSwitch.cpp | 12108 +++++++++++++++++++++------------------- 3 files changed, 7648 insertions(+), 6529 deletions(-) diff --git a/.gitignore b/.gitignore index 951fca0..5c589f8 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ windows-x64 felix-cache readme.txt makefile_rel* +*.*.orig diff --git a/macchinettaHelper.h b/macchinettaHelper.h index 2d33520..a41c9e2 100644 --- a/macchinettaHelper.h +++ b/macchinettaHelper.h @@ -2,7 +2,8 @@ #include "macchinetta.h" #include "containerMochaccino.h" -namespace NS_MOCHA { +namespace NS_MOCHA +{ using boost::multi_index_container; using namespace boost::multi_index; @@ -123,29 +124,49 @@ uint32_T monitorID=0; int16_T nfieldsInfo=11; int16_T nfieldsME=5; -int16_T nfields=5; +int16_T nfields=5; int16_T nfieldsExtra=11; int16_T nfieldsCtrl=21; -const char * fnamesInfo[11] ={"handle","pv","channelID","connectFlag","hostName","dataType", -"className","accessRead", "accessWrite","nelem","connectionState"}; +const char * fnamesInfo[11] = {"handle","pv","channelID","connectFlag","hostName","dataType", + "className","accessRead", "accessWrite","nelem","connectionState" + }; -const char * fnamesME[5] ={"pv","handle","status","statusText","statusInfo"}; -const char * fnames[5] ={"val","status","alarmStatus","alarmSeverity","ts"}; -const char * fnamesExtra[11] ={"handle","pv","val","status","status_str","alarmStatus","alarmStatus_str", - "alarmSeverity","alarmSeverity_str","ts","epicsTS"}; -const char * fnamesCtrl[21]={"handle","pv","val","status","status_str","alarmStatus","alarmStatus_str", - "alarmSeverity","alarmSeverity_str", - "precision","units","noEnumStrings","enumStrings", - "upperDisplayLimit","lowerDisplayLimit","upperAlarmLimit", "lowerAlarmLimit", - "upperWarningLimit","lowerWarningLimit","upperControlLimit","lowerControlLimit"}; +const char * fnamesME[5] = {"pv","handle","status","statusText","statusInfo"}; +const char * fnames[5] = {"val","status","alarmStatus","alarmSeverity","ts"}; +const char * fnamesExtra[11] = {"handle","pv","val","status","status_str","alarmStatus","alarmStatus_str", + "alarmSeverity","alarmSeverity_str","ts","epicsTS" + }; +const char * fnamesCtrl[21]= {"handle","pv","val","status","status_str","alarmStatus","alarmStatus_str", + "alarmSeverity","alarmSeverity_str", + "precision","units","noEnumStrings","enumStrings", + "upperDisplayLimit","lowerDisplayLimit","upperAlarmLimit", "lowerAlarmLimit", + "upperWarningLimit","lowerWarningLimit","upperControlLimit","lowerControlLimit" + }; -mxArray *fout0; mxArray *fout1; mxArray *fout2; mxArray *fout3; mxArray *fout4; -mxArray *fout5; mxArray *fout6; mxArray *fout7; mxArray *fout8; mxArray *fout9; -mxArray *fout10; mxArray *fout11; mxArray *fout12; mxArray *fout13; mxArray *fout14; -mxArray *fout15; mxArray *fout16; mxArray *fout17; mxArray *fout18; -mxArray *fout1a; mxArray *fout2a; mxArray *fout3a; +mxArray *fout0; +mxArray *fout1; +mxArray *fout2; +mxArray *fout3; +mxArray *fout4; +mxArray *fout5; +mxArray *fout6; +mxArray *fout7; +mxArray *fout8; +mxArray *fout9; +mxArray *fout10; +mxArray *fout11; +mxArray *fout12; +mxArray *fout13; +mxArray *fout14; +mxArray *fout15; +mxArray *fout16; +mxArray *fout17; +mxArray *fout18; +mxArray *fout1a; +mxArray *fout2a; +mxArray *fout3a; unsigned int nc=0,nr=0,nn=0; @@ -154,116 +175,119 @@ mochaccino_set mdt; enum mdtIndex {MOCHA_NATIVE=0, MOCHA_CHAR, MOCHA_UCHAR, MOCHA_SHORT, MOCHA_USHORT, MOCHA_INT, MOCHA_UINT, MOCHA_LONG, MOCHA_ULONG, - MOCHA_FLOAT, MOCHA_DOUBLE, MOCHA_STRING}; + MOCHA_FLOAT, MOCHA_DOUBLE, MOCHA_STRING + }; //map Strings to Integers -enum mochaIndex {SHOW=1, OPEN, OPEN_ARRAY, OPEN_WAIT, GET_OPEN_WAIT_TIME, - OPEN_WAIT_WITH_TIME,OPEN_WAIT_TIME_TO_DEFAULT, - OPEN_NOWAIT, OPEN_NOW, OPEN_NOW_AND_WAIT, OPEN_GROUP, - CLOSE, CLOSE_ARRAY, CLOSE_GROUP, CA_POLL, MEX_UNLOCK, MOCHA_VERSION, - WITH_EXCEPTIONS, HAVE_EXCEPTIONS, SEND_NOW, +enum mochaIndex {SHOW=1, OPEN, OPEN_ARRAY, OPEN_WAIT, GET_OPEN_WAIT_TIME, + OPEN_WAIT_WITH_TIME,OPEN_WAIT_TIME_TO_DEFAULT, + OPEN_NOWAIT, OPEN_NOW, OPEN_NOW_AND_WAIT, OPEN_GROUP, + CLOSE, CLOSE_ARRAY, CLOSE_GROUP, CA_POLL, MEX_UNLOCK, MOCHA_VERSION, + WITH_EXCEPTIONS, HAVE_EXCEPTIONS, SEND_NOW, GET=100, GET_INT8, GET_INT16, GET_INT32, GET_INT64, GET_UINT8, GET_UINT16, GET_UINT32, GET_UINT64, GET_FLOAT, GET_DOUBLE, - GET_STRING, GET_CACHE, GET_ASYN, GET_SCALAR_ARRAY, - GET_SCALAR_ARRAY_CACHE, GET_ARRAY_ASYN, - GET_STRUCT_ARRAY, GET_STRUCT_ARRAY_CACHE, - GET_STRUCT_EXTENDED_ARRAY, GET_STRUCT_EXTENDED_ARRAY_CACHE, - GET_CELL_ARRAY, GET_CELL_ARRAY_CACHE, - GET_WF_AS_STRING, GET_WF_AS_STRING_CACHE, - GET_GROUP, GET_GROUP_CACHE, GET_GROUP_EXTENDED, GET_GROUP_EXTENDED_CACHE, - GET_STRUCT, GET_STRUCT_CACHE, GET_STRUCT_EXTENDED, GET_STRUCT_EXTENDED_CACHE, + GET_STRING, GET_CACHE, GET_ASYN, GET_SCALAR_ARRAY, + GET_SCALAR_ARRAY_CACHE, GET_ARRAY_ASYN, + GET_STRUCT_ARRAY, GET_STRUCT_ARRAY_CACHE, + GET_STRUCT_EXTENDED_ARRAY, GET_STRUCT_EXTENDED_ARRAY_CACHE, + GET_CELL_ARRAY, GET_CELL_ARRAY_CACHE, + GET_WF_AS_STRING, GET_WF_AS_STRING_CACHE, + GET_GROUP, GET_GROUP_CACHE, GET_GROUP_EXTENDED, GET_GROUP_EXTENDED_CACHE, + GET_STRUCT, GET_STRUCT_CACHE, GET_STRUCT_EXTENDED, GET_STRUCT_EXTENDED_CACHE, GET_ENUM_STRINGS, GET_CTRL_STRUCT, GET_CTRL_CACHE, GET_ME_STRUCT, GET_CHANNEL_INFO, - FETCH_INDEX_OF_GROUP_MEMBER, FETCH_INDEX_OF_COLLECTION_MEMBER, + FETCH_INDEX_OF_GROUP_MEMBER, FETCH_INDEX_OF_COLLECTION_MEMBER, GET_STATUS=200, GET_STATUS_TEXT, GET_STATUS_INFO, IS_STATUS_TIMEOUT, - GET_ALARM, GET_ALARM_AS_STRING, - STATUS_AS_STRING, ALARM_STATUS_AS_STRING, ALARM_SEVERITY_AS_STRING, - STATUS_LIST, ALARM_STATUS_LIST, ALARM_SEVERITY_LIST, - GET_TIMESTAMP, GET_EPICS_TIMESTAMP, GET_PULSEID_FROM_TIMESTAMP, - GET_PULSEID_FROM_TIMESTAMP_GROUP, - GET_READ_ACCESS, GET_WRITE_ACCESS, - INIT_GET_SYNC_WITH_CALLBACK_DEFAULT,INIT_GET_SYNC_WITHOUT_CALLBACK, + GET_ALARM, GET_ALARM_AS_STRING, + STATUS_AS_STRING, ALARM_STATUS_AS_STRING, ALARM_SEVERITY_AS_STRING, + STATUS_LIST, ALARM_STATUS_LIST, ALARM_SEVERITY_LIST, + GET_TIMESTAMP, GET_EPICS_TIMESTAMP, GET_PULSEID_FROM_TIMESTAMP, + GET_PULSEID_FROM_TIMESTAMP_GROUP, + GET_READ_ACCESS, GET_WRITE_ACCESS, + INIT_GET_SYNC_WITH_CALLBACK_DEFAULT,INIT_GET_SYNC_WITHOUT_CALLBACK, SET=300, SET_AND_GET, SET_AND_MATCH, SET_SCALAR_ARRAY, SET_STRUCT_ARRAY, SET_GROUP, SET_PUT_PREPARE, - SET_PUT_WAIT, SET_PUT_NOWAIT, - GET_TIMEOUT, SET_TIMEOUT, SET_TIMEOUT_DEFAULT, - SET_TIMEOUT_PUT, SET_TIMEOUT_GET, SET_SELF_GOVERNING_TIMEOUT, - GET_SG_TIMEOUT, SET_SG_TIMEOUT, SET_SG_TIMEOUT_DEFAULT, - SET_SG_TIMEOUT_PUT, SET_SG_TIMEOUT_GET, SET_SG_SELF_GOVERNING_TIMEOUT, - SET_NELEM, SET_NELEM_CACHE, SET_OFFSET, - GET_NELEM_CLIENT, GET_NELEM_NATIVE, GET_NELEM_REQUEST, - GET_NELEM, GET_NELEM_CACHE, GET_OFFSET, + SET_PUT_WAIT, SET_PUT_NOWAIT, + GET_TIMEOUT, SET_TIMEOUT, SET_TIMEOUT_DEFAULT, + SET_TIMEOUT_PUT, SET_TIMEOUT_GET, SET_SELF_GOVERNING_TIMEOUT, + GET_SG_TIMEOUT, SET_SG_TIMEOUT, SET_SG_TIMEOUT_DEFAULT, + SET_SG_TIMEOUT_PUT, SET_SG_TIMEOUT_GET, SET_SG_SELF_GOVERNING_TIMEOUT, + SET_NELEM, SET_NELEM_CACHE, SET_OFFSET, + GET_NELEM_CLIENT, GET_NELEM_NATIVE, GET_NELEM_REQUEST, + GET_NELEM, GET_NELEM_CACHE, GET_OFFSET, MONITOR=400, MONITOR_STOP, MONITOR_FLUSH_EVENT, - GET_MONITOR_HANDLES, GET_MONITOR_HANDLES_AND_ACTIONS, + GET_MONITOR_HANDLES, GET_MONITOR_HANDLES_AND_ACTIONS, IS_CONNECTED=500, ALL_CONNECTED, - PRINT_STATUS=600, PRINT_MONITORS, PRINT_HANDLE, PRINT_HANDLES, - PRINT_DISCONNECTED_HANDLES,GET_HANDLES,GET_HANDLE_STATES, - GET_HANDLES_WITHIN_GROUP, - GET_DISCONNECTED_HANDLES, GET_CONNECTED_HANDLES, - HANDLE_FROM_PV, PV_FROM_HANDLE, LIST_COLLECTIONS, LIST_COLLECTION_MEMBERS, - LIST_GROUPS, LIST_GROUP_MEMBERS, DEFINE_GROUP, - LOAD_XML_COLLECTIONS=900, LOAD_XML_GROUPS, LOAD_SF_GROUPS, GET_CHANNEL_LIST, - TEST=999 }; + PRINT_STATUS=600, PRINT_MONITORS, PRINT_HANDLE, PRINT_HANDLES, + PRINT_DISCONNECTED_HANDLES,GET_HANDLES,GET_HANDLE_STATES, + GET_HANDLES_WITHIN_GROUP, + GET_DISCONNECTED_HANDLES, GET_CONNECTED_HANDLES, + HANDLE_FROM_PV, PV_FROM_HANDLE, LIST_COLLECTIONS, LIST_COLLECTION_MEMBERS, + LIST_GROUPS, LIST_GROUP_MEMBERS, DEFINE_GROUP, + LOAD_XML_COLLECTIONS=900, LOAD_XML_GROUPS, LOAD_SF_GROUPS, GET_CHANNEL_LIST, + TEST=999 + }; -void msInsert() { +void msInsert() +{ ms.insert(mochaccino(SHOW, "show")); ms.insert(mochaccino(OPEN, "open")); ms.insert(mochaccino(OPEN_ARRAY, "openarray")); - ms.insert(mochaccino(CLOSE_ARRAY, "closearray")); + ms.insert(mochaccino(CLOSE_ARRAY, "closearray")); ms.insert(mochaccino(OPEN_WAIT, "openwait")); - ms.insert(mochaccino(GET_OPEN_WAIT_TIME, "getopenwaittime")); + ms.insert(mochaccino(GET_OPEN_WAIT_TIME, "getopenwaittime")); ms.insert(mochaccino(OPEN_NOWAIT, "opennowait")); - ms.insert(mochaccino(OPEN_NOWAIT, "openprepare")); + ms.insert(mochaccino(OPEN_NOWAIT, "openprepare")); ms.insert(mochaccino(OPEN_NOW, "opennow")); - ms.insert(mochaccino(OPEN_NOW_AND_WAIT, "opennowandwait")); - ms.insert(mochaccino(OPEN_WAIT_WITH_TIME, "setopentimeout")); - ms.insert(mochaccino(OPEN_WAIT_TIME_TO_DEFAULT, "setopentimeouttodefault")); - ms.insert(mochaccino(OPEN_WAIT_WITH_TIME, "setopenwaittime")); - ms.insert(mochaccino(OPEN_WAIT_TIME_TO_DEFAULT, "setopenwaittimetodefault")); - + ms.insert(mochaccino(OPEN_NOW_AND_WAIT, "opennowandwait")); + ms.insert(mochaccino(OPEN_WAIT_WITH_TIME, "setopentimeout")); + ms.insert(mochaccino(OPEN_WAIT_TIME_TO_DEFAULT, "setopentimeouttodefault")); + ms.insert(mochaccino(OPEN_WAIT_WITH_TIME, "setopenwaittime")); + ms.insert(mochaccino(OPEN_WAIT_TIME_TO_DEFAULT, "setopenwaittimetodefault")); + ms.insert(mochaccino(OPEN_GROUP, "opengroup")); ms.insert(mochaccino(CLOSE, "close")); - + ms.insert(mochaccino(CLOSE_GROUP, "closegroup")); - - ms.insert(mochaccino(CA_POLL, "capoll")); - ms.insert(mochaccino(MEX_UNLOCK, "mexunlock")); - ms.insert(mochaccino(MOCHA_VERSION, "version")); - + + ms.insert(mochaccino(CA_POLL, "capoll")); + ms.insert(mochaccino(MEX_UNLOCK, "mexunlock")); + ms.insert(mochaccino(MOCHA_VERSION, "version")); + ms.insert(mochaccino(WITH_EXCEPTIONS, "withexceptions")); - ms.insert(mochaccino(WITH_EXCEPTIONS, "setexceptions")); - ms.insert(mochaccino(HAVE_EXCEPTIONS, "haveexceptions")); + ms.insert(mochaccino(WITH_EXCEPTIONS, "setexceptions")); + ms.insert(mochaccino(HAVE_EXCEPTIONS, "haveexceptions")); ms.insert(mochaccino(SEND_NOW, "sendnow")); ms.insert(mochaccino(SEND_NOW, "caflush")); ms.insert(mochaccino(GET_ASYN, "getasyn")); - ms.insert(mochaccino(GET_ME_STRUCT, "getmestruct")); - - ms.insert(mochaccino(GET_WF_AS_STRING, "getcharasstring")); - ms.insert(mochaccino(GET_WF_AS_STRING_CACHE, "getcharasstringcache")); - ms.insert(mochaccino(GET_WF_AS_STRING, "getwfasstring")); - ms.insert(mochaccino(GET_WF_AS_STRING_CACHE, "getwfasstringcache")); + ms.insert(mochaccino(GET_ME_STRUCT, "getmestruct")); + + ms.insert(mochaccino(GET_WF_AS_STRING, "getcharasstring")); + ms.insert(mochaccino(GET_WF_AS_STRING_CACHE, "getcharasstringcache")); + ms.insert(mochaccino(GET_WF_AS_STRING, "getwfasstring")); + ms.insert(mochaccino(GET_WF_AS_STRING_CACHE, "getwfasstringcache")); ms.insert(mochaccino(GET_SCALAR_ARRAY, "getscalararray")); ms.insert(mochaccino(GET_SCALAR_ARRAY_CACHE,"getscalararraycache")); - - ms.insert(mochaccino(GET_CELL_ARRAY, "getcellarray")); - ms.insert(mochaccino(GET_CELL_ARRAY_CACHE, "getcellarraycache")); - + + ms.insert(mochaccino(GET_CELL_ARRAY, "getcellarray")); + ms.insert(mochaccino(GET_CELL_ARRAY_CACHE, "getcellarraycache")); + ms.insert(mochaccino(GET_ARRAY_ASYN, "getarrayasyn")); - + //ms.insert(mochaccino(GET_STRUCT_ARRAY, "getstructarray")); //ms.insert(mochaccino(GET_STRUCT_ARRAY_CACHE,"getstructarraycache")); - ms.insert(mochaccino(GET_STRUCT_ARRAY, "getpvarray")); + ms.insert(mochaccino(GET_STRUCT_ARRAY, "getpvarray")); ms.insert(mochaccino(GET_STRUCT_ARRAY_CACHE,"getpvarraycache")); - - + + ms.insert(mochaccino(GET_STRUCT_EXTENDED_ARRAY, "getstructarray")); ms.insert(mochaccino(GET_STRUCT_EXTENDED_ARRAY_CACHE,"getstructarraycache")); - //ms.insert(mochaccino(GET_STRUCT_EXTENDED_ARRAY, "getpvxarray")); + //ms.insert(mochaccino(GET_STRUCT_EXTENDED_ARRAY, "getpvxarray")); //ms.insert(mochaccino(GET_STRUCT_EXTENDED_ARRAY_CACHE,"getpvxarraycache")); - - ms.insert(mochaccino(INIT_GET_SYNC_WITH_CALLBACK_DEFAULT, "usesyncgetwithdefaultcallback")); - ms.insert(mochaccino(INIT_GET_SYNC_WITHOUT_CALLBACK, "usesyncgetwithoutcallback")); - + + ms.insert(mochaccino(INIT_GET_SYNC_WITH_CALLBACK_DEFAULT, "usesyncgetwithdefaultcallback")); + ms.insert(mochaccino(INIT_GET_SYNC_WITHOUT_CALLBACK, "usesyncgetwithoutcallback")); + ms.insert(mochaccino(GET, "get")); ms.insert(mochaccino(GET_CACHE, "getcache")); ms.insert(mochaccino(GET_UINT8, "getuint8")); @@ -281,23 +305,23 @@ void msInsert() { //ms.insert(mochaccino(GET_STRUCT, "getstruct")); //ms.insert(mochaccino(GET_STRUCT_CACHE, "getstructcache")); - ms.insert(mochaccino(GET_STRUCT, "getpv")); + ms.insert(mochaccino(GET_STRUCT, "getpv")); ms.insert(mochaccino(GET_STRUCT_CACHE, "getpvcache")); - - ms.insert(mochaccino(GET_STRUCT_EXTENDED, "getstruct")); + + ms.insert(mochaccino(GET_STRUCT_EXTENDED, "getstruct")); ms.insert(mochaccino(GET_STRUCT_EXTENDED_CACHE, "getstructcache")); - //ms.insert(mochaccino(GET_STRUCT_EXTENDED, "getpvx")); + //ms.insert(mochaccino(GET_STRUCT_EXTENDED, "getpvx")); //ms.insert(mochaccino(GET_STRUCT_EXTENDED_CACHE, "getpvxcache")); - - ms.insert(mochaccino(GET_GROUP, "getgroup")); - ms.insert(mochaccino(GET_GROUP_CACHE, "getgroupcache")); + + ms.insert(mochaccino(GET_GROUP, "getgroup")); + ms.insert(mochaccino(GET_GROUP_CACHE, "getgroupcache")); ms.insert(mochaccino(GET_GROUP, "getpvgroup")); - ms.insert(mochaccino(GET_GROUP_CACHE, "getpvgroupcache")); - ms.insert(mochaccino(GET_GROUP_EXTENDED, "getstructgroup")); - ms.insert(mochaccino(GET_GROUP_EXTENDED_CACHE, "getstructgroupcache")); - - - ms.insert(mochaccino(GET_ENUM_STRINGS, "getenumstrings")); + ms.insert(mochaccino(GET_GROUP_CACHE, "getpvgroupcache")); + ms.insert(mochaccino(GET_GROUP_EXTENDED, "getstructgroup")); + ms.insert(mochaccino(GET_GROUP_EXTENDED_CACHE, "getstructgroupcache")); + + + ms.insert(mochaccino(GET_ENUM_STRINGS, "getenumstrings")); ms.insert(mochaccino(GET_CTRL_STRUCT, "getctrl")); ms.insert(mochaccino(GET_CTRL_CACHE, "getctrlcache")); @@ -307,105 +331,106 @@ void msInsert() { ms.insert(mochaccino(LIST_GROUP_MEMBERS, "listgroupmembers")); ms.insert(mochaccino(LIST_COLLECTIONS, "listcollections")); ms.insert(mochaccino(LIST_COLLECTION_MEMBERS, "listcollectionmembers")); - ms.insert(mochaccino(STATUS_AS_STRING, "statusasstring")); - ms.insert(mochaccino(ALARM_STATUS_AS_STRING, "alarmstatusasstring")); - ms.insert(mochaccino(ALARM_SEVERITY_AS_STRING, "alarmseverityasstring")); - - ms.insert(mochaccino(STATUS_LIST, "statuslist")); - ms.insert(mochaccino(ALARM_STATUS_LIST, "alarmstatuslist")); - ms.insert(mochaccino(ALARM_SEVERITY_LIST, "alarmseveritylist")); - + ms.insert(mochaccino(STATUS_AS_STRING, "statusasstring")); + ms.insert(mochaccino(ALARM_STATUS_AS_STRING, "alarmstatusasstring")); + ms.insert(mochaccino(ALARM_SEVERITY_AS_STRING, "alarmseverityasstring")); + + ms.insert(mochaccino(STATUS_LIST, "statuslist")); + ms.insert(mochaccino(ALARM_STATUS_LIST, "alarmstatuslist")); + ms.insert(mochaccino(ALARM_SEVERITY_LIST, "alarmseveritylist")); + ms.insert(mochaccino(GET_STATUS, "getstatus")); ms.insert(mochaccino(GET_STATUS_TEXT, "statusastext")); ms.insert(mochaccino(GET_STATUS_INFO, "statusinfo")); - ms.insert(mochaccino(IS_STATUS_TIMEOUT, "istimeout")); + ms.insert(mochaccino(IS_STATUS_TIMEOUT, "istimeout")); ms.insert(mochaccino(GET_ALARM, "getalarm")); - ms.insert(mochaccino(GET_ALARM_AS_STRING, "getalarmasstring")); + ms.insert(mochaccino(GET_ALARM_AS_STRING, "getalarmasstring")); ms.insert(mochaccino(GET_TIMESTAMP, "gettimestamp")); - ms.insert(mochaccino(GET_EPICS_TIMESTAMP, "getepicstimestamp")); - ms.insert(mochaccino(GET_EPICS_TIMESTAMP, "getets")); + ms.insert(mochaccino(GET_EPICS_TIMESTAMP, "getepicstimestamp")); + ms.insert(mochaccino(GET_EPICS_TIMESTAMP, "getets")); //ms.insert(mochaccino(GET_PULSEID_FROM_TIMESTAMP, "getpulseidfromts")); //ms.insert(mochaccino(GET_PULSEID_FROM_TIMESTAMP_GROUP,"getgrouppulseidfromts")); - + ms.insert(mochaccino(GET_READ_ACCESS, "getreadaccess")); ms.insert(mochaccino(GET_WRITE_ACCESS, "getwriteaccess")); - ms.insert(mochaccino(GET_CHANNEL_INFO, "getchannelinfo")); - ms.insert(mochaccino(GET_CHANNEL_INFO, "getinfo")); - + ms.insert(mochaccino(GET_CHANNEL_INFO, "getchannelinfo")); + ms.insert(mochaccino(GET_CHANNEL_INFO, "getinfo")); + ms.insert(mochaccino(SET, "set")); - ms.insert(mochaccino(SET_AND_GET, "setandget")); - ms.insert(mochaccino(SET_AND_MATCH, "setandmatch")); + ms.insert(mochaccino(SET_AND_GET, "setandget")); + ms.insert(mochaccino(SET_AND_MATCH, "setandmatch")); ms.insert(mochaccino(SET_SCALAR_ARRAY, "setscalararray")); ms.insert(mochaccino(SET_STRUCT_ARRAY, "setstructarray")); - ms.insert(mochaccino(SET_STRUCT_ARRAY, "setpvarray")); + ms.insert(mochaccino(SET_STRUCT_ARRAY, "setpvarray")); ms.insert(mochaccino(SET_STRUCT_ARRAY, "setmany")); - - + + ms.insert(mochaccino(SET_GROUP, "setgroup")); ms.insert(mochaccino(SET_PUT_PREPARE, "setputprepare")); ms.insert(mochaccino(SET_PUT_WAIT, "setputwait")); ms.insert(mochaccino(SET_PUT_NOWAIT, "setputnowait")); - ms.insert(mochaccino(SET_PUT_NOWAIT, "setputdefault")); + ms.insert(mochaccino(SET_PUT_NOWAIT, "setputdefault")); ms.insert(mochaccino(GET_TIMEOUT, "gettimeout")); ms.insert(mochaccino(SET_TIMEOUT, "settimeout")); - ms.insert(mochaccino(SET_TIMEOUT_PUT, "settimeoutput")); - ms.insert(mochaccino(SET_TIMEOUT_GET, "settimeoutget")); - ms.insert(mochaccino(SET_TIMEOUT_DEFAULT,"settimeoutdefault")); - ms.insert(mochaccino(SET_SELF_GOVERNING_TIMEOUT,"setselfgoverningtimeout")); - - ms.insert(mochaccino(GET_SG_TIMEOUT, "getsgtimeout")); + ms.insert(mochaccino(SET_TIMEOUT_PUT, "settimeoutput")); + ms.insert(mochaccino(SET_TIMEOUT_GET, "settimeoutget")); + ms.insert(mochaccino(SET_TIMEOUT_DEFAULT,"settimeoutdefault")); + ms.insert(mochaccino(SET_SELF_GOVERNING_TIMEOUT,"setselfgoverningtimeout")); + + ms.insert(mochaccino(GET_SG_TIMEOUT, "getsgtimeout")); ms.insert(mochaccino(SET_SG_TIMEOUT, "setsgtimeout")); - ms.insert(mochaccino(SET_SG_TIMEOUT_PUT, "setsgtimeoutput")); - ms.insert(mochaccino(SET_SG_TIMEOUT_GET, "setsgtimeoutget")); - ms.insert(mochaccino(SET_SG_TIMEOUT_DEFAULT,"setsgtimeoutdefault")); - ms.insert(mochaccino(SET_SG_SELF_GOVERNING_TIMEOUT,"setsgselfgoverningtimeout")); - - ms.insert(mochaccino(SET_NELEM, "setnelem")); - ms.insert(mochaccino(SET_NELEM_CACHE,"setnelemcache")); - - ms.insert(mochaccino(SET_OFFSET, "setoffset")); - ms.insert(mochaccino(GET_NELEM_CLIENT, "getnelemclient")); - ms.insert(mochaccino(GET_NELEM_NATIVE, "getnelemnative")); - ms.insert(mochaccino(GET_NELEM_REQUEST, "getnelemrequest")); - ms.insert(mochaccino(GET_NELEM, "getnelem")); - ms.insert(mochaccino(GET_NELEM_CACHE,"getnelemcache")); - - ms.insert(mochaccino(GET_OFFSET, "getoffset")); - + ms.insert(mochaccino(SET_SG_TIMEOUT_PUT, "setsgtimeoutput")); + ms.insert(mochaccino(SET_SG_TIMEOUT_GET, "setsgtimeoutget")); + ms.insert(mochaccino(SET_SG_TIMEOUT_DEFAULT,"setsgtimeoutdefault")); + ms.insert(mochaccino(SET_SG_SELF_GOVERNING_TIMEOUT,"setsgselfgoverningtimeout")); + + ms.insert(mochaccino(SET_NELEM, "setnelem")); + ms.insert(mochaccino(SET_NELEM_CACHE,"setnelemcache")); + + ms.insert(mochaccino(SET_OFFSET, "setoffset")); + ms.insert(mochaccino(GET_NELEM_CLIENT, "getnelemclient")); + ms.insert(mochaccino(GET_NELEM_NATIVE, "getnelemnative")); + ms.insert(mochaccino(GET_NELEM_REQUEST, "getnelemrequest")); + ms.insert(mochaccino(GET_NELEM, "getnelem")); + ms.insert(mochaccino(GET_NELEM_CACHE,"getnelemcache")); + + ms.insert(mochaccino(GET_OFFSET, "getoffset")); + ms.insert(mochaccino(MONITOR, "monitor")); ms.insert(mochaccino(MONITOR_STOP, "monitorstop")); ms.insert(mochaccino(MONITOR_FLUSH_EVENT, "monitorflushevent")); - - ms.insert(mochaccino(GET_MONITOR_HANDLES, "getmonitorhandles")); - ms.insert(mochaccino(GET_MONITOR_HANDLES_AND_ACTIONS, "getmonitorhandlesandactions")); - - ms.insert(mochaccino(IS_CONNECTED, "isconnected")); + + ms.insert(mochaccino(GET_MONITOR_HANDLES, "getmonitorhandles")); + ms.insert(mochaccino(GET_MONITOR_HANDLES_AND_ACTIONS, "getmonitorhandlesandactions")); + + ms.insert(mochaccino(IS_CONNECTED, "isconnected")); ms.insert(mochaccino(ALL_CONNECTED, "allconnected")); - ms.insert(mochaccino(PRINT_STATUS, "printstatus")); - ms.insert(mochaccino(PRINT_DISCONNECTED_HANDLES,"printdisconnectedhandles")); - ms.insert(mochaccino(GET_HANDLES, "gethandles")); - ms.insert(mochaccino(GET_HANDLE_STATES, "gethandlestates")); - ms.insert(mochaccino(GET_HANDLES_WITHIN_GROUP, "gethandleswithingroup")); - - ms.insert(mochaccino(GET_CONNECTED_HANDLES, "getconnectedhandles")); - ms.insert(mochaccino(GET_DISCONNECTED_HANDLES, "getdisconnectedhandles")); - ms.insert(mochaccino(PRINT_MONITORS, "printmonitors")); + ms.insert(mochaccino(PRINT_STATUS, "printstatus")); + ms.insert(mochaccino(PRINT_DISCONNECTED_HANDLES,"printdisconnectedhandles")); + ms.insert(mochaccino(GET_HANDLES, "gethandles")); + ms.insert(mochaccino(GET_HANDLE_STATES, "gethandlestates")); + ms.insert(mochaccino(GET_HANDLES_WITHIN_GROUP, "gethandleswithingroup")); + + ms.insert(mochaccino(GET_CONNECTED_HANDLES, "getconnectedhandles")); + ms.insert(mochaccino(GET_DISCONNECTED_HANDLES, "getdisconnectedhandles")); + ms.insert(mochaccino(PRINT_MONITORS, "printmonitors")); ms.insert(mochaccino(PRINT_HANDLE, "printhandle")); - ms.insert(mochaccino(PRINT_HANDLES, "printhandles")); + ms.insert(mochaccino(PRINT_HANDLES, "printhandles")); ms.insert(mochaccino(HANDLE_FROM_PV, "gethandlefrompv")); ms.insert(mochaccino(PV_FROM_HANDLE, "getpvfromhandle")); ms.insert(mochaccino(DEFINE_GROUP, "definegroup")); - + ms.insert(mochaccino(LOAD_XML_COLLECTIONS,"loadxmlcollections")); ms.insert(mochaccino(LOAD_XML_GROUPS, "loadxmlgroups")); ms.insert(mochaccino(LOAD_SF_GROUPS, "loadsfgroups")); - ms.insert(mochaccino(GET_CHANNEL_LIST, "getchannellist")); + ms.insert(mochaccino(GET_CHANNEL_LIST, "getchannellist")); ms.insert(mochaccino(TEST, "test")); } -void mdtInsert() { +void mdtInsert() +{ mdt.insert(mochaccino(MOCHA_NATIVE, "native")); mdt.insert(mochaccino(MOCHA_CHAR, "int8")); mdt.insert(mochaccino(MOCHA_UCHAR, "uint8")); @@ -422,7 +447,8 @@ void mdtInsert() { mdt.insert(mochaccino(MOCHA_STRING, "string")); } -void printStatus(int status ) { +void printStatus(int status ) +{ std::string s = cafe.getCafeStatus().csi.message(status); std::string c = cafe.getCafeStatus().csc.message(status); mexPrintf("%s\n",c.c_str()); @@ -430,118 +456,133 @@ void printStatus(int status ) { } -std::string prepareExceptionID(int status ) { - std::string exID="CAFE_"; exID.append(cafe.getCafeStatus().severity(status)); - exID.append(":"); exID.append(cafe.getCafeStatus().msgID(status)); - return exID; +std::string prepareExceptionID(int status ) +{ + std::string exID="CAFE_"; + exID.append(cafe.getCafeStatus().severity(status)); + exID.append(":"); + exID.append(cafe.getCafeStatus().msgID(status)); + return exID; } -std::string prepareExceptionText(unsigned int handle, int status ) { - std::string exText="PV="; - exText.append(cafe.getPVFromHandle(handle)); - exText.append(" Handle="); - exText.append(static_cast( &(std::ostringstream() << handle) )->str()); - exText.append(" statusCode="); - exText.append(static_cast( &(std::ostringstream() << status) )->str()); - exText.append(" statusText="); exText.append(cafe.getCafeStatus().msgID(status)); - exText.append(" statusInfo="); exText.append(cafe.getCafeStatus().info(status)); - return exText; +std::string prepareExceptionText(unsigned int handle, int status ) +{ + std::string exText="PV="; + exText.append(cafe.getPVFromHandle(handle)); + exText.append(" Handle="); + exText.append(static_cast( &(std::ostringstream() << handle) )->str()); + exText.append(" statusCode="); + exText.append(static_cast( &(std::ostringstream() << status) )->str()); + exText.append(" statusText="); + exText.append(cafe.getCafeStatus().msgID(status)); + exText.append(" statusInfo="); + exText.append(cafe.getCafeStatus().info(status)); + return exText; } -void fillMEStruct(std::string sME) { +void fillMEStruct(std::string sME) +{ - fout1 = mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); - ulongArray = (uint32_T *) mxGetData (fout1); - - fout2 = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); - longStatus = (int32_T *) mxGetData (fout2); - - fout0 = mxCreateCellMatrix(1,1); - fout3 = mxCreateCellMatrix(1,1); - fout4 = mxCreateCellMatrix(1,1); - - std::string str2 =""; - std::string str =""; - - std::size_t found = sME.find("PV="); - - if (found != std::string::npos) { - str2 = sME.substr(found+3); - found = str2.find(" "); - str = str2.substr(0,found); - mexPrintf("PV %s\n", str.c_str()); - mxSetCell (fout0, 0, mxCreateString( str.c_str())); - } - - found= sME.find("Handle="); - if (found!= std::string::npos) { - str2 = sME.substr(found+7); - found = str2.find(" "); - str = str2.substr(0,found); - //mexPrintf("handle %d\n", std::atoi(str.c_str())); - ulongArray[0]= std::atoi(str.c_str()); - } - - found= sME.find("statusCode="); - if (found!= std::string::npos) { - - str2 = sME.substr(found+11); - found = str2.find(" "); - str = str2.substr(0,found); - //mexPrintf("status %d\n", std::atoi(str.c_str())); - longStatus[0]= std::atoi(str.c_str()); - } - - found= sME.find("statusText="); - if (found!= std::string::npos) { - str2 = sME.substr(found+11); - found = str2.find(" "); - str = str2.substr(0,found); - //mexPrintf("statusText %s\n", str.c_str()); - mxSetCell (fout3, 0, mxCreateString(str.c_str())); - } - - found= sME.find("statusInfo="); - if (found!= std::string::npos) { - str2 = sME.substr(found+11); - //mexPrintf("statusInfo %s\n", str2.c_str()); - mxSetCell (fout4, 0, mxCreateString(str2.c_str())); - } - - return; + fout1 = mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); + ulongArray = (uint32_T *) mxGetData (fout1); + + fout2 = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); + longStatus = (int32_T *) mxGetData (fout2); + + fout0 = mxCreateCellMatrix(1,1); + fout3 = mxCreateCellMatrix(1,1); + fout4 = mxCreateCellMatrix(1,1); + + std::string str2 =""; + std::string str =""; + + std::size_t found = sME.find("PV="); + + if (found != std::string::npos) + { + str2 = sME.substr(found+3); + found = str2.find(" "); + str = str2.substr(0,found); + mexPrintf("PV %s\n", str.c_str()); + mxSetCell (fout0, 0, mxCreateString( str.c_str())); + } + + found= sME.find("Handle="); + if (found!= std::string::npos) + { + str2 = sME.substr(found+7); + found = str2.find(" "); + str = str2.substr(0,found); + //mexPrintf("handle %d\n", std::atoi(str.c_str())); + ulongArray[0]= std::atoi(str.c_str()); + } + + found= sME.find("statusCode="); + if (found!= std::string::npos) + { + + str2 = sME.substr(found+11); + found = str2.find(" "); + str = str2.substr(0,found); + //mexPrintf("status %d\n", std::atoi(str.c_str())); + longStatus[0]= std::atoi(str.c_str()); + } + + found= sME.find("statusText="); + if (found!= std::string::npos) + { + str2 = sME.substr(found+11); + found = str2.find(" "); + str = str2.substr(0,found); + //mexPrintf("statusText %s\n", str.c_str()); + mxSetCell (fout3, 0, mxCreateString(str.c_str())); + } + + found= sME.find("statusInfo="); + if (found!= std::string::npos) + { + str2 = sME.substr(found+11); + //mexPrintf("statusInfo %s\n", str2.c_str()); + mxSetCell (fout4, 0, mxCreateString(str2.c_str())); + } + + return; } -bool isValidClass(const mxArray * inputClass) { +bool isValidClass(const mxArray * inputClass) +{ // Refuse these input mx classes; mxClassID mxid =mxGetClassID( inputClass); - switch(mxid) { - case mxUNKNOWN_CLASS: - mexPrintf("Undetermined class: %s \n",mxGetClassName( inputClass) ); - return false; - break; - case mxSTRUCT_CLASS: - case mxFUNCTION_CLASS: - mexPrintf("The requested class is not yet supported: %s \n",mxGetClassName( inputClass) ); - return false; - break; - case mxVOID_CLASS: - mexPrintf("This requested class is reserved: %s \n",mxGetClassName( inputClass) ); - return false; - break; + switch(mxid) + { + case mxUNKNOWN_CLASS: + mexPrintf("Undetermined class: %s \n",mxGetClassName( inputClass) ); + return false; + break; + case mxSTRUCT_CLASS: + case mxFUNCTION_CLASS: + mexPrintf("The requested class is not yet supported: %s \n",mxGetClassName( inputClass) ); + return false; + break; + case mxVOID_CLASS: + mexPrintf("This requested class is reserved: %s \n",mxGetClassName( inputClass) ); + return false; + break; } return true; } -unsigned int getMdtIndexFromCafeDataType(CAFE_DATATYPE cdt){ +unsigned int getMdtIndexFromCafeDataType(CAFE_DATATYPE cdt) +{ unsigned int mdtIndex; switch ( cdt) @@ -574,7 +615,8 @@ unsigned int getMdtIndexFromCafeDataType(CAFE_DATATYPE cdt){ return mdtIndex; } -unsigned int getMdtIndex(const mxArray * l){ +unsigned int getMdtIndex(const mxArray * l) +{ char messStruct[METHOD_NAME_MAX_SIZE]; mxArray * mDataStruct; @@ -589,7 +631,7 @@ unsigned int getMdtIndex(const mxArray * l){ mDataStruct = (mxArray *) l; mxGetString(mDataStruct, messStruct, messLengthStruct); - //Not allowed! + //Not allowed! //mxFree(mxGetData(mDataStruct)); // Added line to avoid memory leak //mxDestroyArray(mDataStruct); @@ -600,7 +642,10 @@ unsigned int getMdtIndex(const mxArray * l){ //tolowercase std::string messString = messStruct; - if(messString.size()==0) {return mdtIndex;} + if(messString.size()==0) + { + return mdtIndex; + } std::transform(messString.begin(), messString.end(), messString.begin(), ::tolower); strcpy(messStruct,messString.c_str()); @@ -608,11 +653,13 @@ unsigned int getMdtIndex(const mxArray * l){ //Is Valid Data Type?? it_name_mdt = name_mdt_index.find(messStruct); - if (it_name_mdt != name_mdt_index.end()) { + if (it_name_mdt != name_mdt_index.end()) + { mdtIndex=(*it_name_mdt).id; - //mexPrintf("MESSAGE INDEX: %d %s ", mdtIndex, messStruct); + //mexPrintf("MESSAGE INDEX: %d %s ", mdtIndex, messStruct); } - else { + else + { mexPrintf("WARNING: Unknown data type: %s\n", messStruct); mexPrintf("WARNING: Possible data types are listed. \n"); mexPrintf("WARNING: Using native type if known else double\n"); @@ -628,82 +675,99 @@ void scanCell(const mxArray * thisCell) { size_t thisNeWithinObject = mxGetNumberOfElements (thisCell); - for (mwIndex i=0; i openArray(std::vector vstr) { +std::vector openArray(std::vector vstr) +{ std::vector vuint32; vuint32.reserve(vstr.size()); - + std::fill(vuint32.begin(), vuint32.end(), 0); - try { + try + { cafe.open(vstr, vuint32); } - catch(CAFEException_open &e) { + catch(CAFEException_open &e) + { mexPrintf("---------------\n"); //cout << e.what() << endl; - mexPrintf("%s\n", e.what() ); + mexPrintf("%s\n", e.what() ); mexPrintf("---------------\n"); cafe.printCAFEException_pv(e.pvEx); @@ -1000,7 +1101,8 @@ std::vector openArray(std::vector vstr) { mexPrintf("EXITING MATLAB\n"); exit(1); } - catch(exception &e) { + catch(exception &e) + { mexPrintf("---------------\n"); mexPrintf("%s\n", e.what() ); @@ -1013,14 +1115,17 @@ std::vector openArray(std::vector vstr) { } -unsigned int open(char _pv[PVNAME_MAX_SIZE]) { +unsigned int open(char _pv[PVNAME_MAX_SIZE]) +{ uint32_T _handle=0; - try { + try + { cafe.open(_pv, (unsigned int&) _handle); } - catch(CAFEException_open &e) { + catch(CAFEException_open &e) + { mexPrintf("---------------\n"); cout << e.what() << endl; @@ -1031,7 +1136,8 @@ unsigned int open(char _pv[PVNAME_MAX_SIZE]) { mexPrintf("EXITING MATLAB\n"); exit(1); } - catch(exception &e) { + catch(exception &e) + { mexPrintf("---------------\n"); cout << e.what() << endl; @@ -1044,13 +1150,16 @@ unsigned int open(char _pv[PVNAME_MAX_SIZE]) { } -unsigned int groupOpen(char _pv[PVNAME_MAX_SIZE]) { +unsigned int groupOpen(char _pv[PVNAME_MAX_SIZE]) +{ uint32_T _ghandle=0; - - try { - status=cafe.groupOpen((const char *) _pv, (unsigned int &) _ghandle); + + try + { + status=cafe.groupOpen((const char *) _pv, (unsigned int &) _ghandle); } - catch(CAFEException_groupOpen &e) { + catch(CAFEException_groupOpen &e) + { mexPrintf("---------------\n"); cout << e.what() << endl; mexPrintf("---------------\n"); @@ -1058,7 +1167,8 @@ unsigned int groupOpen(char _pv[PVNAME_MAX_SIZE]) { mexPrintf("EXITING MATLAB\n"); exit(1); } - catch(exception &e) { + catch(exception &e) + { mexPrintf("---------------\n"); cout << e.what() << endl; mexPrintf("---------------\n"); @@ -1070,15 +1180,18 @@ unsigned int groupOpen(char _pv[PVNAME_MAX_SIZE]) { -unsigned int checkForHandleNoOpen(const mxArray * inputValue) { +unsigned int checkForHandleNoOpen(const mxArray * inputValue) +{ unsigned int _handle=0; - if (mxIsNumeric(inputValue) ) { + if (mxIsNumeric(inputValue) ) + { _handle = (uint32_T) mxGetScalar(inputValue); } - else if (mxIsChar(inputValue) ) { + else if (mxIsChar(inputValue) ) + { //message pvname xData = (mxArray *) inputValue; @@ -1087,20 +1200,24 @@ unsigned int checkForHandleNoOpen(const mxArray * inputValue) { mxGetString(xData, pv, pvLength); _handle=cafe.getHandleHelper().getHandleFromPV(pv); - if (_handle==0) { - mexPrintf("PV=%s has not yet been opened by user!\n", pv ); - } + if (_handle==0) + { + mexPrintf("PV=%s has not yet been opened by user!\n", pv ); + } } - else if (mxIsCell(inputValue) ) { + else if (mxIsCell(inputValue) ) + { mxArray * newCell = mxGetCell(inputValue,0); - if (mxIsNumeric(newCell) ) { + if (mxIsNumeric(newCell) ) + { _handle = (uint32_T) mxGetScalar(newCell); } - else if (mxIsChar(newCell) ) { + else if (mxIsChar(newCell) ) + { //message pvname xData = (mxArray *) newCell; @@ -1109,15 +1226,17 @@ unsigned int checkForHandleNoOpen(const mxArray * inputValue) { mxGetString(xData, pv, pvLength); _handle=cafe.getHandleHelper().getHandleFromPV(pv); - if (_handle==0) { - mexPrintf("PV=%s has not yet been opened by user!\n", pv ); - } + if (_handle==0) + { + mexPrintf("PV=%s has not yet been opened by user!\n", pv ); + } } } - else { + else + { mexPrintf("Error in checkForHandleNoOpen:\n"); - mexPrintf("Handle does not have a numeric value \n"); + mexPrintf("Handle does not have a numeric value \n"); mexPrintf("or PV name does not have a char value \n" ); } return _handle; @@ -1125,16 +1244,19 @@ unsigned int checkForHandleNoOpen(const mxArray * inputValue) { -unsigned int checkForHandle(const mxArray * inputValue) { +unsigned int checkForHandle(const mxArray * inputValue) +{ unsigned int _handle=0; - if (mxIsNumeric(inputValue) ) { + if (mxIsNumeric(inputValue) ) + { _handle = (uint32_T) mxGetScalar(inputValue); } - else if (mxIsChar(inputValue) ) { + else if (mxIsChar(inputValue) ) + { //message pvname xData = (mxArray *) inputValue; @@ -1144,19 +1266,23 @@ unsigned int checkForHandle(const mxArray * inputValue) { _handle=cafe.getHandleHelper().getHandleFromPV(pv); - if (_handle==0) { + if (_handle==0) + { _handle=open(pv); } } - else if (mxIsCell(inputValue) ) { + else if (mxIsCell(inputValue) ) + { mxArray * newCell = mxGetCell(inputValue,0); - if (mxIsNumeric(newCell) ) { + if (mxIsNumeric(newCell) ) + { _handle = (uint32_T) mxGetScalar(newCell); } - else if (mxIsChar(newCell) ) { + else if (mxIsChar(newCell) ) + { //message pvname xData = (mxArray *) newCell; @@ -1166,29 +1292,34 @@ unsigned int checkForHandle(const mxArray * inputValue) { _handle=cafe.getHandleHelper().getHandleFromPV(pv); - if (_handle==0) { + if (_handle==0) + { _handle=open(pv); } } } - else { - mexPrintf("Error in checkForHandle:\n"); - mexPrintf("Handle does not have a numeric value \n"); + else + { + mexPrintf("Error in checkForHandle:\n"); + mexPrintf("Handle does not have a numeric value \n"); mexPrintf("or PV name does not have a char value \n"); return _handle; } - if (_handle==0) { + if (_handle==0) + { mexPrintf("Handle in input argument not given! \n"); } return _handle; } -uint32_T * scanNumericForHandle (const mxArray * inputValue) { +uint32_T * scanNumericForHandle (const mxArray * inputValue) +{ uint32_T * inputULong; - if (mxIsNumeric(inputValue) ) { + if (mxIsNumeric(inputValue) ) + { size_t numberOfHandles=mxGetNumberOfElements (inputValue); mxArray * foutE = mxCreateNumericMatrix(1,numberOfHandles,mxUINT32_CLASS, mxREAL); @@ -1196,77 +1327,89 @@ uint32_T * scanNumericForHandle (const mxArray * inputValue) { mxClassID mxid =mxGetClassID(inputValue); - switch(mxid) { - case mxDOUBLE_CLASS: - inputDouble = (double *) mxGetPr ( inputValue); - for (size_t i=0; i< numberOfHandles; ++i) { - inputULong[i] = (uint32_T) inputDouble[i]; - } - break; - case mxSINGLE_CLASS: - inputFloat = (float *) mxGetData (inputValue); - for (size_t i=0; i< numberOfHandles; ++i) { - inputULong[i] = (uint32_T) inputFloat[i]; - } - break; - case mxLOGICAL_CLASS: - inputBool = (bool *) mxGetData (inputValue); - for (size_t i=0; i< numberOfHandles; ++i) { - inputULong[i] = (uint32_T) inputBool[i]; - } - break; - case mxINT8_CLASS: - inputChar = (int8_T *) mxGetData (inputValue); - for (size_t i=0; i< numberOfHandles; ++i) { - inputULong[i] = (uint32_T) inputChar[i]; - } - break; - case mxUINT8_CLASS: - inputUChar = (uint8_T *) mxGetData (inputValue); - for (size_t i=0; i< numberOfHandles; ++i) { - inputULong[i] = (uint32_T) inputUChar[i]; - } - break; - case mxINT16_CLASS: - inputShort = (int16_T *) mxGetData (inputValue); - for (size_t i=0; i< numberOfHandles; ++i) { - inputULong[i] = (uint32_T) inputShort[i]; - } - break; - case mxUINT16_CLASS: - inputUShort = (uint16_T *) mxGetData (inputValue); - for (size_t i=0; i< numberOfHandles; ++i) { - inputULong[i] = (uint32_T) inputUShort[i]; - } - break; - case mxINT32_CLASS: - inputLong = (int32_T *) mxGetData (inputValue); - for (size_t i=0; i< numberOfHandles; ++i) { - inputULong[i] = (uint32_T) inputLong[i]; - } - break; - case mxUINT32_CLASS: - inputULong = (uint32_T *) mxGetData (inputValue); - //for (size_t i=0; i< numberOfHandles; ++i) { - // inputULongLong[i] = (uint64_T) inputULong[i]; - //} - break; - case mxINT64_CLASS: - inputLongLong = (int64_T *) mxGetData (inputValue); - for (size_t i=0; i< numberOfHandles; ++i) { - inputULong[i] = (uint32_T) inputLongLong[i]; - } - break; - case mxUINT64_CLASS: - inputULongLong = (uint64_T *) mxGetData (inputValue); - for (size_t i=0; i< numberOfHandles; ++i) { - inputULong[i] = (uint32_T) inputULongLong[i]; - } - break; - // Series of Strings go in a CELL + switch(mxid) + { + case mxDOUBLE_CLASS: + inputDouble = (double *) mxGetPr ( inputValue); + for (size_t i=0; i< numberOfHandles; ++i) + { + inputULong[i] = (uint32_T) inputDouble[i]; + } + break; + case mxSINGLE_CLASS: + inputFloat = (float *) mxGetData (inputValue); + for (size_t i=0; i< numberOfHandles; ++i) + { + inputULong[i] = (uint32_T) inputFloat[i]; + } + break; + case mxLOGICAL_CLASS: + inputBool = (bool *) mxGetData (inputValue); + for (size_t i=0; i< numberOfHandles; ++i) + { + inputULong[i] = (uint32_T) inputBool[i]; + } + break; + case mxINT8_CLASS: + inputChar = (int8_T *) mxGetData (inputValue); + for (size_t i=0; i< numberOfHandles; ++i) + { + inputULong[i] = (uint32_T) inputChar[i]; + } + break; + case mxUINT8_CLASS: + inputUChar = (uint8_T *) mxGetData (inputValue); + for (size_t i=0; i< numberOfHandles; ++i) + { + inputULong[i] = (uint32_T) inputUChar[i]; + } + break; + case mxINT16_CLASS: + inputShort = (int16_T *) mxGetData (inputValue); + for (size_t i=0; i< numberOfHandles; ++i) + { + inputULong[i] = (uint32_T) inputShort[i]; + } + break; + case mxUINT16_CLASS: + inputUShort = (uint16_T *) mxGetData (inputValue); + for (size_t i=0; i< numberOfHandles; ++i) + { + inputULong[i] = (uint32_T) inputUShort[i]; + } + break; + case mxINT32_CLASS: + inputLong = (int32_T *) mxGetData (inputValue); + for (size_t i=0; i< numberOfHandles; ++i) + { + inputULong[i] = (uint32_T) inputLong[i]; + } + break; + case mxUINT32_CLASS: + inputULong = (uint32_T *) mxGetData (inputValue); + //for (size_t i=0; i< numberOfHandles; ++i) { + // inputULongLong[i] = (uint64_T) inputULong[i]; + //} + break; + case mxINT64_CLASS: + inputLongLong = (int64_T *) mxGetData (inputValue); + for (size_t i=0; i< numberOfHandles; ++i) + { + inputULong[i] = (uint32_T) inputLongLong[i]; + } + break; + case mxUINT64_CLASS: + inputULongLong = (uint64_T *) mxGetData (inputValue); + for (size_t i=0; i< numberOfHandles; ++i) + { + inputULong[i] = (uint32_T) inputULongLong[i]; + } + break; + // Series of Strings go in a CELL } } - else { + else + { mexPrintf("scanNumericForHandle was not given a numeric for input!"); mxArray * foutE = mxCreateNumericMatrix(1,1,mxUINT32_CLASS, mxREAL); inputULong = (uint32_T *) mxGetData (foutE); @@ -1275,115 +1418,132 @@ uint32_T * scanNumericForHandle (const mxArray * inputValue) { return inputULong; } -uint32_T * checkHandleArray(const mxArray * inputValue, bool openIfNoHandle) { +uint32_T * checkHandleArray(const mxArray * inputValue, bool openIfNoHandle) +{ uint32_T * inputULong; mxArray * foutE; - size_t numberOfHandles=0; + size_t numberOfHandles=0; - if (mxIsNumeric(inputValue) ) { + if (mxIsNumeric(inputValue) ) + { + + numberOfHandles=mxGetNumberOfElements (inputValue); - numberOfHandles=mxGetNumberOfElements (inputValue); - foutE = mxCreateNumericMatrix(1,std::max((int)numberOfHandles,1),mxUINT32_CLASS, mxREAL); inputULong= (uint32_T *) mxGetData (foutE); mxClassID mxid =mxGetClassID(inputValue); - - //mexPrintf("Class ID %d\n", mxid ); - //mexPrintf(mxGetClassName(inputValue)); - switch(mxid) { - case mxDOUBLE_CLASS: - inputDouble = (double *) mxGetPr ( inputValue); - for (size_t i=0; i< numberOfHandles; ++i) { - inputULong[i] = (uint32_T) inputDouble[i]; - } - break; - case mxSINGLE_CLASS: - inputFloat = (float *) mxGetData (inputValue); - for (size_t i=0; i< numberOfHandles; ++i) { - inputULong[i] = (uint32_T) inputFloat[i]; - } - break; - case mxLOGICAL_CLASS: - inputBool = (bool *) mxGetData (inputValue); - for (size_t i=0; i< numberOfHandles; ++i) { - inputULong[i] = (uint32_T) inputBool[i]; - } - break; - case mxINT8_CLASS: - inputChar = (int8_T *) mxGetData (inputValue); - for (size_t i=0; i< numberOfHandles; ++i) { - inputULong[i] = (uint32_T) inputChar[i]; - } - break; - case mxUINT8_CLASS: - inputUChar = (uint8_T *) mxGetData (inputValue); - for (size_t i=0; i< numberOfHandles; ++i) { - inputULong[i] = (uint32_T) inputUChar[i]; - } - break; - case mxINT16_CLASS: - inputShort = (int16_T *) mxGetData (inputValue); - for (size_t i=0; i< numberOfHandles; ++i) { - inputULong[i] = (uint32_T) inputShort[i]; - } - break; - case mxUINT16_CLASS: - inputUShort = (uint16_T *) mxGetData (inputValue); - for (size_t i=0; i< numberOfHandles; ++i) { - inputULong[i] = (uint32_T) inputUShort[i]; - } - break; - case mxINT32_CLASS: - inputLong = (int32_T *) mxGetData (inputValue); - for (size_t i=0; i< numberOfHandles; ++i) { - inputULong[i] = (uint32_T) inputLong[i]; - } - break; - case mxUINT32_CLASS: - inputULong = (uint32_T *) mxGetData (inputValue); + //mexPrintf("Class ID %d\n", mxid ); + //mexPrintf(mxGetClassName(inputValue)); - break; - case mxINT64_CLASS: - inputLongLong = (int64_T *) mxGetData (inputValue); - for (size_t i=0; i< numberOfHandles; ++i) { - inputULong[i] = (uint32_T) inputLongLong[i]; - } - break; - case mxUINT64_CLASS: - inputULongLong = (uint64_T *) mxGetData (inputValue); - for (size_t i=0; i< numberOfHandles; ++i) { - inputULong[i] = (uint32_T) inputULongLong[i]; - } - break; - // Series of Strings go in a CELL + switch(mxid) + { + case mxDOUBLE_CLASS: + inputDouble = (double *) mxGetPr ( inputValue); + for (size_t i=0; i< numberOfHandles; ++i) + { + inputULong[i] = (uint32_T) inputDouble[i]; + } + break; + case mxSINGLE_CLASS: + inputFloat = (float *) mxGetData (inputValue); + for (size_t i=0; i< numberOfHandles; ++i) + { + inputULong[i] = (uint32_T) inputFloat[i]; + } + break; + case mxLOGICAL_CLASS: + inputBool = (bool *) mxGetData (inputValue); + for (size_t i=0; i< numberOfHandles; ++i) + { + inputULong[i] = (uint32_T) inputBool[i]; + } + break; + case mxINT8_CLASS: + inputChar = (int8_T *) mxGetData (inputValue); + for (size_t i=0; i< numberOfHandles; ++i) + { + inputULong[i] = (uint32_T) inputChar[i]; + } + break; + case mxUINT8_CLASS: + inputUChar = (uint8_T *) mxGetData (inputValue); + for (size_t i=0; i< numberOfHandles; ++i) + { + inputULong[i] = (uint32_T) inputUChar[i]; + } + break; + case mxINT16_CLASS: + inputShort = (int16_T *) mxGetData (inputValue); + for (size_t i=0; i< numberOfHandles; ++i) + { + inputULong[i] = (uint32_T) inputShort[i]; + } + break; + case mxUINT16_CLASS: + inputUShort = (uint16_T *) mxGetData (inputValue); + for (size_t i=0; i< numberOfHandles; ++i) + { + inputULong[i] = (uint32_T) inputUShort[i]; + } + break; + case mxINT32_CLASS: + inputLong = (int32_T *) mxGetData (inputValue); + for (size_t i=0; i< numberOfHandles; ++i) + { + inputULong[i] = (uint32_T) inputLong[i]; + } + break; + case mxUINT32_CLASS: + inputULong = (uint32_T *) mxGetData (inputValue); + + break; + case mxINT64_CLASS: + inputLongLong = (int64_T *) mxGetData (inputValue); + for (size_t i=0; i< numberOfHandles; ++i) + { + inputULong[i] = (uint32_T) inputLongLong[i]; + } + break; + case mxUINT64_CLASS: + inputULongLong = (uint64_T *) mxGetData (inputValue); + for (size_t i=0; i< numberOfHandles; ++i) + { + inputULong[i] = (uint32_T) inputULongLong[i]; + } + break; + // Series of Strings go in a CELL } - - //for (size_t i=0; i //#include //#endif @@ -18,3512 +18,3751 @@ using namespace NS_MOCHA; void macchinettaFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { - - if (nrhs <1) { + + if (nrhs <1) + { mexPrintf("Input argument not entered. \n"); mexPrintf("The command: mocha \'show\' will display the methods available. \n"); return; } - - if (mxIsCell(prhs[0])) { - mexPrintf("mocha message argument (1st input arg) must be a char and not a cell. \n"); - return; - } + + if (mxIsCell(prhs[0])) + { + mexPrintf("mocha message argument (1st input arg) must be a char and not a cell. \n"); + return; + } int32_T mochaIndex=-1; - if ( mxIsNumeric(prhs[0]) && !mxIsChar(prhs[0]) ) { + if ( mxIsNumeric(prhs[0]) && !mxIsChar(prhs[0]) ) + { mochaIndex= (int) mxGetScalar( prhs[0] ); - if (mochaIndex !=MONITOR_FLUSH_EVENT) { - mexPrintf("We prefer not to expose the numerical index value directly. \n"); - mexPrintf("Please use the method name (MATLAB char) as input to the first argument. \n"); - mexPrintf("The command: mocha \'show\' will display the methods available. \n"); - - mexPrintf("1st input argument Class Name: %s\n", mxGetClassName(prhs[0])); - mexPrintf("1st input argument Class ID: %d\n", mxGetClassID(prhs[0])); - mexPrintf("1st input argument to mocha must be of type char/mxCHAR_CLASS\n"); - - return; - } + if (mochaIndex !=MONITOR_FLUSH_EVENT) + { + mexPrintf("We prefer not to expose the numerical index value directly. \n"); + mexPrintf("Please use the method name (MATLAB char) as input to the first argument. \n"); + mexPrintf("The command: mocha \'show\' will display the methods available. \n"); + + mexPrintf("1st input argument Class Name: %s\n", mxGetClassName(prhs[0])); + mexPrintf("1st input argument Class ID: %d\n", mxGetClassID(prhs[0])); + mexPrintf("1st input argument to mocha must be of type char/mxCHAR_CLASS\n"); + + return; + } } /* if (strcmp (mxGetClassName(prhs[0]),"string") ==0 ) { - - mxChar * mess2 = static_cast(mxGetData(prhs[0])); - - mData = (mxArray *) mess2; + + mxChar * mess2 = static_cast(mxGetData(prhs[0])); + + mData = (mxArray *) mess2; messLength = METHOD_NAME_MAX_SIZE+1; - + if ( mxGetString(mData, mess, messLength) == 1) { - mexPrintf ("mxGetString has failed; input is not of mxChar type\n"); - } - - mexPrintf ("mocha does not support string/mxSTRING_CLASS as input\n"); - mexPrintf ("Please use char/mxCHAR_CLASS as data type for input\n"); - return; - } + mexPrintf ("mxGetString has failed; input is not of mxChar type\n"); + } + + mexPrintf ("mocha does not support string/mxSTRING_CLASS as input\n"); + mexPrintf ("Please use char/mxCHAR_CLASS as data type for input\n"); + return; + } else { - */ + */ //message - - //Trick to handle mocha(402) input from monitor Action - - messLength = METHOD_NAME_MAX_SIZE+1; - if (mxIsChar(prhs[0]) ) { - mData = (mxArray *) prhs[0]; - mxGetString(mData, mess, messLength); - } - else if (mochaIndex ==MONITOR_FLUSH_EVENT){ - strcpy(mess,"monitorflushevent"); - } - - + + //Trick to handle mocha(402) input from monitor Action + + messLength = METHOD_NAME_MAX_SIZE+1; + if (mxIsChar(prhs[0]) ) + { + mData = (mxArray *) prhs[0]; + mxGetString(mData, mess, messLength); + } + else if (mochaIndex ==MONITOR_FLUSH_EVENT) + { + strcpy(mess,"monitorflushevent"); + } + + char messOriginal[METHOD_NAME_MAX_SIZE+1]; strcpy(messOriginal,mess); - - //mexPrintf("message mess:%s\n", mess); - //mexPrintf("message orig:%s\n", messOriginal); - + + //mexPrintf("message mess:%s\n", mess); + //mexPrintf("message orig:%s\n", messOriginal); + //remove leadingTrailing Blanks const char * _mess=mess; cafe.getHandleHelper().removeLeadingAndTrailingSpaces(_mess,mess); std::string messString = mess; - + std::transform(messString.begin(), messString.end(), messString.begin(), ::tolower); strcpy(mess,messString.c_str()); - - - if(!isCAInitialized && strcmp(mess,"monitorflushevent")!=0 && strcmp(mess,"close")!=0) { + + + if(!isCAInitialized && strcmp(mess,"monitorflushevent")!=0 && strcmp(mess,"close")!=0) + { NS_MOCHA::msInsert(); NS_MOCHA::mdtInsert(); - - // print_out_by(ms); + + // print_out_by(ms); } - else if (!isCAInitialized && strcmp(mess,"close")==0) { + else if (!isCAInitialized && strcmp(mess,"close")==0) + { mexPrintf("The CAFEteria was never opened! \n"); return; } - if(!isCAInitialized && strcmp(mess,"close")!=0){ - - - if (!mexIsLocked()) { - mexLock(); - } - - //Remove PyCafe component should cafe have been compiled with pyCafe - //This flag controls import_PyCafe for when PyCafe_api.h is used - //If PyCafe.h is not used then you must link to non-Py cafe C++ librarry - - - //if ( cafe.setPyCafe(true) ) { - // mexPrintf("Py_Initialize \n"); - // Py_Initialize(); - //} - - #ifdef HAVE_PYTHON_H - //cafe.setPyCafe(true); - //dlopen("libpython2.6.so", RTLD_GLOBAL|RTLD_LAZY); - //dlopen("libpython3.5m.so", RTLD_GLOBAL|RTLD_LAZY); - mexPrintf("HAVE_PYTHON_H \n"); - //Py_Initialize(); - //mexPrintf("Py_Initialize from MATLAB \n"); - #endif - + if(!isCAInitialized && strcmp(mess,"close")!=0) + { + + + if (!mexIsLocked()) + { + mexLock(); + } + + //Remove PyCafe component should cafe have been compiled with pyCafe + //This flag controls import_PyCafe for when PyCafe_api.h is used + //If PyCafe.h is not used then you must link to non-Py cafe C++ librarry + + + //if ( cafe.setPyCafe(true) ) { + // mexPrintf("Py_Initialize \n"); + // Py_Initialize(); + //} + +#ifdef HAVE_PYTHON_H + //cafe.setPyCafe(true); + //dlopen("libpython2.6.so", RTLD_GLOBAL|RTLD_LAZY); + //dlopen("libpython3.5m.so", RTLD_GLOBAL|RTLD_LAZY); + mexPrintf("HAVE_PYTHON_H \n"); + //Py_Initialize(); + //mexPrintf("Py_Initialize from MATLAB \n"); +#endif + cafe.init(); - - //#ifdef HAVE_PYTHON_H - // cafe.loadSFGroups("VA"); - //#endif - + + //#ifdef HAVE_PYTHON_H + // cafe.loadSFGroups("VA"); + //#endif + isCAInitialized=true; - - if (strcmp(mess,"monitorflushevent")==0 ) { - mexPrintf("The CAFEteria is now open due to an outstanding monitorFlushEvent action (probably from a timer) \n"); - } - // else { - //mexPrintf("The CAFEteria is now open \n"); - // } + + if (strcmp(mess,"monitorflushevent")==0 ) + { + mexPrintf("The CAFEteria is now open due to an outstanding monitorFlushEvent action (probably from a timer) \n"); + } + // else { + //mexPrintf("The CAFEteria is now open \n"); + // } } - - + + mochaccino_set_by_name & name_index = ms.get (); mochaccino_set_by_name::iterator it_name; - - - //mexPrintf("message %s\n", mess); - //mexPrintf("message %s\n", messString.c_str()); - + + + //mexPrintf("message %s\n", mess); + //mexPrintf("message %s\n", messString.c_str()); + it_name = name_index.find(mess); - if ( (it_name) != name_index.end() ) { - mochaIndex=(*it_name).id; - } + if ( (it_name) != name_index.end() ) + { + mochaIndex=(*it_name).id; + } int32_T mdtIndex=MOCHA_NATIVE; int32_T mochaIndexOriginal=mochaIndex; bool cacheFlag=false; - bool sgTimeoutFlag=false; - bool extendedPV=false; - - size_t numberOfHandlesGetAsyn=0; + bool sgTimeoutFlag=false; + bool extendedPV=false; + + size_t numberOfHandlesGetAsyn=0; size_t nh=0; size_t nv=0; //Wrapper methods - switch(mochaIndex) { - case GET_INT8: - mochaIndex=GET; - mdtIndex=MOCHA_CHAR; - break; - case GET_INT16: - mochaIndex=GET; - mdtIndex=MOCHA_SHORT; - break; - case GET_INT32: - mochaIndex=GET; - mdtIndex=MOCHA_INT; - break; - case GET_INT64: - mochaIndex=GET; - mdtIndex=MOCHA_LONG; - break; - case GET_UINT8: - mochaIndex=GET; - mdtIndex=MOCHA_UCHAR; - break; - case GET_UINT16: - mochaIndex=GET; - mdtIndex=MOCHA_USHORT; - break; - case GET_UINT32: - mochaIndex=GET; - mdtIndex=MOCHA_UINT; - break; - case GET_UINT64: - mochaIndex=GET; - mdtIndex=MOCHA_ULONG; - break; - case GET_FLOAT: - mochaIndex=GET; - mdtIndex=MOCHA_FLOAT; - break; - case GET_DOUBLE: - mochaIndex=GET; - mdtIndex=MOCHA_DOUBLE; - break; - case GET_STRING: - mochaIndex=GET; - mdtIndex=MOCHA_STRING; - break; - case GET_CELL_ARRAY_CACHE: - mochaIndex=GET_CELL_ARRAY; - cacheFlag=true; - break; - case GET_SCALAR_ARRAY_CACHE: - mochaIndex=GET_SCALAR_ARRAY; - cacheFlag=true; - break; - case GET_STRUCT_ARRAY_CACHE: - mochaIndex=GET_STRUCT_ARRAY; - cacheFlag=true; - break; - case GET_STRUCT_CACHE: - mochaIndex=GET_STRUCT; - cacheFlag=true; - break; - case GET_GROUP_CACHE: - mochaIndex=GET_GROUP; - cacheFlag=true; - break; - - - case GET_STRUCT_EXTENDED: - mochaIndex=GET_STRUCT; - extendedPV=true; - break; - - case GET_STRUCT_EXTENDED_ARRAY: - mochaIndex=GET_STRUCT_ARRAY; - extendedPV=true; - break; - - case GET_GROUP_EXTENDED: - mochaIndex=GET_GROUP; - extendedPV=true; - break; - - case GET_STRUCT_EXTENDED_ARRAY_CACHE: - mochaIndex=GET_STRUCT_ARRAY; - cacheFlag=true; - extendedPV=true; - break; - case GET_STRUCT_EXTENDED_CACHE: - mochaIndex=GET_STRUCT; - cacheFlag=true; - extendedPV=true; - break; - case GET_GROUP_EXTENDED_CACHE: - mochaIndex=GET_GROUP; - cacheFlag=true; - extendedPV=true; - break; - - case GET_WF_AS_STRING_CACHE: - mochaIndex=GET_WF_AS_STRING; - cacheFlag=true; - break; - - case GET_CACHE: - mochaIndex=GET; - cacheFlag=true; - break; - case GET_CTRL_CACHE: - mochaIndex=GET_CTRL_STRUCT; - cacheFlag=true; - break; - case GET_NELEM_CACHE: - mochaIndex=GET_NELEM_REQUEST; - cacheFlag=true; - break; - case GET_ASYN: - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, handle/pv \n", nrhs); - return; - } - if (mxIsChar(prhs[1]) ) { - numberOfHandlesGetAsyn=1; + switch(mochaIndex) + { + case GET_INT8: + mochaIndex=GET; + mdtIndex=MOCHA_CHAR; + break; + case GET_INT16: + mochaIndex=GET; + mdtIndex=MOCHA_SHORT; + break; + case GET_INT32: + mochaIndex=GET; + mdtIndex=MOCHA_INT; + break; + case GET_INT64: + mochaIndex=GET; + mdtIndex=MOCHA_LONG; + break; + case GET_UINT8: + mochaIndex=GET; + mdtIndex=MOCHA_UCHAR; + break; + case GET_UINT16: + mochaIndex=GET; + mdtIndex=MOCHA_USHORT; + break; + case GET_UINT32: + mochaIndex=GET; + mdtIndex=MOCHA_UINT; + break; + case GET_UINT64: + mochaIndex=GET; + mdtIndex=MOCHA_ULONG; + break; + case GET_FLOAT: + mochaIndex=GET; + mdtIndex=MOCHA_FLOAT; + break; + case GET_DOUBLE: + mochaIndex=GET; + mdtIndex=MOCHA_DOUBLE; + break; + case GET_STRING: + mochaIndex=GET; + mdtIndex=MOCHA_STRING; + break; + case GET_CELL_ARRAY_CACHE: + mochaIndex=GET_CELL_ARRAY; + cacheFlag=true; + break; + case GET_SCALAR_ARRAY_CACHE: + mochaIndex=GET_SCALAR_ARRAY; + cacheFlag=true; + break; + case GET_STRUCT_ARRAY_CACHE: + mochaIndex=GET_STRUCT_ARRAY; + cacheFlag=true; + break; + case GET_STRUCT_CACHE: + mochaIndex=GET_STRUCT; + cacheFlag=true; + break; + case GET_GROUP_CACHE: + mochaIndex=GET_GROUP; + cacheFlag=true; + break; + + + case GET_STRUCT_EXTENDED: + mochaIndex=GET_STRUCT; + extendedPV=true; + break; + + case GET_STRUCT_EXTENDED_ARRAY: + mochaIndex=GET_STRUCT_ARRAY; + extendedPV=true; + break; + + case GET_GROUP_EXTENDED: + mochaIndex=GET_GROUP; + extendedPV=true; + break; + + case GET_STRUCT_EXTENDED_ARRAY_CACHE: + mochaIndex=GET_STRUCT_ARRAY; + cacheFlag=true; + extendedPV=true; + break; + case GET_STRUCT_EXTENDED_CACHE: + mochaIndex=GET_STRUCT; + cacheFlag=true; + extendedPV=true; + break; + case GET_GROUP_EXTENDED_CACHE: + mochaIndex=GET_GROUP; + cacheFlag=true; + extendedPV=true; + break; + + case GET_WF_AS_STRING_CACHE: + mochaIndex=GET_WF_AS_STRING; + cacheFlag=true; + break; + + case GET_CACHE: + mochaIndex=GET; + cacheFlag=true; + break; + case GET_CTRL_CACHE: + mochaIndex=GET_CTRL_STRUCT; + cacheFlag=true; + break; + case GET_NELEM_CACHE: + mochaIndex=GET_NELEM_REQUEST; + cacheFlag=true; + break; + case GET_ASYN: + if (nrhs<2) + { + mexPrintf("Invalid Number of argument %d. Input: message, handle/pv \n", nrhs); + return; + } + if (mxIsChar(prhs[1]) ) + { + numberOfHandlesGetAsyn=1; + } + else + { + numberOfHandlesGetAsyn=mxGetNumberOfElements (prhs[1]); + } + if (numberOfHandlesGetAsyn >1) + { + mochaIndex=GET_ARRAY_ASYN; + } + break; + + case SET: + + + if (nrhs<3) + { + mexPrintf("Invalid Number of argument %d. Input: 'set', handle/pv, data \n", nrhs); + return; + } + + + if (mxIsChar(prhs[1])) + { + nh=1; + } + else + { + nh=mxGetNumberOfElements (prhs[1]); + } + if (mxIsChar(prhs[2])) + { + nv=1; + } + else + { + nv=mxGetNumberOfElements (prhs[2]); + } + + ///mexPrintf("nh=%d, nvalues=%d, nargin=%d\n", nh,nv, nrhs); + if (nh>1 && nh==nv && nrhs==3) + { + mochaIndex=SET_SCALAR_ARRAY; + //mexPrintf("SET_SCALAR_ARRAY\n"); + } + else if (nh>1 && nh==(nrhs-2)) + { + mochaIndex=SET_STRUCT_ARRAY; + //mexPrintf("SET_STRUCT_ARRAY\n"); + } + else if (nh>1) + { + mochaIndex=SET_STRUCT_ARRAY; + mexPrintf("Inbalance between number of handles and input data\n"); + //mexPrintf("SET_STRUCT_ARRAY\n"); + } + + break; + + case SET_NELEM_CACHE: + mochaIndex=SET_NELEM; + cacheFlag=true; + break; + + case OPEN: + if (nrhs>1) + { + if( mxIsCell(prhs[1]) ) + { + mochaIndex=OPEN_ARRAY; } - else { - numberOfHandlesGetAsyn=mxGetNumberOfElements (prhs[1]); - } - if (numberOfHandlesGetAsyn >1) { - mochaIndex=GET_ARRAY_ASYN; - } - break; - - case SET: - - - if (nrhs<3) { - mexPrintf("Invalid Number of argument %d. Input: 'set', handle/pv, data \n", nrhs); - return; + } + break; + + case CLOSE: + if (nrhs>1) + { + if( mxGetNumberOfElements (prhs[1]) >1 ) + { + mochaIndex=CLOSE_ARRAY; } - - - if (mxIsChar(prhs[1])) { - nh=1; - } - else{ - nh=mxGetNumberOfElements (prhs[1]); - } - if (mxIsChar(prhs[2])) { - nv=1; - } - else{ - nv=mxGetNumberOfElements (prhs[2]); - } - - ///mexPrintf("nh=%d, nvalues=%d, nargin=%d\n", nh,nv, nrhs); - if (nh>1 && nh==nv && nrhs==3) { - mochaIndex=SET_SCALAR_ARRAY; - //mexPrintf("SET_SCALAR_ARRAY\n"); - } - else if (nh>1 && nh==(nrhs-2)) { - mochaIndex=SET_STRUCT_ARRAY; - //mexPrintf("SET_STRUCT_ARRAY\n"); - } - else if (nh>1) { - mochaIndex=SET_STRUCT_ARRAY; - mexPrintf("Inbalance between number of handles and input data\n"); - //mexPrintf("SET_STRUCT_ARRAY\n"); - } - - break; - - case SET_NELEM_CACHE: - mochaIndex=SET_NELEM; - cacheFlag=true; - break; - - case OPEN: - if (nrhs>1) { - if( mxIsCell(prhs[1]) ) { - mochaIndex=OPEN_ARRAY; - } - } - break; - - case CLOSE: - if (nrhs>1) { - if( mxGetNumberOfElements (prhs[1]) >1 ) { - mochaIndex=CLOSE_ARRAY; - } - } - break; - - case OPEN_WAIT_WITH_TIME: - if (nrhs<2) { - mochaIndex=OPEN_WAIT_TIME_TO_DEFAULT; - //cafe.channelOpenPolicy.setWhenToFlushSendBuffer(FLUSH_AFTER_EACH_CHANNEL_CREATION); - //cafe.channelOpenPolicy.setFlushSendBufferKind(WITH_PEND_EVENT); - } - break; - - default: - break; + } + break; + + case OPEN_WAIT_WITH_TIME: + if (nrhs<2) + { + mochaIndex=OPEN_WAIT_TIME_TO_DEFAULT; + //cafe.channelOpenPolicy.setWhenToFlushSendBuffer(FLUSH_AFTER_EACH_CHANNEL_CREATION); + //cafe.channelOpenPolicy.setFlushSendBufferKind(WITH_PEND_EVENT); + } + break; + + default: + break; } //Test again for GET - //Wrapper methods - switch(mochaIndex) { - case GET: - - if (mxIsChar(prhs[1])) { - nh=1; + //Wrapper methods + switch(mochaIndex) + { + case GET: + + if (mxIsChar(prhs[1])) + { + nh=1; + } + else + { + + nh=mxGetNumberOfElements (prhs[1]); + + } + + ///mexPrintf("nh=%d, nargin=%d\n", nh, nrhs); + if (nrhs>3) + { + mexPrintf("Usage: get [pv] (optional)\n"); + return; + } + if (nh>1) + { + mochaIndex=GET_SCALAR_ARRAY; + //mexPrintf("GET_SCALAR_ARRAY\n"); + if(nrhs==3 &&mxIsChar(prhs[nrhs-1])) + { + mdtIndex=NS_MOCHA::getMdtIndex(prhs[nrhs-1]); } - else{ - - nh=mxGetNumberOfElements (prhs[1]); - - } - - ///mexPrintf("nh=%d, nargin=%d\n", nh, nrhs); - if (nrhs>3) { - mexPrintf("Usage: get [pv] (optional)\n"); - return; - } - if (nh>1) { - mochaIndex=GET_SCALAR_ARRAY; - //mexPrintf("GET_SCALAR_ARRAY\n"); - if(nrhs==3 &&mxIsChar(prhs[nrhs-1])) { - mdtIndex=NS_MOCHA::getMdtIndex(prhs[nrhs-1]); - } - //else { - //mexPrintf("3rd input argument giving the must be a string\n"); - //} - - //mexPrintf("GET_SCALAR_ARRAY\n"); - } - break; - - case GET_STRUCT: - if (mxIsChar(prhs[1])) { - nh=1; + //else { + //mexPrintf("3rd input argument giving the must be a string\n"); + //} + + //mexPrintf("GET_SCALAR_ARRAY\n"); + } + break; + + case GET_STRUCT: + if (mxIsChar(prhs[1])) + { + nh=1; + } + else + { + nh=mxGetNumberOfElements (prhs[1]); + } + + ///mexPrintf("nh=%d, nargin=%d\n", nh, nrhs); + if (nrhs>3) + { + mexPrintf("Usage: get [pv] (optional)\n"); + return; + } + if (nh>1) + { + mochaIndex=GET_STRUCT_ARRAY; + //mexPrintf("GET_STRUCT_ARRAY\n"); + if(nrhs==3 &&mxIsChar(prhs[nrhs-1])) + { + mdtIndex=NS_MOCHA::getMdtIndex(prhs[nrhs-1]); } - else{ - nh=mxGetNumberOfElements (prhs[1]); - } - - ///mexPrintf("nh=%d, nargin=%d\n", nh, nrhs); - if (nrhs>3) { - mexPrintf("Usage: get [pv] (optional)\n"); - return; - } - if (nh>1) { - mochaIndex=GET_STRUCT_ARRAY; - //mexPrintf("GET_STRUCT_ARRAY\n"); - if(nrhs==3 &&mxIsChar(prhs[nrhs-1])) { - mdtIndex=NS_MOCHA::getMdtIndex(prhs[nrhs-1]); - } - //else { - //mexPrintf("3rd input argument giving the must be a string\n"); - //} - } - - break; - } + //else { + //mexPrintf("3rd input argument giving the must be a string\n"); + //} + } + + break; + } // The Big Switch - switch (mochaIndex) { + switch (mochaIndex) + { - case TEST: - mexPrintf("mocha mex file is active\n"); - break; + case TEST: + mexPrintf("mocha mex file is active\n"); + break; - case MOCHA_VERSION: - plhs[0]=mxCreateString((char *) "mocha-1.8.0 : 14 December 2018"); - break; + case MOCHA_VERSION: + plhs[0]=mxCreateString((char *) "mocha-1.8.0 : 14 December 2018"); + break; - case SHOW: - //print_out_by(ms); - for (it_name=name_index.begin(); it_name != name_index.end(); ++it_name) { - mexPrintf("%s\n", ((*it_name).name).c_str()); - } - break; - - case CA_POLL: - cafe._ca_poll(); - break; - - case MEX_UNLOCK: - - if (!mexIsLocked()) { - mexUnlock(); - } - break; - - case SET_PUT_PREPARE: + case SHOW: + //print_out_by(ms); + for (it_name=name_index.begin(); it_name != name_index.end(); ++it_name) { - - - if (nrhs<2) { - mexPrintf("Invalid Number of argument(s) %d. Input: setPutPrepare, handle(s) or handleArray \n", nrhs); - return; - } - - - size_t numberOfHandles=0; - - - for (size_t j=1; j dhV; - vector pvV; - cafe.getHandleHelper().getHandles(dhV,pvV); - numberOfHandles=dhV.size(); - - for (size_t i=0; i< numberOfHandles; ++i) { + break; - status=cafe.getPolicy().getChannelRequestPolicyPut(dhV[i], polput); - if (status==ECAFE_INVALID_HANDLE) { - mexPrintf("SET_PUT_WAIT: Invalid handle no = %d \n", dhV[i]); - continue; - } + case CA_POLL: + cafe._ca_poll(); + break; - //mexPrintf("no wait for handle no = %d\n", handleULong[i]); - //mexPrintf("wait for handle no = %d\n", handleULong[i]); - polput.setMethodKind(WITH_CALLBACK_DEFAULT); - polput.setWaitKind(WAIT); - polput.setWhenToFlushSendBuffer(FLUSH_AFTER_EACH_MESSAGE); - cafe.getPolicy().setChannelRequestPolicyPut(dhV[i], polput); - } - - break; - } - + case MEX_UNLOCK: - for (size_t j=1; j dhV; - vector pvV; - cafe.getHandleHelper().getHandles(dhV,pvV); - numberOfHandles=dhV.size(); - - for (size_t i=0; i< numberOfHandles; ++i) { + break; - status=cafe.getPolicy().getChannelRequestPolicyPut(dhV[i], polput); - if (status==ECAFE_INVALID_HANDLE) { - mexPrintf("SET_PUT_NOWAIT: Invalid handle no = %d \n", dhV[i]); - continue; - } - - //mexPrintf("no wait for handle no = %d\n", handleULong[i]); - //mexPrintf("wait for handle no = %d\n", handleULong[i]); - polput.setMethodKind(WITH_CALLBACK_DEFAULT); - polput.setWaitKind(NO_WAIT); - polput.setWhenToFlushSendBuffer(FLUSH_AFTER_EACH_MESSAGE); - cafe.getPolicy().setChannelRequestPolicyPut(dhV[i], polput); - } - - break; - } + case SET_PUT_PREPARE: + { - for (size_t j=1; j dhV; - vector pvV; - cafe.getHandleHelper().getHandles(dhV,pvV); - unsigned int numberOfHandles=dhV.size(); - - if (numberOfHandles==0) {return;} - - ChannelRequestPolicy polget; - polget.setPolicy(FLUSH_AFTER_EACH_MESSAGE, WAIT, WITHOUT_CALLBACK); - - for (size_t i=0; i< numberOfHandles; ++i) { - cafe.getPolicy().setChannelRequestPolicyGet(dhV[i], polget); - } - - break; - } - case INIT_GET_SYNC_WITH_CALLBACK_DEFAULT: - { - cafe.channelRequestPolicyMasterGet.setPolicy(FLUSH_AFTER_EACH_MESSAGE, WAIT, WITH_CALLBACK_DEFAULT); - - vector dhV; - vector pvV; - cafe.getHandleHelper().getHandles(dhV,pvV); - unsigned int numberOfHandles=dhV.size(); - - if (numberOfHandles==0) {return;} - - ChannelRequestPolicy polget; - polget.setPolicy(FLUSH_AFTER_EACH_MESSAGE, WAIT, WITH_CALLBACK_DEFAULT); - - for (size_t i=0; i< numberOfHandles; ++i) { - cafe.getPolicy().setChannelRequestPolicyGet(dhV[i], polget); - } - - break; - } - - case OPEN_NOWAIT: - //cafe.channelOpenPolicy.setWhenToFlushSendBuffer(FLUSH_DESIGNATED_TO_CLIENT); - //cafe.channelOpenPolicy.setFlushSendBufferKind(WITH_PEND_EVENT); - cafe.openPrepare(); - - break; - - case OPEN_WAIT: - cafe.channelOpenPolicy.setWhenToFlushSendBuffer(FLUSH_AFTER_EACH_CHANNEL_CREATION); - cafe.channelOpenPolicy.setFlushSendBufferKind(WITH_PEND_EVENT); - - break; - - - case OPEN_NOW: - //cafe.channelOpenPolicy.flushSendBufferNow(); - //cafe.channelOpenPolicy.setWhenToFlushSendBuffer(FLUSH_AFTER_EACH_CHANNEL_CREATION); - //cafe.channelOpenPolicy.setFlushSendBufferKind(WITH_PEND_EVENT); - cafe.openNow(); - - break; - - //change open method to with pend_event - for single opens that wish to pend - case OPEN_WAIT_WITH_TIME: - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, timeout \n", nrhs); - return; - } - - - if (nrhs>1) { - if (!mxIsNumeric(prhs[1]) ) { - mexPrintf("Timeout does not have a numeric value \n"); - return; - } - - - cafe.channelOpenPolicy.setTimeout(mxGetScalar(prhs[1])); - //cafe.channelOpenPolicy.setWhenToFlushSendBuffer(FLUSH_AFTER_EACH_CHANNEL_CREATION); - //cafe.channelOpenPolicy.setFlushSendBufferKind(WITH_PEND_EVENT); - - } - - break; - case OPEN_WAIT_TIME_TO_DEFAULT: - if (nrhs>1) { - mexPrintf("Ignoring number of arguments %d\n", nrhs); - mexPrintf("This method resets open wait time to default value\n"); - } - - - plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL); - doubleArray = (double *) mxGetPr (plhs[0]); - doubleArray[0]= cafe.channelOpenPolicy.setTimeoutToDefault(); - - - break; + size_t numberOfHandles=0; - case OPEN_NOW_AND_WAIT: - - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, timeout \n", nrhs); - return; - } + for (size_t j=1; j1) { - if (!mxIsNumeric(prhs[1]) ) { - mexPrintf("Timeout does not have a numeric value \n"); - return; - } - - //Get Timeput - //double tPrevious=cafe.channelOpenPolicy.getTimeout(); - //cafe.channelOpenPolicy.setTimeout(mxGetScalar(prhs[1])); - //cafe.channelOpenPolicy.flushSendBufferNow(); - //reset - //cafe.channelOpenPolicy.setWhenToFlushSendBuffer(FLUSH_NOW); - //cafe.channelOpenPolicy.setFlushSendBufferKind(WITH_PEND_EVENT); - - //Set to previous - //cafe.channelOpenPolicy.setTimeoutToDefault(); - //cafe.channelOpenPolicy.setTimeout(tPrevious); - - cafe.openNowAndWait(mxGetScalar(prhs[1])); - } - break; - - - case GET_OPEN_WAIT_TIME: - if (nrhs>1) { - mexPrintf("Ignoring number of arguments %d\n", nrhs); - mexPrintf("This method returns the current open wait time value\n"); - } - - plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL); - doubleArray = (double *) mxGetPr (plhs[0]); - doubleArray[0]= cafe.channelOpenPolicy.getTimeout(); - break; - - case WITH_EXCEPTIONS: - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, bool \n", nrhs); - return; - } - - if( !mxIsLogical(prhs[1]) ) { - mexPrintf("2nd input argument must be of Matlab type Logical, i.e.true/false \n" ); - return; - } - - - //withExceptions = mxGetLogicals (prhs[1]); - withExceptions = mxIsLogicalScalarTrue (prhs[1]); - - break; - - - case HAVE_EXCEPTIONS: - - plhs[0] = mxCreateNumericMatrix(1,1,mxLOGICAL_CLASS,mxREAL); - logicalData = (mxLogical *) mxGetData (plhs[0]); - logicalData[0]=withExceptions; - - break; - - case SEND_NOW: - ca_flush_io(); - break; - - - case OPEN_ARRAY: - { - - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message Array, pv Output: handle Array \n", nrhs); - return; - } - - if( !mxIsCell(prhs[1]) ) { - mexPrintf("Process Variable names must be in a cell. \n" ); - return; - } - - size_t numberOfHandles=mxGetNumberOfElements (prhs[1]); - - if(numberOfHandles==0) { - mexPrintf("ERROR: MISSING INPUT \n"); - return; - } - - vector vstr; - vstr.reserve(numberOfHandles); - - for (size_t i=0; i< numberOfHandles; ++i) { - - mxArray * newCell = mxGetCell(prhs[1],i); - - if (mxIsChar(newCell) ) { - - //message pvname - xData = (mxArray *) newCell; - - pvLength = PVNAME_MAX_SIZE+1; - mxGetString(xData, pv, pvLength); - vstr.push_back(pv); - } - else { - - plhs[0] = mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); - ulongArray = (uint32_T *) mxGetData (plhs[0]); - ulongArray[0]=0; - mexPrintf("ERROR READING INPUT, ELEMENT %d of %d IS NOT A mxCHAR \n", i, numberOfHandles); - return; - } - } - - - vector vuint32=NS_MOCHA::openArray(vstr); - - - plhs[0] = mxCreateNumericMatrix(1,vuint32.size(),mxUINT32_CLASS,mxREAL); - ulongArray = (uint32_T *) mxGetData (plhs[0]); - for (size_t i=0; i::signaling_NaN(); - - groupStatus[0]=ECAFE_UNKNOWN_GROUP; - - return; - } - - mdtIndex=MOCHA_NATIVE; - - if (nrhs>2) { - //ischar? - if (!mxIsChar(prhs[2]) ) { - mexPrintf("3rd input argument must be a char \n"); - return; + if (status==ECAFE_INVALID_HANDLE) + { + mexPrintf("SET_PUT_PREPARE: Invalid handle no = %d \n", handleULong[i]); + continue; } - mdtIndex=getMdtIndex(prhs[2]); + + //mexPrintf("no wait for handle no = %d\n", handleULong[i]); + polput.setMethodKind(WITH_CALLBACK_DEFAULT); + polput.setWaitKind(NO_WAIT); + polput.setWhenToFlushSendBuffer(FLUSH_DESIGNATED_TO_CLIENT); + cafe.getPolicy().setChannelRequestPolicyPut(handleULong[i], polput); } - + } - int32_T mdtIndexOriginal=mdtIndex; + break; + } + case SET_PUT_WAIT: + { + size_t numberOfHandles=0; + ChannelRequestPolicy polput; - PVGroup pvgroup; + if (nrhs<2) + { + //mexPrintf("Invalid Number of argument(s) %d. Input: setNoWait, handle(s) or handleArray \n", nrhs); + //return; + vector dhV; + vector pvV; + cafe.getHandleHelper().getHandles(dhV,pvV); + numberOfHandles=dhV.size(); - status=cafe.groupAttach(ghandle, pvgroup); - - PVDataHolder * du; - unsigned int NPV=0; - bool isGroupTimeout=false; + for (size_t i=0; i< numberOfHandles; ++i) + { - if (status!=ECAFE_UNKNOWN_GROUP && status != ECAFE_EMPTY_GROUP) { + status=cafe.getPolicy().getChannelRequestPolicyPut(dhV[i], polput); + if (status==ECAFE_INVALID_HANDLE) + { + mexPrintf("SET_PUT_WAIT: Invalid handle no = %d \n", dhV[i]); + continue; + } - - if (cacheFlag) { - status=cafe.groupGetCache(ghandle, pvgroup); - } - else { - status=cafe.groupGet(ghandle, pvgroup); - } - - - // statusGroup != ICAFE_SUCCESS when one or more channels accesses fail - if ( pvgroup.getStatusGroup() != ICAFE_SUCCESS ) { - for (mwSignedIndex i=0; i dhV; + vector pvV; + cafe.getHandleHelper().getHandles(dhV,pvV); + numberOfHandles=dhV.size(); + + for (size_t i=0; i< numberOfHandles; ++i) + { + + status=cafe.getPolicy().getChannelRequestPolicyPut(dhV[i], polput); + if (status==ECAFE_INVALID_HANDLE) + { + mexPrintf("SET_PUT_NOWAIT: Invalid handle no = %d \n", dhV[i]); + continue; + } + + //mexPrintf("no wait for handle no = %d\n", handleULong[i]); + //mexPrintf("wait for handle no = %d\n", handleULong[i]); + polput.setMethodKind(WITH_CALLBACK_DEFAULT); + polput.setWaitKind(NO_WAIT); + polput.setWhenToFlushSendBuffer(FLUSH_AFTER_EACH_MESSAGE); + cafe.getPolicy().setChannelRequestPolicyPut(dhV[i], polput); + } + + break; + } + + + for (size_t j=1; j dhV; + vector pvV; + cafe.getHandleHelper().getHandles(dhV,pvV); + unsigned int numberOfHandles=dhV.size(); + + if (numberOfHandles==0) + { + return; + } + + ChannelRequestPolicy polget; + polget.setPolicy(FLUSH_AFTER_EACH_MESSAGE, WAIT, WITHOUT_CALLBACK); + + for (size_t i=0; i< numberOfHandles; ++i) + { + cafe.getPolicy().setChannelRequestPolicyGet(dhV[i], polget); + } + + break; + } + case INIT_GET_SYNC_WITH_CALLBACK_DEFAULT: + { + cafe.channelRequestPolicyMasterGet.setPolicy(FLUSH_AFTER_EACH_MESSAGE, WAIT, WITH_CALLBACK_DEFAULT); + + vector dhV; + vector pvV; + cafe.getHandleHelper().getHandles(dhV,pvV); + unsigned int numberOfHandles=dhV.size(); + + if (numberOfHandles==0) + { + return; + } + + ChannelRequestPolicy polget; + polget.setPolicy(FLUSH_AFTER_EACH_MESSAGE, WAIT, WITH_CALLBACK_DEFAULT); + + for (size_t i=0; i< numberOfHandles; ++i) + { + cafe.getPolicy().setChannelRequestPolicyGet(dhV[i], polget); + } + + break; + } + + case OPEN_NOWAIT: + //cafe.channelOpenPolicy.setWhenToFlushSendBuffer(FLUSH_DESIGNATED_TO_CLIENT); + //cafe.channelOpenPolicy.setFlushSendBufferKind(WITH_PEND_EVENT); + cafe.openPrepare(); + + break; + + case OPEN_WAIT: + cafe.channelOpenPolicy.setWhenToFlushSendBuffer(FLUSH_AFTER_EACH_CHANNEL_CREATION); + cafe.channelOpenPolicy.setFlushSendBufferKind(WITH_PEND_EVENT); + + break; + + + case OPEN_NOW: + //cafe.channelOpenPolicy.flushSendBufferNow(); + //cafe.channelOpenPolicy.setWhenToFlushSendBuffer(FLUSH_AFTER_EACH_CHANNEL_CREATION); + //cafe.channelOpenPolicy.setFlushSendBufferKind(WITH_PEND_EVENT); + cafe.openNow(); + + break; + + //change open method to with pend_event - for single opens that wish to pend + case OPEN_WAIT_WITH_TIME: + if (nrhs<2) + { + mexPrintf("Invalid Number of argument %d. Input: message, timeout \n", nrhs); + return; + } + + + if (nrhs>1) + { + if (!mxIsNumeric(prhs[1]) ) + { + mexPrintf("Timeout does not have a numeric value \n"); + return; + } + + + cafe.channelOpenPolicy.setTimeout(mxGetScalar(prhs[1])); + //cafe.channelOpenPolicy.setWhenToFlushSendBuffer(FLUSH_AFTER_EACH_CHANNEL_CREATION); + //cafe.channelOpenPolicy.setFlushSendBufferKind(WITH_PEND_EVENT); + + } + + break; + + + case OPEN_WAIT_TIME_TO_DEFAULT: + if (nrhs>1) + { + mexPrintf("Ignoring number of arguments %d\n", nrhs); + mexPrintf("This method resets open wait time to default value\n"); + } + + + plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL); + doubleArray = (double *) mxGetPr (plhs[0]); + doubleArray[0]= cafe.channelOpenPolicy.setTimeoutToDefault(); + + + break; + + + case OPEN_NOW_AND_WAIT: + + if (nrhs<2) + { + mexPrintf("Invalid Number of argument %d. Input: message, timeout \n", nrhs); + return; + } + + if (nrhs>1) + { + if (!mxIsNumeric(prhs[1]) ) + { + mexPrintf("Timeout does not have a numeric value \n"); + return; + } + + //Get Timeput + //double tPrevious=cafe.channelOpenPolicy.getTimeout(); + //cafe.channelOpenPolicy.setTimeout(mxGetScalar(prhs[1])); + //cafe.channelOpenPolicy.flushSendBufferNow(); + //reset + //cafe.channelOpenPolicy.setWhenToFlushSendBuffer(FLUSH_NOW); + //cafe.channelOpenPolicy.setFlushSendBufferKind(WITH_PEND_EVENT); + + //Set to previous + //cafe.channelOpenPolicy.setTimeoutToDefault(); + //cafe.channelOpenPolicy.setTimeout(tPrevious); + + cafe.openNowAndWait(mxGetScalar(prhs[1])); + } + break; + + + case GET_OPEN_WAIT_TIME: + if (nrhs>1) + { + mexPrintf("Ignoring number of arguments %d\n", nrhs); + mexPrintf("This method returns the current open wait time value\n"); + } + + plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL); + doubleArray = (double *) mxGetPr (plhs[0]); + doubleArray[0]= cafe.channelOpenPolicy.getTimeout(); + break; + + case WITH_EXCEPTIONS: + if (nrhs<2) + { + mexPrintf("Invalid Number of argument %d. Input: message, bool \n", nrhs); + return; + } + + if( !mxIsLogical(prhs[1]) ) + { + mexPrintf("2nd input argument must be of Matlab type Logical, i.e.true/false \n" ); + return; + } + + + //withExceptions = mxGetLogicals (prhs[1]); + withExceptions = mxIsLogicalScalarTrue (prhs[1]); + + break; + + + case HAVE_EXCEPTIONS: + + plhs[0] = mxCreateNumericMatrix(1,1,mxLOGICAL_CLASS,mxREAL); + logicalData = (mxLogical *) mxGetData (plhs[0]); + logicalData[0]=withExceptions; + + break; + + case SEND_NOW: + ca_flush_io(); + break; + + + case OPEN_ARRAY: + { + + if (nrhs<2) + { + mexPrintf("Invalid Number of argument %d. Input: message Array, pv Output: handle Array \n", nrhs); + return; + } + + if( !mxIsCell(prhs[1]) ) + { + mexPrintf("Process Variable names must be in a cell. \n" ); + return; + } + + size_t numberOfHandles=mxGetNumberOfElements (prhs[1]); + + if(numberOfHandles==0) + { + mexPrintf("ERROR: MISSING INPUT \n"); + return; + } + + vector vstr; + vstr.reserve(numberOfHandles); + + for (size_t i=0; i< numberOfHandles; ++i) + { + + mxArray * newCell = mxGetCell(prhs[1],i); + + if (mxIsChar(newCell) ) + { + + //message pvname + xData = (mxArray *) newCell; + + pvLength = PVNAME_MAX_SIZE+1; + mxGetString(xData, pv, pvLength); + vstr.push_back(pv); + } + else + { + + plhs[0] = mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); + ulongArray = (uint32_T *) mxGetData (plhs[0]); + ulongArray[0]=0; + mexPrintf("ERROR READING INPUT, ELEMENT %d of %d IS NOT A mxCHAR \n", i, numberOfHandles); + return; + } + } + + + vector vuint32=NS_MOCHA::openArray(vstr); + + + plhs[0] = mxCreateNumericMatrix(1,vuint32.size(),mxUINT32_CLASS,mxREAL); + ulongArray = (uint32_T *) mxGetData (plhs[0]); + for (size_t i=0; i::signaling_NaN(); + + groupStatus[0]=ECAFE_UNKNOWN_GROUP; + + return; + } + + mdtIndex=MOCHA_NATIVE; + + if (nrhs>2) + { + //ischar? + if (!mxIsChar(prhs[2]) ) + { + mexPrintf("3rd input argument must be a char \n"); + return; + } + mdtIndex=getMdtIndex(prhs[2]); + } + + + int32_T mdtIndexOriginal=mdtIndex; + + PVGroup pvgroup; + + status=cafe.groupAttach(ghandle, pvgroup); + + PVDataHolder * du; + unsigned int NPV=0; + bool isGroupTimeout=false; + + if (status!=ECAFE_UNKNOWN_GROUP && status != ECAFE_EMPTY_GROUP) + { + + + if (cacheFlag) + { + status=cafe.groupGetCache(ghandle, pvgroup); + } + else + { + status=cafe.groupGet(ghandle, pvgroup); + } + + + // statusGroup != ICAFE_SUCCESS when one or more channels accesses fail + if ( pvgroup.getStatusGroup() != ICAFE_SUCCESS ) + { + for (mwSignedIndex i=0; i dhV = cafe.getHandlesFromWithinGroupV(ghandle); - du = new PVDataHolder[dhV.size()]; - if (cacheFlag) { - status=cafe.getPVArray(dhV, du); - } - else { - //status=cafe.getPVArrayCache(dhV, du); - status=cafe.getCachePVArray(dhV, du); - } - NPV=dhV.size(); - isGroupTimeout=true; - - } - } - else { - - mexPrintf("status/handle %d / %d \n", status, ghandle); - mexPrintf("Returning NaN in place of struct \n"); - - NS_MOCHA::printStatus(status); - - doubleArray[0]=numeric_limits::signaling_NaN(); - - groupStatus[0]=status; - - return; + } } - + + if (!cafe.getCafeStatus().csc.isTimeout(status) ) // OK + { + + du = pvgroup.getPVData(); + NPV= pvgroup.getNPV(); + } + else //timeout + { + mexPrintf("Info: Timeout in CAFE Group; reverting to getPVArray method\n"); + vector dhV = cafe.getHandlesFromWithinGroupV(ghandle); + du = new PVDataHolder[dhV.size()]; + if (cacheFlag) + { + status=cafe.getPVArray(dhV, du); + } + else + { + //status=cafe.getPVArrayCache(dhV, du); + status=cafe.getCachePVArray(dhV, du); + } + NPV=dhV.size(); + isGroupTimeout=true; + + } + } + else + { + + mexPrintf("status/handle %d / %d \n", status, ghandle); + mexPrintf("Returning NaN in place of struct \n"); + + NS_MOCHA::printStatus(status); + + doubleArray[0]=numeric_limits::signaling_NaN(); + groupStatus[0]=status; - if (extendedPV) { - plhs[0]=mxCreateStructMatrix(1,NPV, nfieldsExtra, fnamesExtra); - } - else { - plhs[0]=mxCreateStructMatrix(1,NPV, nfields, fnames); - } - + return; + } - for (mwSignedIndex j=0; j 2) + { + mexPrintf("Ignoring all input arguments after the 2nd \n"); + mexPrintf("Method is mocha ('getAsyn', \n"); + } + + handle=checkForHandle(prhs[1]); + if(handle==0) + { + mexPrintf("Handle does not exist!\n"); + return; + } + + //status + plhs[0] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); + longStatus = (int32_T *) mxGetData ( plhs[0]); + + status=cafe.get(handle); + longStatus[0]=status; + + if (status!=ICAFE_NORMAL) + { + //NS_MOCHA::printStatus(status); + cafe.printStatus(handle,status); + + } + + break; + } + + + case GET_ARRAY_ASYN: + { + if (nrhs<2) + { + mexPrintf("Invalid Number of argument %d. Input: message, handle/pv \n", nrhs); + return; + } + size_t numberOfHandles=0; + + if (mxIsChar(prhs[1]) ) + { + numberOfHandles=1; + } + else + { + numberOfHandles=mxGetNumberOfElements (prhs[1]); + } + + handleULong = checkHandleArray(prhs[1],true); + + if (handleULong==NULL) + { + mexPrintf("GET_ARRAY_SYNC: Ignoring NULL value in input \n"); + mexPrintf("Number of arguments should be %d. with Input: message, handle/pv \n", nrhs); + return; + } + + plhs[1] = mxCreateNumericMatrix(1,numberOfHandles,mxINT32_CLASS, mxREAL); + longArray = (int32_T *) mxGetData (plhs[1]); + + status=cafe.get( (unsigned int *) handleULong, numberOfHandles, + (int *) longArray); + + plhs[0] = mxCreateNumericMatrix(1,1,mxINT32_CLASS, mxREAL); + longStatus = (int32_T *) mxGetData (plhs[0]); + longStatus[0]=(int32_T) status; + + break; + } + + + case GET_ENUM_STRINGS: + { + + if (mxIsChar(prhs[1])) + { + nh=1; + } + else + { + nh=mxGetNumberOfElements (prhs[1]); + } + if (nh >1) + { + mexPrintf("Method limited to one handle/pv only. Reporting on first given"); + } + + handle=checkForHandle(prhs[1]); + + if(handle==0) + { + mexPrintf("Handle does not exist!\n"); + return; + } + + chtype rdt; + status=cafe.getHandleHelper().getDataTypeRequest(handle, rdt); + + if (status!=ICAFE_NORMAL) + { + mexPrintf("Error for handle input= %d \n", (uint32_T) handle ); + NS_MOCHA::printStatus(status); + plhs[0] = mxCreateCellMatrix(1,1); + mxSetCell (plhs[0], 0, mxCreateString((const char *) "" ) ); + return; + } + + vector enumStrings= cafe.getHandleHelper().getEnumStrings(handle); + unsigned int noEnumStrings=enumStrings.size(); + + if (noEnumStrings==0) + { + status=cafe.getHandleHelper().getStatus(handle); + if (status!=ICAFE_NORMAL) + { + NS_MOCHA::printStatus(status); + } + plhs[0] = mxCreateCellMatrix(1,1); + mxSetCell (plhs[0], 0, mxCreateString((const char *) "" ) ); + } + else + { + plhs[0] = mxCreateCellMatrix(1,noEnumStrings); + for (mwSignedIndex i=0; i 1) + { + mexPrintf("Method limited to one handle/pv only. Reporting on first given"); + } + + handle=checkForHandle(prhs[1]); + if(handle==0) + { + mexPrintf("Handle does not exist!\n"); + return; + } + + mdtIndex=MOCHA_NATIVE; + + if (nrhs>2) + { + //ischar? + if (!mxIsChar(prhs[2]) ) + { + mexPrintf("3rd input argument must be a char \n"); return; } - - - //ischar? - if (!mxIsChar(prhs[1]) ) { - mexPrintf("2nd input argument must be of type char \n"); + mdtIndex=getMdtIndex(prhs[2]); + } + + fout1 = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); + longStatus = (int32_T *) mxGetData (fout1); + fout2 = mxCreateNumericMatrix(1,1,mxINT16_CLASS,mxREAL); + shortAlarmStatus = (int16_T *) mxGetData (fout2); + fout3 = mxCreateNumericMatrix(1,1,mxINT16_CLASS,mxREAL); + shortAlarmSeverity = (int16_T *) mxGetData (fout3); + fout4 = mxCreateNumericMatrix(1,1, mxUINT16_CLASS,mxREAL); + precision = (uint16_T *) mxGetData(fout4); + + fout6 = mxCreateNumericMatrix(1,1, mxUINT16_CLASS,mxREAL); + noEnumStrings = (uint16_T *) mxGetData(fout6); + fout8 = mxCreateDoubleMatrix(1,1,mxREAL); + udl = (double *) mxGetPr (fout8); + fout9 = mxCreateDoubleMatrix(1,1,mxREAL); + ldl = (double *) mxGetPr (fout9); + fout10 = mxCreateDoubleMatrix(1,1,mxREAL); + ual = (double *) mxGetPr (fout10); + fout11 = mxCreateDoubleMatrix(1,1,mxREAL); + lal = (double *) mxGetPr (fout11); + fout12 = mxCreateDoubleMatrix(1,1,mxREAL); + uwl = (double *) mxGetPr (fout12); + fout13 = mxCreateDoubleMatrix(1,1,mxREAL); + lwl = (double *) mxGetPr (fout13); + fout14 = mxCreateDoubleMatrix(1,1,mxREAL); + ucl = (double *) mxGetPr (fout14); + fout15 = mxCreateDoubleMatrix(1,1,mxREAL); + lcl = (double *) mxGetPr (fout15); + + + fout16=mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); + fHandle = (uint32_T *) mxGetData(fout16); + fHandle[0]=handle; + string s = cafe.getPVFromHandle(handle); + fout17 =mxCreateString( s.c_str() ); + + nelem=cafe.getHandleHelper().getNelemRequestCtrl(handle); + + // mexPrintf("nelemRequested %d", nelem); + PVCtrlHolder du; + du.setNelem(nelem); + //du.setNelem(2); + // mexPrintf("nelem %d ", du.getNelem()); + + if (cacheFlag) + { + status=cafe.getCtrlCache(handle,du); + } + else + { + status=cafe.getCtrl(handle,du); + } + + reportError=false; + + plhs[0]=mxCreateStructMatrix(1, 1, nfieldsCtrl, fnamesCtrl); + + //Match INPUT to CAFE DATATYPE + if (mdtIndex==MOCHA_NATIVE) + { + mdtIndex=getMdtIndexFromCafeDataType(du.getDataType()); + if (cafe.getHandleHelper().isEnum(handle)) + { + mdtIndex=MOCHA_STRING; + } + } + + fillCtrlStruct(mdtIndex, du); + + if (status==ICAFE_NORMAL) + { + fout5 = mxCreateString((char *) du.getUnits()); + ////fillCtrlStruct(mdtIndex, du); + } //if + else + { + reportError=true; + } + // Use shared_ptr since cafe-1.0 + //delete [] du.val; + + if (reportError) + { + fout0=getValueIfError(mdtIndex); + //longStatus[0] = (int32_T) status; + //shortAlarmStatus[0] = (int16_T) 0; + //shortAlarmSeverity[0] = (int16_T) 0; + fout5 = mxCreateString((const char *) ""); + precision[0]=0; + noEnumStrings[0]=0; + fout7 = mxCreateCellMatrix(1,1); + for (mwSignedIndex i=0; i <1; ++i) + mxSetCell (fout7, i, mxCreateString((const char *) "" ) ); + udl[0]=0; + ldl[0]=0; + ual[0]=0; + lal[0]=0; + uwl[0]=0; + lwl[0]=0; + ucl[0]=0; + lcl[0]=0; + //cafe.printStatus(handle,status); + } + + mxSetFieldByNumber(plhs[0], 0, 0, fout16); //handle + mxSetFieldByNumber(plhs[0], 0, 1, fout17); //pv + mxSetFieldByNumber(plhs[0], 0, 2, fout0); + mxSetFieldByNumber(plhs[0], 0, 3, fout1); + mxSetFieldByNumber(plhs[0], 0, 4, fout1a); + mxSetFieldByNumber(plhs[0], 0, 5, fout2); + mxSetFieldByNumber(plhs[0], 0, 6, fout2a); + mxSetFieldByNumber(plhs[0], 0, 7, fout3); + mxSetFieldByNumber(plhs[0], 0, 8, fout3a); + + mxSetFieldByNumber(plhs[0], 0, 9, fout4); + mxSetFieldByNumber(plhs[0], 0, 10, fout5); + mxSetFieldByNumber(plhs[0], 0, 11, fout6); + mxSetFieldByNumber(plhs[0], 0, 12, fout7); + mxSetFieldByNumber(plhs[0], 0, 13, fout8); + mxSetFieldByNumber(plhs[0], 0, 14, fout9); + mxSetFieldByNumber(plhs[0], 0, 15, fout10); + mxSetFieldByNumber(plhs[0], 0, 16, fout11); + mxSetFieldByNumber(plhs[0], 0, 17, fout12); + mxSetFieldByNumber(plhs[0], 0, 18, fout13); + mxSetFieldByNumber(plhs[0], 0, 19, fout14); + mxSetFieldByNumber(plhs[0], 0, 20, fout15); + break; + } + + case GET_STRUCT: + { + if (nrhs<2) + { + mexPrintf("Invalid Number of argument %d. Input: message, handle/pv, matlab type (optional) \n", nrhs); + return; + } + + handle=checkForHandle(prhs[1]); + if(handle==0) + { + mexPrintf("Handle does not exist!\n"); + return; + } + + mdtIndex=MOCHA_NATIVE; + + if (nrhs>2) + { + //ischar? + if (!mxIsChar(prhs[2]) ) + { + mexPrintf("3rd input argument must be a char \n"); return; } - - - mData = (mxArray *) prhs[1]; - MELength = ME_MESSAGE_MAX_SIZE+1; - mxGetString(mData, MEmess, MELength); - - - plhs[0]=mxCreateStructMatrix(1, 1, nfieldsME, fnamesME); - - - fillMEStruct( (string)MEmess); - - - mxSetFieldByNumber(plhs[0], 0, 0, fout0); + mdtIndex=getMdtIndex(prhs[2]); + } + + reportError=false; + + uint32_T * d4; + nelem = cafe.getHandleHelper().getNelemClient(handle); //change NelemRequest to NelemClient + + // OUTPUT + + if (extendedPV) + { + plhs[0]=mxCreateStructMatrix(1, 1, nfieldsExtra, fnamesExtra); + } + else + { + plhs[0]=mxCreateStructMatrix(1, 1, nfields, fnames); + } + /* + fout1 = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); + longStatus = (int32_T *) mxGetData (fout1); + + fout2 = mxCreateNumericMatrix(1,1,mxINT16_CLASS,mxREAL); + shortAlarmStatus = (int16_T *) mxGetData (fout2); + + fout3 = mxCreateNumericMatrix(1,1,mxINT16_CLASS,mxREAL); + shortAlarmSeverity = (int16_T *) mxGetData (fout3); + + fout4 = mxCreateNumericMatrix(1,7,mxUINT32_CLASS,mxREAL); + d4 = (uint32_T *) mxGetData(fout4); + + + + + fout9 = mxCreateNumericMatrix(1,2,mxUINT32_CLASS,mxREAL); + d9 = (uint32_T *) mxGetData(fout9); + */ + + PVDataHolder du; + + epicsTimeStamp ets1; + ets1.secPastEpoch=0; + ets1.nsec=0; + + unsigned int nelemPrevious=1; + bool nelemCacheChangeFlag=false; + + if(cacheFlag) + { + nelem = cafe.getHandleHelper().getNelemToRetrieveFromCache(handle); + if (nelem > cafe.getHandleHelper().getNelemRequest(handle) ) + { + nelemPrevious=nelem; + nelem = min( (unsigned int) nelem, cafe.getHandleHelper().getNelemRequest(handle)); + cafe.getHandleHelper().setNelemToRetrieveFromCache(handle,nelem); + nelemCacheChangeFlag=true; + } + } + + du.setNelem(nelem); + + if (cacheFlag) + { + status=cafe.getCache(handle,du); + } + else + { + status=cafe.get(handle,du); + } + + //Match INPUT to CAFE DATATYPE + if (mdtIndex==MOCHA_NATIVE) + { + mdtIndex=getMdtIndexFromCafeDataType(du.getDataType()); + if (cafe.getHandleHelper().isEnum(handle)) + { + mdtIndex=MOCHA_STRING; + } + } + + fillPVStruct(mdtIndex, du); + + if (extendedPV) + { + fillPVStructExtra(handle, du); + } + + if (status!=ICAFE_NORMAL) + { + reportError=true; + } + + + if(nelemCacheChangeFlag) + { + cafe.getHandleHelper().setNelemToRetrieveFromCache(handle,nelemPrevious); + } + + // Use shared_ptr since cafe-1.0 + // delete [] du.val; + + if (reportError) + { + + fout0=getValueIfError(mdtIndex); + //longStatus[0] = (int32_T) status; + //shortAlarmStatus[0] = (int16_T) 0; + //shortAlarmSeverity[0] = (int16_T) 0; + + //cafe.printStatus(handle,status); + } + + + if (extendedPV) + { + mxSetFieldByNumber(plhs[0], 0, 0, fout10); + mxSetFieldByNumber(plhs[0], 0, 1, fout5); + mxSetFieldByNumber(plhs[0], 0, 2, fout0); + mxSetFieldByNumber(plhs[0], 0, 3, fout1); + mxSetFieldByNumber(plhs[0], 0, 4, fout6); + mxSetFieldByNumber(plhs[0], 0, 5, fout2); + mxSetFieldByNumber(plhs[0], 0, 6, fout7); + mxSetFieldByNumber(plhs[0], 0, 7, fout3); + mxSetFieldByNumber(plhs[0], 0, 8, fout8); + mxSetFieldByNumber(plhs[0], 0, 9, fout4); + mxSetFieldByNumber(plhs[0], 0,10, fout9); + } + else + { + mxSetFieldByNumber(plhs[0], 0, 0, fout0); mxSetFieldByNumber(plhs[0], 0, 1, fout1); mxSetFieldByNumber(plhs[0], 0, 2, fout2); mxSetFieldByNumber(plhs[0], 0, 3, fout3); mxSetFieldByNumber(plhs[0], 0, 4, fout4); - - break; - - } - - - case GET_ASYN: - { - - //Already checked for at top of program where we deterine if GET_ARRAY_ASYN or GET_ASYN is used - if (nrhs>2) { - mexPrintf("Ignoring all input arguments after the 2nd \n"); - mexPrintf("Method is mocha ('getAsyn', \n"); - } - - handle=checkForHandle(prhs[1]); - if(handle==0) { - mexPrintf("Handle does not exist!\n"); - return;} - - //status - plhs[0] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); - longStatus = (int32_T *) mxGetData ( plhs[0]); - - status=cafe.get(handle); - longStatus[0]=status; - - if (status!=ICAFE_NORMAL) { - //NS_MOCHA::printStatus(status); - cafe.printStatus(handle,status); - - } - - break; - } - - - case GET_ARRAY_ASYN: - { - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, handle/pv \n", nrhs); - return; - } - size_t numberOfHandles=0; - - if (mxIsChar(prhs[1]) ) { - numberOfHandles=1; - } - else { - numberOfHandles=mxGetNumberOfElements (prhs[1]); - } - - handleULong = checkHandleArray(prhs[1],true); - - if (handleULong==NULL) { - mexPrintf("GET_ARRAY_SYNC: Ignoring NULL value in input \n"); - mexPrintf("Number of arguments should be %d. with Input: message, handle/pv \n", nrhs); - return; - } - - plhs[1] = mxCreateNumericMatrix(1,numberOfHandles,mxINT32_CLASS, mxREAL); - longArray = (int32_T *) mxGetData (plhs[1]); - - status=cafe.get( (unsigned int *) handleULong, numberOfHandles, - (int *) longArray); - - plhs[0] = mxCreateNumericMatrix(1,1,mxINT32_CLASS, mxREAL); - longStatus = (int32_T *) mxGetData (plhs[0]); - longStatus[0]=(int32_T) status; - - break; } - - case GET_ENUM_STRINGS: - { - - if (mxIsChar(prhs[1])) { - nh=1; - } - else{ - nh=mxGetNumberOfElements (prhs[1]); - } - if (nh >1) { - mexPrintf("Method limited to one handle/pv only. Reporting on first given"); - } - - handle=checkForHandle(prhs[1]); - - if(handle==0) { - mexPrintf("Handle does not exist!\n"); - return;} - - chtype rdt; - status=cafe.getHandleHelper().getDataTypeRequest(handle, rdt); - - if (status!=ICAFE_NORMAL) { - mexPrintf("Error for handle input= %d \n", (uint32_T) handle ); - NS_MOCHA::printStatus(status); - plhs[0] = mxCreateCellMatrix(1,1); - mxSetCell (plhs[0], 0, mxCreateString((const char *) "" ) ); - return; - } - - vector enumStrings= cafe.getHandleHelper().getEnumStrings(handle); - unsigned int noEnumStrings=enumStrings.size(); - - if (noEnumStrings==0){ - status=cafe.getHandleHelper().getStatus(handle); - if (status!=ICAFE_NORMAL) { - NS_MOCHA::printStatus(status); - } - plhs[0] = mxCreateCellMatrix(1,1); - mxSetCell (plhs[0], 0, mxCreateString((const char *) "" ) ); - } - else { - plhs[0] = mxCreateCellMatrix(1,noEnumStrings); - for (mwSignedIndex i=0; i 1) { - mexPrintf("Method limited to one handle/pv only. Reporting on first given"); - } - - handle=checkForHandle(prhs[1]); - if(handle==0) { - mexPrintf("Handle does not exist!\n"); - return;} - - mdtIndex=MOCHA_NATIVE; - - if (nrhs>2) { - //ischar? - if (!mxIsChar(prhs[2]) ) { - mexPrintf("3rd input argument must be a char \n"); - return; - } - mdtIndex=getMdtIndex(prhs[2]); - } - - fout1 = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); - longStatus = (int32_T *) mxGetData (fout1); - fout2 = mxCreateNumericMatrix(1,1,mxINT16_CLASS,mxREAL); - shortAlarmStatus = (int16_T *) mxGetData (fout2); - fout3 = mxCreateNumericMatrix(1,1,mxINT16_CLASS,mxREAL); - shortAlarmSeverity = (int16_T *) mxGetData (fout3); - fout4 = mxCreateNumericMatrix(1,1, mxUINT16_CLASS,mxREAL); - precision = (uint16_T *) mxGetData(fout4); - - fout6 = mxCreateNumericMatrix(1,1, mxUINT16_CLASS,mxREAL); - noEnumStrings = (uint16_T *) mxGetData(fout6); - fout8 = mxCreateDoubleMatrix(1,1,mxREAL); - udl = (double *) mxGetPr (fout8); - fout9 = mxCreateDoubleMatrix(1,1,mxREAL); - ldl = (double *) mxGetPr (fout9); - fout10 = mxCreateDoubleMatrix(1,1,mxREAL); - ual = (double *) mxGetPr (fout10); - fout11 = mxCreateDoubleMatrix(1,1,mxREAL); - lal = (double *) mxGetPr (fout11); - fout12 = mxCreateDoubleMatrix(1,1,mxREAL); - uwl = (double *) mxGetPr (fout12); - fout13 = mxCreateDoubleMatrix(1,1,mxREAL); - lwl = (double *) mxGetPr (fout13); - fout14 = mxCreateDoubleMatrix(1,1,mxREAL); - ucl = (double *) mxGetPr (fout14); - fout15 = mxCreateDoubleMatrix(1,1,mxREAL); - lcl = (double *) mxGetPr (fout15); - - - fout16=mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); - fHandle = (uint32_T *) mxGetData(fout16); - fHandle[0]=handle; - string s = cafe.getPVFromHandle(handle); - fout17 =mxCreateString( s.c_str() ); - - nelem=cafe.getHandleHelper().getNelemRequestCtrl(handle); - - // mexPrintf("nelemRequested %d", nelem); - PVCtrlHolder du; - du.setNelem(nelem); - //du.setNelem(2); - // mexPrintf("nelem %d ", du.getNelem()); - - if (cacheFlag) { - status=cafe.getCtrlCache(handle,du); - } - else { - status=cafe.getCtrl(handle,du); - } - - reportError=false; - - plhs[0]=mxCreateStructMatrix(1, 1, nfieldsCtrl, fnamesCtrl); - - //Match INPUT to CAFE DATATYPE - if (mdtIndex==MOCHA_NATIVE) { - mdtIndex=getMdtIndexFromCafeDataType(du.getDataType()); - if (cafe.getHandleHelper().isEnum(handle)) { - mdtIndex=MOCHA_STRING; - } - } - - fillCtrlStruct(mdtIndex, du); - - if (status==ICAFE_NORMAL) { - fout5 = mxCreateString((char *) du.getUnits()); - ////fillCtrlStruct(mdtIndex, du); - } //if - else { - reportError=true; - } - // Use shared_ptr since cafe-1.0 - //delete [] du.val; - - if (reportError) { - fout0=getValueIfError(mdtIndex); - //longStatus[0] = (int32_T) status; - //shortAlarmStatus[0] = (int16_T) 0; - //shortAlarmSeverity[0] = (int16_T) 0; - fout5 = mxCreateString((const char *) ""); - precision[0]=0; - noEnumStrings[0]=0; - fout7 = mxCreateCellMatrix(1,1); - for (mwSignedIndex i=0; i <1; ++i) - mxSetCell (fout7, i, mxCreateString((const char *) "" ) ); - udl[0]=0; - ldl[0]=0; - ual[0]=0; - lal[0]=0; - uwl[0]=0; - lwl[0]=0; - ucl[0]=0; - lcl[0]=0; - //cafe.printStatus(handle,status); - } - - mxSetFieldByNumber(plhs[0], 0, 0, fout16); //handle - mxSetFieldByNumber(plhs[0], 0, 1, fout17); //pv - mxSetFieldByNumber(plhs[0], 0, 2, fout0); - mxSetFieldByNumber(plhs[0], 0, 3, fout1); - mxSetFieldByNumber(plhs[0], 0, 4, fout1a); - mxSetFieldByNumber(plhs[0], 0, 5, fout2); - mxSetFieldByNumber(plhs[0], 0, 6, fout2a); - mxSetFieldByNumber(plhs[0], 0, 7, fout3); - mxSetFieldByNumber(plhs[0], 0, 8, fout3a); - - mxSetFieldByNumber(plhs[0], 0, 9, fout4); - mxSetFieldByNumber(plhs[0], 0, 10, fout5); - mxSetFieldByNumber(plhs[0], 0, 11, fout6); - mxSetFieldByNumber(plhs[0], 0, 12, fout7); - mxSetFieldByNumber(plhs[0], 0, 13, fout8); - mxSetFieldByNumber(plhs[0], 0, 14, fout9); - mxSetFieldByNumber(plhs[0], 0, 15, fout10); - mxSetFieldByNumber(plhs[0], 0, 16, fout11); - mxSetFieldByNumber(plhs[0], 0, 17, fout12); - mxSetFieldByNumber(plhs[0], 0, 18, fout13); - mxSetFieldByNumber(plhs[0], 0, 19, fout14); - mxSetFieldByNumber(plhs[0], 0, 20, fout15); - break; } - case GET_STRUCT: - { - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, handle/pv, matlab type (optional) \n", nrhs); - return; - } - - handle=checkForHandle(prhs[1]); - if(handle==0) { - mexPrintf("Handle does not exist!\n"); - return;} - - mdtIndex=MOCHA_NATIVE; - - if (nrhs>2) { - //ischar? - if (!mxIsChar(prhs[2]) ) { - mexPrintf("3rd input argument must be a char \n"); - return; - } - mdtIndex=getMdtIndex(prhs[2]); - } - - reportError=false; - - uint32_T * d4; - nelem = cafe.getHandleHelper().getNelemClient(handle); //change NelemRequest to NelemClient - - // OUTPUT - - if (extendedPV) { - plhs[0]=mxCreateStructMatrix(1, 1, nfieldsExtra, fnamesExtra); - } - else { - plhs[0]=mxCreateStructMatrix(1, 1, nfields, fnames); - } - /* - fout1 = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); - longStatus = (int32_T *) mxGetData (fout1); - - fout2 = mxCreateNumericMatrix(1,1,mxINT16_CLASS,mxREAL); - shortAlarmStatus = (int16_T *) mxGetData (fout2); - - fout3 = mxCreateNumericMatrix(1,1,mxINT16_CLASS,mxREAL); - shortAlarmSeverity = (int16_T *) mxGetData (fout3); - - fout4 = mxCreateNumericMatrix(1,7,mxUINT32_CLASS,mxREAL); - d4 = (uint32_T *) mxGetData(fout4); - - - - - fout9 = mxCreateNumericMatrix(1,2,mxUINT32_CLASS,mxREAL); - d9 = (uint32_T *) mxGetData(fout9); - */ - - PVDataHolder du; - - epicsTimeStamp ets1; - ets1.secPastEpoch=0; - ets1.nsec=0; - - unsigned int nelemPrevious=1; - bool nelemCacheChangeFlag=false; - - if(cacheFlag) { - nelem = cafe.getHandleHelper().getNelemToRetrieveFromCache(handle); - if (nelem > cafe.getHandleHelper().getNelemRequest(handle) ) { - nelemPrevious=nelem; - nelem = min( (unsigned int) nelem, cafe.getHandleHelper().getNelemRequest(handle)); - cafe.getHandleHelper().setNelemToRetrieveFromCache(handle,nelem); - nelemCacheChangeFlag=true; - } - } - - du.setNelem(nelem); - - if (cacheFlag) { - status=cafe.getCache(handle,du); - } - else { - status=cafe.get(handle,du); - } - - //Match INPUT to CAFE DATATYPE - if (mdtIndex==MOCHA_NATIVE) { - mdtIndex=getMdtIndexFromCafeDataType(du.getDataType()); - if (cafe.getHandleHelper().isEnum(handle)) { - mdtIndex=MOCHA_STRING; - } - } - - fillPVStruct(mdtIndex, du); - - if (extendedPV) { - fillPVStructExtra(handle, du); - } - - if (status!=ICAFE_NORMAL) { - reportError=true; - } - - - if(nelemCacheChangeFlag) { - cafe.getHandleHelper().setNelemToRetrieveFromCache(handle,nelemPrevious); - } - - // Use shared_ptr since cafe-1.0 - // delete [] du.val; - - if (reportError) { - - fout0=getValueIfError(mdtIndex); - //longStatus[0] = (int32_T) status; - //shortAlarmStatus[0] = (int16_T) 0; - //shortAlarmSeverity[0] = (int16_T) 0; - - //cafe.printStatus(handle,status); - } - - - if (extendedPV) { - mxSetFieldByNumber(plhs[0], 0, 0, fout10); - mxSetFieldByNumber(plhs[0], 0, 1, fout5); - mxSetFieldByNumber(plhs[0], 0, 2, fout0); - mxSetFieldByNumber(plhs[0], 0, 3, fout1); - mxSetFieldByNumber(plhs[0], 0, 4, fout6); - mxSetFieldByNumber(plhs[0], 0, 5, fout2); - mxSetFieldByNumber(plhs[0], 0, 6, fout7); - mxSetFieldByNumber(plhs[0], 0, 7, fout3); - mxSetFieldByNumber(plhs[0], 0, 8, fout8); - mxSetFieldByNumber(plhs[0], 0, 9, fout4); - mxSetFieldByNumber(plhs[0], 0,10, fout9); - } - else { - mxSetFieldByNumber(plhs[0], 0, 0, fout0); - mxSetFieldByNumber(plhs[0], 0, 1, fout1); - mxSetFieldByNumber(plhs[0], 0, 2, fout2); - mxSetFieldByNumber(plhs[0], 0, 3, fout3); - mxSetFieldByNumber(plhs[0], 0, 4, fout4); - } - - if (status!=ICAFE_NORMAL) { - if (withExceptions) { - mexErrMsgIdAndTxt(prepareExceptionID(status).c_str(), prepareExceptionText(handle,status).c_str()); - } - } - break; - } + } - case GET_SCALAR_ARRAY: + case GET_SCALAR_ARRAY: + { + + if (nrhs<2) { - - if (nrhs<2) { - if(cacheFlag) { - mexPrintf("Invalid Number of argument %d. Input: 'getScalarArrayCache', handleArray \n", nrhs); - } - else { - mexPrintf("Invalid Number of argument %d. Input: 'getScalarArray', handleArray \n", nrhs); - } - return; - } - - if (nrhs>2 && (mochaIndex==mochaIndexOriginal || cacheFlag) ) { - //ischar? - if (!mxIsChar(prhs[nrhs-1]) ) { - mexPrintf("Last input argument must be a char \n"); - return; - } - mdtIndex=NS_MOCHA::getMdtIndex(prhs[nrhs-1]); - } - - - int32_T mdtIndexOriginal=mdtIndex; - size_t numberOfHandles=mxGetNumberOfElements (prhs[1]); - - neWithinAllCells=0; // filled by checkHandleArray - - //What is dataType? - handleULong = checkHandleArray(prhs[1],true);//(uint64_T *) mxGetData ( prhs[1]); - - - if (handleULong==NULL) { - mexPrintf("GET_SCALAR_ARRAY: Ignoring NULL value in input\n"); - mexPrintf("Input Invalid. Should be: 'getStructArray(Cache)', handleArray \n"); - return; - } - - if (mxIsChar(prhs[1]) ) { - numberOfHandles=1; - //mexPrintf("char numberOfHandles %d",numberOfHandles); - } - else if (mxIsCell(prhs[1]) ) { - numberOfHandles=neWithinAllCells; - //mexPrintf(" cell numberOfHandles %d",numberOfHandles); - } - - - //for (size_t i=0; i1) { - nelem=1; // First element only - } - pvd[i].setNelem(nelem); - - //Is this really needed? - if(cacheFlag) { - cafe.getHandleHelper().setNelemToRetrieveFromCache((unsigned int) handleULong[i],nelem); - } - } - - if(cacheFlag) { - status=cafe.getCache( (unsigned int *) handleULong, numberOfHandles, - pvd); - } - else { - - status=cafe.get( (unsigned int *) handleULong, numberOfHandles, - pvd); - - } - - - int32_T * groupStatus; - - //overall groupStatus - plhs[1] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); - groupStatus = (int32_T *) mxGetData (plhs[1]); - groupStatus[0]=status; - - plhs[2] = mxCreateNumericMatrix(1,numberOfHandles,mxINT32_CLASS,mxREAL); - longStatus = (int32_T *) mxGetData (plhs[2]); - - //plhs[0] = mxCreateDoubleMatrix (1,numberOfHandles,mxREAL); - //doubleArray = (double *) mxGetPr (plhs[0]); - - //If no datatype is given, assume datatype of first element! - if (mdtIndexOriginal==MOCHA_NATIVE){ - mdtIndex=NS_MOCHA::getMdtIndexFromCafeDataType(pvd[0].getDataType()); - if (cafe.getHandleHelper().isEnum(handleULong[0])) { //check this for handleULong[0] - mdtIndex=MOCHA_STRING; - } - } - - - - switch (mdtIndex) + if(cacheFlag) { - case MOCHA_DOUBLE: - plhs[0] = mxCreateDoubleMatrix(1,numberOfHandles,mxREAL); - doubleArray = (double *) mxGetPr (plhs[0]); - for (mwSignedIndex j=0; j ::quiet_NaN(); - } - longStatus[j]=pvd[j].getStatus(); - } - break; + mexPrintf("Invalid Number of argument %d. Input: 'getScalarArrayCache', handleArray \n", nrhs); + } + else + { + mexPrintf("Invalid Number of argument %d. Input: 'getScalarArray', handleArray \n", nrhs); + } + return; + } - case MOCHA_FLOAT: - plhs[0] = mxCreateNumericMatrix(1,numberOfHandles,mxSINGLE_CLASS, mxREAL); - floatArray = (float *) mxGetData (plhs[0]); - for (mwSignedIndex j=0; j ::quiet_NaN(); - } - longStatus[j]=pvd[j].getStatus(); - } - break; + if (nrhs>2 && (mochaIndex==mochaIndexOriginal || cacheFlag) ) + { + //ischar? + if (!mxIsChar(prhs[nrhs-1]) ) + { + mexPrintf("Last input argument must be a char \n"); + return; + } + mdtIndex=NS_MOCHA::getMdtIndex(prhs[nrhs-1]); + } - case MOCHA_INT: - plhs[0] = mxCreateNumericMatrix(1,numberOfHandles,mxINT32_CLASS, mxREAL); - longArray = (int32_T *) mxGetData (plhs[0] ); - for (mwSignedIndex j=0; j ::quiet_NaN(); - } - longStatus[j]=pvd[j].getStatus(); - } - break; - case MOCHA_SHORT: - plhs[0] = mxCreateNumericMatrix(1,numberOfHandles,mxINT16_CLASS, mxREAL); - shortArray = (int16_T *) mxGetData (plhs[0]); - for (mwSignedIndex j=0; j ::quiet_NaN(); - } - longStatus[j]=pvd[j].getStatus(); - } - break; + int32_T mdtIndexOriginal=mdtIndex; + size_t numberOfHandles=mxGetNumberOfElements (prhs[1]); - case MOCHA_USHORT: - plhs[0] = mxCreateNumericMatrix(1,numberOfHandles,mxUINT16_CLASS, mxREAL); - ushortArray = (uint16_T *) mxGetData (plhs[0]); - for (mwSignedIndex j=0; j ::quiet_NaN(); - } - longStatus[j]=pvd[j].getStatus(); - } - break; + neWithinAllCells=0; // filled by checkHandleArray - case MOCHA_UCHAR: - plhs[0] = mxCreateNumericMatrix(1,numberOfHandles,mxUINT8_CLASS, mxREAL); - ucharArray = (uint8_T *) mxGetData (plhs[0]); - for (mwSignedIndex j=0; j ::quiet_NaN(); - } - longStatus[j]=pvd[j].getStatus(); - } - break; + //What is dataType? + handleULong = checkHandleArray(prhs[1],true);//(uint64_T *) mxGetData ( prhs[1]); - case MOCHA_STRING: - { - plhs[0] = mxCreateCellMatrix(1,numberOfHandles); - for (mwSignedIndex j=0; j ::quiet_NaN() )); - } - longStatus[j]=pvd[j].getStatus(); - } - break; - } - // Non DBR_TYPES - case MOCHA_CHAR: - plhs[0] = mxCreateNumericMatrix(1,numberOfHandles,mxINT8_CLASS, mxREAL); - charArray = (int8_T *) mxGetData (plhs[0]); - for (mwSignedIndex j=0; j ::quiet_NaN(); - } - longStatus[j]=pvd[j].getStatus(); - } - break; - case MOCHA_UINT: - plhs[0] = mxCreateNumericMatrix(1,numberOfHandles,mxUINT32_CLASS, mxREAL); - ulongArray = (uint32_T *) mxGetData (plhs[0]); - for (mwSignedIndex j=0; j ::quiet_NaN(); - } - longStatus[j]=pvd[j].getStatus(); - } - break; - case MOCHA_LONG: - plhs[0] = mxCreateNumericMatrix(1,numberOfHandles,mxINT64_CLASS, mxREAL); - longlongArray = (int64_T *) mxGetData (plhs[0]); - for (mwSignedIndex j=0; j ::quiet_NaN(); - } - longStatus[j]=pvd[j].getStatus(); - } - break; - case MOCHA_ULONG: - plhs[0] = mxCreateNumericMatrix(1,numberOfHandles,mxUINT64_CLASS, mxREAL); - ulonglongArray = (uint64_T *) mxGetData (plhs[0]); - for (mwSignedIndex j=0; j ::quiet_NaN(); - } - longStatus[j]=pvd[j].getStatus(); - } - break; - default: + + if (handleULong==NULL) + { + mexPrintf("GET_SCALAR_ARRAY: Ignoring NULL value in input\n"); + mexPrintf("Input Invalid. Should be: 'getStructArray(Cache)', handleArray \n"); + return; + } + + if (mxIsChar(prhs[1]) ) + { + numberOfHandles=1; + //mexPrintf("char numberOfHandles %d",numberOfHandles); + } + else if (mxIsCell(prhs[1]) ) + { + numberOfHandles=neWithinAllCells; + //mexPrintf(" cell numberOfHandles %d",numberOfHandles); + } + + + //for (size_t i=0; i1) + { + nelem=1; // First element only + } + pvd[i].setNelem(nelem); + + //Is this really needed? + if(cacheFlag) + { + cafe.getHandleHelper().setNelemToRetrieveFromCache((unsigned int) handleULong[i],nelem); + } + } + + if(cacheFlag) + { + status=cafe.getCache( (unsigned int *) handleULong, numberOfHandles, + pvd); + } + else + { + + status=cafe.get( (unsigned int *) handleULong, numberOfHandles, + pvd); + + } + + + int32_T * groupStatus; + + //overall groupStatus + plhs[1] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); + groupStatus = (int32_T *) mxGetData (plhs[1]); + groupStatus[0]=status; + + plhs[2] = mxCreateNumericMatrix(1,numberOfHandles,mxINT32_CLASS,mxREAL); + longStatus = (int32_T *) mxGetData (plhs[2]); + + //plhs[0] = mxCreateDoubleMatrix (1,numberOfHandles,mxREAL); + //doubleArray = (double *) mxGetPr (plhs[0]); + + //If no datatype is given, assume datatype of first element! + if (mdtIndexOriginal==MOCHA_NATIVE) + { + mdtIndex=NS_MOCHA::getMdtIndexFromCafeDataType(pvd[0].getDataType()); + if (cafe.getHandleHelper().isEnum(handleULong[0])) //check this for handleULong[0] + { + mdtIndex=MOCHA_STRING; + } + } + + + + switch (mdtIndex) + { + case MOCHA_DOUBLE: + plhs[0] = mxCreateDoubleMatrix(1,numberOfHandles,mxREAL); + doubleArray = (double *) mxGetPr (plhs[0]); + for (mwSignedIndex j=0; j ::quiet_NaN())); - } - longStatus[j]=pvd[j].getStatus(); - } - break; + doubleArray[j]=pvd[j].getAsDouble(0); } - } //switch - - // for (mwSignedIndex j=0; j 2 && (mochaIndex==mochaIndexOriginal || cacheFlag) ) { - //ischar? - if (!mxIsChar(prhs[2]) ) { - mexPrintf("3rd input argument (data type) must be a char \n"); - return; + else + { + doubleArray[j]=numeric_limits::quiet_NaN(); + } + longStatus[j]=pvd[j].getStatus(); + } + break; + + case MOCHA_FLOAT: + plhs[0] = mxCreateNumericMatrix(1,numberOfHandles,mxSINGLE_CLASS, mxREAL); + floatArray = (float *) mxGetData (plhs[0]); + for (mwSignedIndex j=0; j ::quiet_NaN(); + } + longStatus[j]=pvd[j].getStatus(); + } + break; + + case MOCHA_INT: + plhs[0] = mxCreateNumericMatrix(1,numberOfHandles,mxINT32_CLASS, mxREAL); + longArray = (int32_T *) mxGetData (plhs[0] ); + for (mwSignedIndex j=0; j ::quiet_NaN(); + } + longStatus[j]=pvd[j].getStatus(); + } + break; + + case MOCHA_SHORT: + plhs[0] = mxCreateNumericMatrix(1,numberOfHandles,mxINT16_CLASS, mxREAL); + shortArray = (int16_T *) mxGetData (plhs[0]); + for (mwSignedIndex j=0; j ::quiet_NaN(); + } + longStatus[j]=pvd[j].getStatus(); + } + break; + + case MOCHA_USHORT: + plhs[0] = mxCreateNumericMatrix(1,numberOfHandles,mxUINT16_CLASS, mxREAL); + ushortArray = (uint16_T *) mxGetData (plhs[0]); + for (mwSignedIndex j=0; j ::quiet_NaN(); + } + longStatus[j]=pvd[j].getStatus(); + } + break; + + case MOCHA_UCHAR: + plhs[0] = mxCreateNumericMatrix(1,numberOfHandles,mxUINT8_CLASS, mxREAL); + ucharArray = (uint8_T *) mxGetData (plhs[0]); + for (mwSignedIndex j=0; j ::quiet_NaN(); + } + longStatus[j]=pvd[j].getStatus(); + } + break; + + case MOCHA_STRING: + { + plhs[0] = mxCreateCellMatrix(1,numberOfHandles); + for (mwSignedIndex j=0; j ::quiet_NaN() )); } - mdtIndex=NS_MOCHA::getMdtIndex(prhs[2]); - } - - int32_T mdtIndexOriginal=mdtIndex; - size_t numberOfHandles=mxGetNumberOfElements (prhs[1]); - - - neWithinAllCells=0; // filled by checkHandleArray - - //What is dataType? - handleULong = checkHandleArray(prhs[1],true);//(uint64_T *) mxGetData ( prhs[1]); - - if (handleULong==NULL) { - mexPrintf("GET_STRUCT_ARRAY: Ignoring NULL value in input \n"); - mexPrintf("Input Invalid. Should be: 'getStructArray', handleArray \n"); - return; - } - - - if(handleULong[0]==0) { - mexPrintf("Input Invalid. Should be: 'getStructArray', handleArray \n"); - return; - } - - if (mxIsChar(prhs[1]) ) { - numberOfHandles=1; - } - else if (mxIsCell(prhs[1]) ) { - numberOfHandles=neWithinAllCells; - //mexPrintf(" cell numberOfHandles %d",numberOfHandles); - } - - - - PVDataHolder * pvd = new PVDataHolder[numberOfHandles]; - - for (size_t i=0; i2 && (mochaIndex==mochaIndexOriginal || cacheFlag) ) { - //ischar? - if (!mxIsChar(prhs[2]) ) { - mexPrintf("3rd input argument (data type) must be a char \n"); - return; - } - mdtIndex=NS_MOCHA::getMdtIndex(prhs[2]); - } - - int32_T mdtIndexOriginal=mdtIndex; - size_t numberOfHandles=mxGetNumberOfElements (prhs[1]); - - neWithinAllCells=0; // filled by checkHandleArray - - //What is dataType? - handleULong = checkHandleArray(prhs[1],true);//(uint64_T *) mxGetData ( prhs[1]); - - if (handleULong==NULL) { - mexPrintf("GET_CELL_ARRAY: Ignoring NULL value in input \n"); - mexPrintf("Input Invalid. Should be: 'getCellArray', handleArray \n"); - return; - } - - - if(handleULong[0]==0) { - mexPrintf("Input Invalid. Should be: 'getCellArray', handleArray \n"); - return; - } - - if (mxIsChar(prhs[1]) ) { - numberOfHandles=1; - } - else if (mxIsCell(prhs[1]) ) { - numberOfHandles=neWithinAllCells; - //mexPrintf(" cell numberOfHandles %d",numberOfHandles); - } - - - PVDataHolder * pvd = new PVDataHolder[numberOfHandles]; - - for (size_t i=0; i2 && (mochaIndex==mochaIndexOriginal || cacheFlag) ) { - //ischar? - if (!mxIsChar(prhs[2]) ) { - mexPrintf("3rd input argument must be a char \n"); - return; + // Non DBR_TYPES + case MOCHA_CHAR: + plhs[0] = mxCreateNumericMatrix(1,numberOfHandles,mxINT8_CLASS, mxREAL); + charArray = (int8_T *) mxGetData (plhs[0]); + for (mwSignedIndex j=0; j ::quiet_NaN(); + } + longStatus[j]=pvd[j].getStatus(); } - if (mdtIndex==MOCHA_NATIVE){ - - - - status=cafe.getHandleHelper().getDataTypeRequest(handle, rdt); - - - if (status!=ICAFE_NORMAL) { - mexPrintf("Error for handle input= %d \n", (uint32_T) mxGetScalar(prhs[1]) ); - NS_MOCHA::printStatus(status); - longStatus[0]=status; - plhs[0]=getValueIfError(mdtIndex); - return; + break; + case MOCHA_UINT: + plhs[0] = mxCreateNumericMatrix(1,numberOfHandles,mxUINT32_CLASS, mxREAL); + ulongArray = (uint32_T *) mxGetData (plhs[0]); + for (mwSignedIndex j=0; j ::quiet_NaN(); + } + longStatus[j]=pvd[j].getStatus(); + } + break; + case MOCHA_LONG: + plhs[0] = mxCreateNumericMatrix(1,numberOfHandles,mxINT64_CLASS, mxREAL); + longlongArray = (int64_T *) mxGetData (plhs[0]); + for (mwSignedIndex j=0; j ::quiet_NaN(); + } + longStatus[j]=pvd[j].getStatus(); + } + break; + case MOCHA_ULONG: + plhs[0] = mxCreateNumericMatrix(1,numberOfHandles,mxUINT64_CLASS, mxREAL); + ulonglongArray = (uint64_T *) mxGetData (plhs[0]); + for (mwSignedIndex j=0; j ::quiet_NaN(); + } + longStatus[j]=pvd[j].getStatus(); + } + break; + default: + { + plhs[0] = mxCreateCellMatrix(1,numberOfHandles); + for (mwSignedIndex j=0; j ::quiet_NaN())); + } + longStatus[j]=pvd[j].getStatus(); + } + break; + } + } //switch - CAFE_DATATYPE cdt = (CAFE_DATATYPE) rdt; - - + // for (mwSignedIndex j=0; j 2 && (mochaIndex==mochaIndexOriginal || cacheFlag) ) + { + //ischar? + if (!mxIsChar(prhs[2]) ) + { + mexPrintf("3rd input argument (data type) must be a char \n"); + return; + } + mdtIndex=NS_MOCHA::getMdtIndex(prhs[2]); + } + + int32_T mdtIndexOriginal=mdtIndex; + size_t numberOfHandles=mxGetNumberOfElements (prhs[1]); + + + neWithinAllCells=0; // filled by checkHandleArray + + //What is dataType? + handleULong = checkHandleArray(prhs[1],true);//(uint64_T *) mxGetData ( prhs[1]); + + if (handleULong==NULL) + { + mexPrintf("GET_STRUCT_ARRAY: Ignoring NULL value in input \n"); + mexPrintf("Input Invalid. Should be: 'getStructArray', handleArray \n"); + return; + } + + + if(handleULong[0]==0) + { + mexPrintf("Input Invalid. Should be: 'getStructArray', handleArray \n"); + return; + } + + if (mxIsChar(prhs[1]) ) + { + numberOfHandles=1; + } + else if (mxIsCell(prhs[1]) ) + { + numberOfHandles=neWithinAllCells; + //mexPrintf(" cell numberOfHandles %d",numberOfHandles); + } + + + + PVDataHolder * pvd = new PVDataHolder[numberOfHandles]; + + for (size_t i=0; i 0 ) { - - nelem = min( cafe.getHandleHelper().getNelemClient(handle), - (cafe.getHandleHelper().getNelemNative(handle)-cafe.getHandleHelper().getOffset(handle)) ); - - } - - if(nelem<1) { - nelem=1; // This is to build output matrix + + fillPVStruct(mdtIndex, pvd[j]); + if (extendedPV) + { + fillPVStructExtra(handleULong[j], pvd[j]); } - - - unsigned int nelemPrevious=1; - bool nelemCacheChangeFlag=false; - - if(cacheFlag) { - - nelem = cafe.getHandleHelper().getNelemToRetrieveFromCache(handle) ; - - //mexPrintf("get Cache: nelem = %d \n", nelem); - - - if ( (cafe.getHandleHelper().getOffsetLast(handle) > 0) || - (cafe.getHandleHelper().getNelemToRetrieveFromCache(handle) > cafe.getHandleHelper().getNelemRequest(handle))){ - - - //if (nelem > cafe.getHandleHelper().getNelemRequest(handle) ) { - nelemPrevious=cafe.getHandleHelper().getNelemToRetrieveFromCache(handle); - nelem = min( (unsigned int) nelem, cafe.getHandleHelper().getNelemRequest(handle)-cafe.getHandleHelper().getOffsetLast(handle)); - - //mexPrintf("nelem to ret from Cache %d \n",cafe.getHandleHelper().getNelemToRetrieveFromCache(handle)); - //mexPrintf("nelem to ret from Cache %d \n",nelem); - //cafe.getHandleHelper().setNelemToRetrieveFromCache(handle,nelem+cafe.getHandleHelper().getOffsetLast(handle)); - cafe.getHandleHelper().setNelemToRetrieveFromCache(handle,nelem); - nelemCacheChangeFlag=true; - } - + + if (pvd[j].getStatus()!=ICAFE_NORMAL) + { + fout0=getValueIfError(mdtIndex); + //longStatus[0] = (int32_T) pvd[j].getStatus(); + //shortAlarmStatus[0] = (int16_T) 0; + //shortAlarmSeverity[0] = (int16_T) 0; } - - switch (mdtIndex) - { - case MOCHA_DOUBLE: - plhs[0] = mxCreateDoubleMatrix(1,nelem,mxREAL); - doubleArray = (double *) mxGetPr (plhs[0]); - if(cacheFlag) { status=cafe.getCache(handle,doubleArray);} - else {status=cafe.get(handle,doubleArray);} - break; - case MOCHA_FLOAT: - plhs[0] = mxCreateNumericMatrix(1,nelem,mxSINGLE_CLASS, mxREAL); - floatArray = (float *) mxGetData (plhs[0]); - if(cacheFlag) { mexPrintf("here"); status=cafe.getCache(handle,floatArray); mexPrintf("status %d", status);} - else {status=cafe.get(handle,floatArray);} - break; - case MOCHA_INT: - plhs[0] = mxCreateNumericMatrix(1,nelem,mxINT32_CLASS, mxREAL); - longArray = (int32_T *) mxGetData (plhs[0] ); - if(cacheFlag) { status=cafe.getCache(handle,longArray);} - else {status=cafe.get(handle,longArray);} - break; + if (extendedPV) + { + mxSetFieldByNumber(plhs[0], j, 0, fout10); + mxSetFieldByNumber(plhs[0], j, 1, fout5); + mxSetFieldByNumber(plhs[0], j, 2, fout0); + mxSetFieldByNumber(plhs[0], j, 3, fout1); + mxSetFieldByNumber(plhs[0], j, 4, fout6); + mxSetFieldByNumber(plhs[0], j, 5, fout2); + mxSetFieldByNumber(plhs[0], j, 6, fout7); + mxSetFieldByNumber(plhs[0], j, 7, fout3); + mxSetFieldByNumber(plhs[0], j, 8, fout8); + mxSetFieldByNumber(plhs[0], j, 9, fout4); + mxSetFieldByNumber(plhs[0], j,10, fout9); + } + else + { - case MOCHA_SHORT: - plhs[0] = mxCreateNumericMatrix(1,nelem,mxINT16_CLASS, mxREAL); - shortArray = (int16_T *) mxGetData (plhs[0]); - if(cacheFlag) { status=cafe.getCache(handle,shortArray);} - else {status=cafe.get(handle,shortArray);} - break; + mxSetFieldByNumber(plhs[0], j, 0, fout0); + mxSetFieldByNumber(plhs[0], j, 1, fout1); + mxSetFieldByNumber(plhs[0], j, 2, fout2); + mxSetFieldByNumber(plhs[0], j, 3, fout3); + mxSetFieldByNumber(plhs[0], j, 4, fout4); + } - case MOCHA_USHORT: - plhs[0] = mxCreateNumericMatrix(1,nelem,mxUINT16_CLASS, mxREAL); - ushortArray = (uint16_T *) mxGetData (plhs[0]); - if(cacheFlag) { status=cafe.getCache(handle,ushortArray);} - else {status=cafe.get(handle,ushortArray);} - break; - case MOCHA_UCHAR: - plhs[0] = mxCreateNumericMatrix(1,nelem,mxUINT8_CLASS, mxREAL); - ucharArray = (uint8_T *) mxGetData (plhs[0]); - if(cacheFlag) { status=cafe.getCache(handle,ucharArray);} - else {status=cafe.get(handle,ucharArray);} - break; + // Use shared_ptr since cafe-1.0 + //delete [] pvd[j].val; + } + delete [] pvd; - case MOCHA_STRING: + + break; + } + + + case GET_CELL_ARRAY: + { + if (nrhs<2) + { + mexPrintf("Invalid Number of argument %d. Input: 'getCellArray', handleArray, optional data type \n", nrhs); + return; + } + + if (nrhs>2 && (mochaIndex==mochaIndexOriginal || cacheFlag) ) + { + //ischar? + if (!mxIsChar(prhs[2]) ) + { + mexPrintf("3rd input argument (data type) must be a char \n"); + return; + } + mdtIndex=NS_MOCHA::getMdtIndex(prhs[2]); + } + + int32_T mdtIndexOriginal=mdtIndex; + size_t numberOfHandles=mxGetNumberOfElements (prhs[1]); + + neWithinAllCells=0; // filled by checkHandleArray + + //What is dataType? + handleULong = checkHandleArray(prhs[1],true);//(uint64_T *) mxGetData ( prhs[1]); + + if (handleULong==NULL) + { + mexPrintf("GET_CELL_ARRAY: Ignoring NULL value in input \n"); + mexPrintf("Input Invalid. Should be: 'getCellArray', handleArray \n"); + return; + } + + + if(handleULong[0]==0) + { + mexPrintf("Input Invalid. Should be: 'getCellArray', handleArray \n"); + return; + } + + if (mxIsChar(prhs[1]) ) + { + numberOfHandles=1; + } + else if (mxIsCell(prhs[1]) ) + { + numberOfHandles=neWithinAllCells; + //mexPrintf(" cell numberOfHandles %d",numberOfHandles); + } + + + PVDataHolder * pvd = new PVDataHolder[numberOfHandles]; + + for (size_t i=0; i2 && (mochaIndex==mochaIndexOriginal || cacheFlag) ) + { + //ischar? + if (!mxIsChar(prhs[2]) ) + { + mexPrintf("3rd input argument must be a char \n"); + return; + } + mdtIndex=NS_MOCHA::getMdtIndex(prhs[2]); + + } + if (mdtIndex==MOCHA_NATIVE) + { + + + + status=cafe.getHandleHelper().getDataTypeRequest(handle, rdt); + + + if (status!=ICAFE_NORMAL) + { + mexPrintf("Error for handle input= %d \n", (uint32_T) mxGetScalar(prhs[1]) ); + NS_MOCHA::printStatus(status); + longStatus[0]=status; plhs[0]=getValueIfError(mdtIndex); - - /* - mexPrintf("status=%s\n", cafe.getCafeStatus().code(status).c_str()); - mexPrintf("status=%s\n", cafe.getCafeStatus().info(status).c_str()); - mexPrintf("status=%s\n", cafe.getCafeStatus().msgID(status).c_str()); - mexPrintf("status=%s\n", cafe.getCafeStatus().severity(status).c_str()); - mexPrintf("status=%s\n", cafe.getCafeStatus().message(status).c_str()); - mexPrintf("status=%s\n", cafe.getCafeStatus().csc.msgIDAsString(status).c_str()); - mexPrintf("status=%s\n", cafe.getCafeStatus().csc.message(status).c_str()); - */ - - if (withExceptions) { - mexErrMsgIdAndTxt(prepareExceptionID(status).c_str(), prepareExceptionText(handle,status).c_str()); - } - + return; } - - break; + + CAFE_DATATYPE cdt = (CAFE_DATATYPE) rdt; + + + + mdtIndex=getMdtIndexFromCafeDataType(cdt); + + + + if (cafe.getHandleHelper().isEnum(handle)) + { + + mdtIndex=MOCHA_STRING; + } + } + + nelem = cafe.getHandleHelper().getNelemClient(handle); //Change Request to Client + + + + if (cafe.getHandleHelper().getOffset(handle) > 0 ) + { + + nelem = min( cafe.getHandleHelper().getNelemClient(handle), + (cafe.getHandleHelper().getNelemNative(handle)-cafe.getHandleHelper().getOffset(handle)) ); + + } + + if(nelem<1) + { + nelem=1; // This is to build output matrix } - - case GET_WF_AS_STRING: + unsigned int nelemPrevious=1; + bool nelemCacheChangeFlag=false; + + if(cacheFlag) { - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, handle/pv \n", nrhs); - return; + + nelem = cafe.getHandleHelper().getNelemToRetrieveFromCache(handle) ; + + //mexPrintf("get Cache: nelem = %d \n", nelem); + + + if ( (cafe.getHandleHelper().getOffsetLast(handle) > 0) || + (cafe.getHandleHelper().getNelemToRetrieveFromCache(handle) > cafe.getHandleHelper().getNelemRequest(handle))) + { + + + //if (nelem > cafe.getHandleHelper().getNelemRequest(handle) ) { + nelemPrevious=cafe.getHandleHelper().getNelemToRetrieveFromCache(handle); + nelem = min( (unsigned int) nelem, cafe.getHandleHelper().getNelemRequest(handle)-cafe.getHandleHelper().getOffsetLast(handle)); + + //mexPrintf("nelem to ret from Cache %d \n",cafe.getHandleHelper().getNelemToRetrieveFromCache(handle)); + //mexPrintf("nelem to ret from Cache %d \n",nelem); + //cafe.getHandleHelper().setNelemToRetrieveFromCache(handle,nelem+cafe.getHandleHelper().getOffsetLast(handle)); + cafe.getHandleHelper().setNelemToRetrieveFromCache(handle,nelem); + nelemCacheChangeFlag=true; } - handle=checkForHandle(prhs[1]); - if(handle==0) { - mexPrintf("Handle does not exist!\n"); - return;} - - string wfStr; - - if (cacheFlag) { - status=cafe.getWFAsString(handle,wfStr); - } - else { - status=cafe.getWFAsStringCache(handle,wfStr); - } - - //plhs[0] = mxCreateCellMatrix(1,2); - //mxSetCell (plhs[0], 0, mxCreateString( wfStr.c_str() )); - - plhs[0] = mxCreateString( wfStr.c_str() ); - - if (status!=ICAFE_NORMAL) { - cafe.printStatus(handle,status); - //NS_MOCHA::printStatus(status); - - if (withExceptions) { - mexErrMsgIdAndTxt(prepareExceptionID(status).c_str(), prepareExceptionText(handle,status).c_str()); - } - } - break; } - - case GET_ALARM: + switch (mdtIndex) { - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, handle/pv \n", nrhs); - return; + case MOCHA_DOUBLE: + plhs[0] = mxCreateDoubleMatrix(1,nelem,mxREAL); + doubleArray = (double *) mxGetPr (plhs[0]); + if(cacheFlag) + { + status=cafe.getCache(handle,doubleArray); } - - handle=checkForHandle(prhs[1]); - if(handle==0) { - mexPrintf("Handle does not exist!\n"); - return;} - - plhs[0] = mxCreateNumericMatrix(1,2, mxINT16_CLASS, mxREAL); - shortArray = (short *) mxGetData(plhs[0]); - - shortArray[0]=-1; - shortArray[1]=-1; - - status=cafe.getHandleHelper().getAlarmStatusSeverity(handle,shortArray); - - if (status!=ICAFE_NORMAL) { - cafe.printStatus(handle,status); - //NS_MOCHA::printStatus(status); - - if (withExceptions) { - mexErrMsgIdAndTxt(prepareExceptionID(status).c_str(), prepareExceptionText(handle,status).c_str()); - } + else + { + status=cafe.get(handle,doubleArray); } break; - } - - case GET_ALARM_AS_STRING: - { - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, handle/pv \n", nrhs); - return; + case MOCHA_FLOAT: + plhs[0] = mxCreateNumericMatrix(1,nelem,mxSINGLE_CLASS, mxREAL); + floatArray = (float *) mxGetData (plhs[0]); + if(cacheFlag) + { + mexPrintf("here"); + status=cafe.getCache(handle,floatArray); + mexPrintf("status %d", status); } - - handle=checkForHandle(prhs[1]); - if(handle==0) { - mexPrintf("Handle does not exist!\n"); - return;} - - - - string asas[2]; - asas[0]=""; - asas[1]=""; - - status=cafe.getHandleHelper().getAlarmStatusSeverityAsString(handle,asas); - - - plhs[0] = mxCreateCellMatrix(1,2); - - mxSetCell (plhs[0], 0, mxCreateString( asas[0].c_str() )); - mxSetCell (plhs[0], 1, mxCreateString( asas[1].c_str() )); - - if (status!=ICAFE_NORMAL) { - cafe.printStatus(handle,status); - //NS_MOCHA::printStatus(status); - - if (withExceptions) { - mexErrMsgIdAndTxt(prepareExceptionID(status).c_str(), prepareExceptionText(handle,status).c_str()); - } + else + { + status=cafe.get(handle,floatArray); } break; - } - - case GET_STATUS: - { - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, handle/pv \n", nrhs); - return; + case MOCHA_INT: + plhs[0] = mxCreateNumericMatrix(1,nelem,mxINT32_CLASS, mxREAL); + longArray = (int32_T *) mxGetData (plhs[0] ); + if(cacheFlag) + { + status=cafe.getCache(handle,longArray); + } + else + { + status=cafe.get(handle,longArray); } - - handle=checkForHandle(prhs[1]); - if(handle==0) { - mexPrintf("Handle does not exist!\n"); - return;} - - status=cafe.getHandleHelper().getStatus(handle); - - plhs[0] = mxCreateNumericMatrix(1,1,mxINT32_CLASS, mxREAL); - - longArray = (int32_T *) mxGetData ( plhs[0]); - longArray[0]= (int32_T) status; - - string s = cafe.getCafeStatus().csi.message(status); - string c = cafe.getCafeStatus().csc.message(status); - - plhs[1] = mxCreateCellMatrix(1,2); - - mxSetCell (plhs[1], 0, mxCreateString( c.c_str() )); - mxSetCell (plhs[1], 1, mxCreateString( s.c_str() )); - break; - } - - case IS_STATUS_TIMEOUT: - { - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, status \n", nrhs); - return; + case MOCHA_SHORT: + plhs[0] = mxCreateNumericMatrix(1,nelem,mxINT16_CLASS, mxREAL); + shortArray = (int16_T *) mxGetData (plhs[0]); + if(cacheFlag) + { + status=cafe.getCache(handle,shortArray); } - - if (!mxIsNumeric(prhs[1]) ) { - mexPrintf("Status does not have a numeric value \n"); - return; + else + { + status=cafe.get(handle,shortArray); } - - plhs[0] = mxCreateLogicalScalar(cafe.getCafeStatus().csc.isTimeout((int32_T) mxGetScalar(prhs[1]))); - - break; - } - - - - - case GET_STATUS_TEXT: - { - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, status \n", nrhs); - return; - } - - if (!mxIsNumeric(prhs[1]) ) { - mexPrintf("Status does not have a numeric value \n"); - return; - } - - string s = cafe.getCafeStatus().csc.message((int32_T) mxGetScalar(prhs[1])); - - plhs[0]=mxCreateString( s.c_str() ); - - //plhs[0] = mxCreateCellMatrix(1,1); - //mxSetCell (plhs[0], 0, mxCreateString( s.c_str())); - break; - } - case GET_STATUS_INFO: - { - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, status \n", nrhs); - return; + case MOCHA_USHORT: + plhs[0] = mxCreateNumericMatrix(1,nelem,mxUINT16_CLASS, mxREAL); + ushortArray = (uint16_T *) mxGetData (plhs[0]); + if(cacheFlag) + { + status=cafe.getCache(handle,ushortArray); } - - if (!mxIsNumeric(prhs[1]) ) { - mexPrintf("Status does not have a numeric value \n" ); - return; + else + { + status=cafe.get(handle,ushortArray); } - - string s = cafe.getCafeStatus().csi.message((int32_T) mxGetScalar(prhs[1])); - - plhs[0]=mxCreateString( s.c_str() ); - - //plhs[0] = mxCreateCellMatrix(1,1); - //mxSetCell (plhs[0], 0, mxCreateString( s.c_str())); - break; - } - case PRINT_STATUS: + case MOCHA_UCHAR: + plhs[0] = mxCreateNumericMatrix(1,nelem,mxUINT8_CLASS, mxREAL); + ucharArray = (uint8_T *) mxGetData (plhs[0]); + if(cacheFlag) + { + status=cafe.getCache(handle,ucharArray); + } + else + { + status=cafe.get(handle,ucharArray); + } + break; + + case MOCHA_STRING: { + dbr_string_t * stringArrayc = new dbr_string_t[nelem]; - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, status \n", nrhs); - return; + if(cacheFlag) + { + status=cafe.getCache(handle,stringArrayc); + } + else + { + status=cafe.get(handle,stringArrayc); } - if (nrhs==2) { + //char *test[40]; + //test[0]="test"; + //test[1]="again"; + //mxChar *pr; + //char *ptr_to_seed_data; + //int c; - if (!mxIsNumeric(prhs[1]) ) { - mexPrintf("Status does not have a numeric value \n"); - return; + + if (status==ICAFE_NORMAL) + { + + if (nelem==1) + { + plhs[0]=mxCreateString( stringArrayc[0] ); + } + else + { + plhs[0] = mxCreateCellMatrix(1,nelem); + for (mwSignedIndex i=0; i 1) { - mexPrintf("Method returns enumerated value/name pairs of alarm conditions \n"); - } - - vector vecS; vector vecI; - cgac.getStates(vecI, vecS); - - plhs[1] = mxCreateNumericMatrix(1,vecI.size(), mxINT32_CLASS,mxREAL); - longArray= (int32_T *) mxGetData(plhs[1]); - - //return string list - plhs[0] = mxCreateCellMatrix(1,vecS.size()); - - for (mwSignedIndex i=0; i1) { - mexPrintf("Method returns enumerated value/name pairs of alarm severities \n"); - } - - vector vecS; vector vecI; - cgas.getStates(vecI, vecS); - - plhs[1] = mxCreateNumericMatrix(1,vecI.size(), mxINT32_CLASS,mxREAL); - longArray= (int32_T *) mxGetData(plhs[1]); - - //return string list - plhs[0] = mxCreateCellMatrix(1,vecS.size()); - - for (mwSignedIndex i=0; i1) { - mexPrintf("Method returns enumerated value/name pairs of status codes \n"); - } - - vector vecS; vector vecI; - cafe.getCafeStatus().csc.getStates(vecI, vecS); - - plhs[1] = mxCreateNumericMatrix(1,vecI.size(), mxINT32_CLASS,mxREAL); - longArray= (int32_T *) mxGetData(plhs[1]); - - //return string list - plhs[0] = mxCreateCellMatrix(1,vecS.size()); - - for (mwSignedIndex i=0; i1) + { + mexPrintf("Method returns enumerated value/name pairs of alarm conditions \n"); + } + + vector vecS; + vector vecI; + cgac.getStates(vecI, vecS); + + plhs[1] = mxCreateNumericMatrix(1,vecI.size(), mxINT32_CLASS,mxREAL); + longArray= (int32_T *) mxGetData(plhs[1]); + + //return string list + plhs[0] = mxCreateCellMatrix(1,vecS.size()); + + for (mwSignedIndex i=0; i1) + { + mexPrintf("Method returns enumerated value/name pairs of alarm severities \n"); + } + + vector vecS; + vector vecI; + cgas.getStates(vecI, vecS); + + plhs[1] = mxCreateNumericMatrix(1,vecI.size(), mxINT32_CLASS,mxREAL); + longArray= (int32_T *) mxGetData(plhs[1]); + + //return string list + plhs[0] = mxCreateCellMatrix(1,vecS.size()); + + for (mwSignedIndex i=0; i1) + { + mexPrintf("Method returns enumerated value/name pairs of status codes \n"); + } + + vector vecS; + vector vecI; + cafe.getCafeStatus().csc.getStates(vecI, vecS); + + plhs[1] = mxCreateNumericMatrix(1,vecI.size(), mxINT32_CLASS,mxREAL); + longArray= (int32_T *) mxGetData(plhs[1]); + + //return string list + plhs[0] = mxCreateCellMatrix(1,vecS.size()); + + for (mwSignedIndex i=0; i vi; - + vector vi; + status=cafe.groupAttach(ghandle, pvg); if (status!=ECAFE_UNKNOWN_GROUP && status != ECAFE_EMPTY_GROUP) { - - status=cafe.groupGetCache(ghandle, pvg); - - vi=cafe.getPulseIDFromTS(pvg); - - } - - plhs[0] = mxCreateNumericMatrix(1,vi.size(), mxUINT32_CLASS,mxREAL); + + status=cafe.groupGetCache(ghandle, pvg); + + vi=cafe.getPulseIDFromTS(pvg); + + } + + plhs[0] = mxCreateNumericMatrix(1,vi.size(), mxUINT32_CLASS,mxREAL); ulongArray= (uint32_T *) mxGetData(plhs[0]); - + for (mwSignedIndex i=0; i::signaling_NaN(); - - //status - plhs[0] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); - longStatus = (int32_T *) mxGetData ( plhs[0]); - longStatus[0]=status; - } - - - break; - } - - case SET_STRUCT_ARRAY: - { - if (nrhs<3) { - mexPrintf("Invalid Number of argument %d. Input: 'setStructArray', handle/pv array, data array \n", nrhs); - return; - } - - - //What is dataType? - handleULong = checkHandleArray(prhs[1],true); - - if (handleULong==NULL) { - mexPrintf("SET_STRUCT_ARRAY: Ignoring NULL value in input\n"); - mexPrintf("Input Invalid. Should be: 'setStructArray', handle/pv array, data array \n"); - return; - } - - - if(handleULong[0]==0) { - mexPrintf("Input Invalid. Should be: 'setStructArray', handle/pv array, data array \n"); - return; - } - - size_t numberOfHandles=mxGetNumberOfElements (prhs[1]); - size_t nDataInputs=nrhs-2; - - //Examine data input - //Break up a cell or an array - //Check no of data inputs - //nelem=nrhs-2; - - /* - if (nhrs=3} { - //neWithinAllDataCells=0; - - - if (mxIsCell(prhs[k])) { - - nDataInputs=getObjectsFromDataCell(prhs[k]); - - mexPrintf("Running No of Elements in Cell = %d \n", nDataInputs); - - } - //else { - // nDataInputs=nDataInputs+1; - //} - } - */ - - - //if (numberOfHandles != nrhs-2) { - if (numberOfHandles != nDataInputs) { - mexPrintf("Input Invalid. Data Array Length %d does not equal No of handles %d! \n", nrhs-2,numberOfHandles); - //mexPrintf("Input Invalid. Data Array Length %d does not equal No of handles %d! \n", nDataInputs,numberOfHandles); - return; - } - - PVDataHolder * du; - - //du = new PVDataHolder[nrhs-2]; - du = new PVDataHolder[nDataInputs]; - - mwSignedIndex j=0; - - for (mwSignedIndex k=2; k3) { - mexPrintf("Ignoring arguments after the 3rd from the %d entered. \nInput: 'setScalarArray', handle/pv array, data array \n", nrhs); - } + NS_MOCHA::printStatus(status); + plhs[1] = mxCreateDoubleMatrix(1,1,mxREAL); + doubleArray = mxGetPr ( plhs[1]); + doubleArray[0]=numeric_limits::signaling_NaN(); - //What is dataType? - handleULong = checkHandleArray(prhs[1],true); - - if (handleULong==NULL) { - mexPrintf("SET_SCALAR_ARRAY: Ignoring NULL value in input \n"); - mexPrintf("Input Invalid. Should be: 'setScalarArray', handle/pv array, data array \n"); - return; - } + //status + plhs[0] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); + longStatus = (int32_T *) mxGetData ( plhs[0]); + longStatus[0]=status; + } - if(handleULong[0]==0) { - mexPrintf("Input Invalid. Should be: 'setScalarArray', handle/pv array, data array \n"); + break; + } + + case SET_STRUCT_ARRAY: + { + if (nrhs<3) + { + mexPrintf("Invalid Number of argument %d. Input: 'setStructArray', handle/pv array, data array \n", nrhs); + return; + } + + + //What is dataType? + handleULong = checkHandleArray(prhs[1],true); + + if (handleULong==NULL) + { + mexPrintf("SET_STRUCT_ARRAY: Ignoring NULL value in input\n"); + mexPrintf("Input Invalid. Should be: 'setStructArray', handle/pv array, data array \n"); + return; + } + + + if(handleULong[0]==0) + { + mexPrintf("Input Invalid. Should be: 'setStructArray', handle/pv array, data array \n"); + return; + } + + size_t numberOfHandles=mxGetNumberOfElements (prhs[1]); + size_t nDataInputs=nrhs-2; + + //Examine data input + //Break up a cell or an array + //Check no of data inputs + //nelem=nrhs-2; + + /* + if (nhrs=3} { + //neWithinAllDataCells=0; + + + if (mxIsCell(prhs[k])) { + + nDataInputs=getObjectsFromDataCell(prhs[k]); + + mexPrintf("Running No of Elements in Cell = %d \n", nDataInputs); + + } + //else { + // nDataInputs=nDataInputs+1; + //} + } + */ + + + //if (numberOfHandles != nrhs-2) { + if (numberOfHandles != nDataInputs) + { + mexPrintf("Input Invalid. Data Array Length %d does not equal No of handles %d! \n", nrhs-2,numberOfHandles); + //mexPrintf("Input Invalid. Data Array Length %d does not equal No of handles %d! \n", nDataInputs,numberOfHandles); + return; + } + + PVDataHolder * du; + + //du = new PVDataHolder[nrhs-2]; + du = new PVDataHolder[nDataInputs]; + + mwSignedIndex j=0; + + for (mwSignedIndex k=2; k3) { - mexPrintf("Ignoring arguments after the 3rd from the %d entered. Input: 'set', handle/pv, data \n", nrhs); - } + mexPrintf("Invalid Number of argument %d. \nInput: 'setScalarArray', handle/pv array, data array \n", nrhs); + return; + } + else if (nrhs>3) + { + mexPrintf("Ignoring arguments after the 3rd from the %d entered. \nInput: 'setScalarArray', handle/pv array, data array \n", nrhs); + } - handle=checkForHandle(prhs[1]); - if(handle==0) {return;} + //What is dataType? + handleULong = checkHandleArray(prhs[1],true); + + if (handleULong==NULL) + { + mexPrintf("SET_SCALAR_ARRAY: Ignoring NULL value in input \n"); + mexPrintf("Input Invalid. Should be: 'setScalarArray', handle/pv array, data array \n"); + return; + } - if (!isValidClass(prhs[2])) return; + if(handleULong[0]==0) + { + mexPrintf("Input Invalid. Should be: 'setScalarArray', handle/pv array, data array \n"); + return; + } - size_t ne = mxGetNumberOfElements ( prhs[2]); + size_t numberOfHandles=mxGetNumberOfElements (prhs[1]); - if(ne==0) { - mexPrintf("Empty Data Array in Input \n"); - return; - } + nelem=mxGetNumberOfElements (prhs[2]); + + if(nelem==0) + { + mexPrintf("Empty Data Array in Input \n"); + return; + } + + if (numberOfHandles != nelem) + { + mexPrintf("Input Invalid. Data Array Length %d does not equal No of handles %d! \n", nelem,numberOfHandles); + return; + } - neWithinAllCells=0; - iWithinAllCells=0; + neWithinAllCells=0; - mxClassID mxid =mxGetClassID( prhs[2]); - - //This line is important for a string as the Number of Elements - //is interpreted as the number of characters!!! - //Hence for ne to be 1 - if (mxid==mxCHAR_CLASS) { ne=1; } - - nelem = cafe.getHandleHelper().getNelemClient(handle); - - - //handle does not exist - if(nelem==0) { - //status - plhs[0] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); - longStatus = (int32_T *) mxGetData ( plhs[0]); - longStatus[0]=ECAFE_INVALID_HANDLE; - - if (withExceptions) { - mexErrMsgIdAndTxt(prepareExceptionID(ECAFE_INVALID_HANDLE).c_str(), prepareExceptionText(handle,ECAFE_INVALID_HANDLE).c_str()); - } - - return; - } - - if(nelem!=ne) {cafe.getHandleHelper().setNelem(handle,ne);} - - mxArray *fout; - switch(mxid) { - case mxDOUBLE_CLASS: - inputDouble = (double *) mxGetPr (prhs[2]); - status=cafe.set(handle,inputDouble); - break; - case mxSINGLE_CLASS: - inputFloat = (float *) mxGetData (prhs[2]); - status=cafe.set(handle,inputFloat); - break; - case mxLOGICAL_CLASS: - inputBool = (bool *) mxGetData (prhs[2]); - fout = mxCreateNumericMatrix(1,ne,mxINT8_CLASS, mxREAL); - inputShort = (short *) mxGetData ( fout ); - for (mwSignedIndex i=0; i3) { - mexPrintf("Ignoring arguments after the 3rd from the %d entered. Input: 'set', handle/pv, data \n", nrhs); - } - - handle=checkForHandle(prhs[1]); - if(handle==0) {return;} + case mxDOUBLE_CLASS: + inputDouble = (double *) mxGetPr (prhs[2]); + status=cafe.set((unsigned int *)handleULong, (unsigned int) numberOfHandles, inputDouble, (int *) longArray); + break; + case mxSINGLE_CLASS: + inputFloat = (float *) mxGetData (prhs[2]); + status=cafe.set((unsigned int *)handleULong, (unsigned int) numberOfHandles, inputFloat, (int *) longArray); + break; + case mxLOGICAL_CLASS: + inputBool = (bool *) mxGetData (prhs[2]); + fout = mxCreateNumericMatrix(1,numberOfHandles,mxINT8_CLASS, mxREAL); + inputShort = (short *) mxGetData ( fout ); + for (mwSignedIndex i=0; i::signaling_NaN(); - - //status - plhs[1] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); - longStatus = (int32_T *) mxGetData ( plhs[1]); - longStatus[0]=ECAFE_INVALID_HANDLE; - - if (withExceptions) { - mexErrMsgIdAndTxt(prepareExceptionID(ECAFE_INVALID_HANDLE).c_str(), prepareExceptionText(handle,ECAFE_INVALID_HANDLE).c_str()); - } - - return; - } - - if(nelem!=ne) {cafe.getHandleHelper().setNelem(handle,ne);} - - size_t neOne=1; //Only deal with first element for the waveform!! - - mxArray *fout; - switch(mxid) { - case mxDOUBLE_CLASS: - inputDouble = (double *) mxGetPr (prhs[2]); - - plhs[0] = mxCreateDoubleMatrix(1,ne,mxREAL); - doubleArray = (double *) mxGetPr (plhs[0]); - - status=cafe.setAndGet(handle,inputDouble[0], doubleArray[0]); - break; - case mxSINGLE_CLASS: - inputFloat = (float *) mxGetData (prhs[2]); - - plhs[0] = mxCreateNumericMatrix(1,ne,mxSINGLE_CLASS, mxREAL); - floatArray = (float *) mxGetData (plhs[0]); - - status=cafe.setAndGet(handle,inputFloat[0], floatArray[0]); - break; - case mxLOGICAL_CLASS: - inputBool = (bool *) mxGetData (prhs[2]); - fout = mxCreateNumericMatrix(1,ne,mxINT8_CLASS, mxREAL); - inputShort = (short *) mxGetData ( fout ); - for (mwSignedIndex i=0; i3) + { + mexPrintf("Ignoring arguments after the 3rd from the %d entered. Input: 'set', handle/pv, data \n", nrhs); + } + + handle=checkForHandle(prhs[1]); + if(handle==0) + { + return; + } + + + if (!isValidClass(prhs[2])) return; + + size_t ne = mxGetNumberOfElements ( prhs[2]); + + if(ne==0) + { + mexPrintf("Empty Data Array in Input \n"); + return; + } + + + neWithinAllCells=0; + iWithinAllCells=0; + + mxClassID mxid =mxGetClassID( prhs[2]); + + //This line is important for a string as the Number of Elements + //is interpreted as the number of characters!!! + //Hence for ne to be 1 + if (mxid==mxCHAR_CLASS) + { + ne=1; + } + + nelem = cafe.getHandleHelper().getNelemClient(handle); + + + //handle does not exist + if(nelem==0) + { + //status + plhs[0] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); + longStatus = (int32_T *) mxGetData ( plhs[0]); + longStatus[0]=ECAFE_INVALID_HANDLE; + + if (withExceptions) + { + mexErrMsgIdAndTxt(prepareExceptionID(ECAFE_INVALID_HANDLE).c_str(), prepareExceptionText(handle,ECAFE_INVALID_HANDLE).c_str()); + } + + return; + } + + if(nelem!=ne) + { + cafe.getHandleHelper().setNelem(handle,ne); + } + + mxArray *fout; + switch(mxid) + { + case mxDOUBLE_CLASS: + inputDouble = (double *) mxGetPr (prhs[2]); + status=cafe.set(handle,inputDouble); + break; + case mxSINGLE_CLASS: + inputFloat = (float *) mxGetData (prhs[2]); + status=cafe.set(handle,inputFloat); + break; + case mxLOGICAL_CLASS: + inputBool = (bool *) mxGetData (prhs[2]); + fout = mxCreateNumericMatrix(1,ne,mxINT8_CLASS, mxREAL); + inputShort = (short *) mxGetData ( fout ); + for (mwSignedIndex i=0; i3) + { + mexPrintf("Ignoring arguments after the 3rd from the %d entered. Input: 'set', handle/pv, data \n", nrhs); + } + + handle=checkForHandle(prhs[1]); + if(handle==0) + { + return; + } + + + if (!isValidClass(prhs[2])) return; + + size_t ne = mxGetNumberOfElements ( prhs[2]); + + if(ne==0) + { + mexPrintf("Empty Data Array in Input \n"); + return; + } + + neWithinAllCells=0; + iWithinAllCells=0; + + mxClassID mxid =mxGetClassID( prhs[2]); + + //This line is important for a string as the Number of Elements + //is interpreted as the number of characters!!! + //Hence for ne to be 1 + if (mxid==mxCHAR_CLASS) + { + ne=1; + } + + nelem = cafe.getHandleHelper().getNelemClient(handle); + + + //handle does not exist + if(nelem==0) + { + + + plhs[0] = mxCreateDoubleMatrix(1,nelem,mxREAL); + doubleArray = (double *) mxGetPr (plhs[0]); + doubleArray[0]=numeric_limits::signaling_NaN(); //status plhs[1] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); longStatus = (int32_T *) mxGetData ( plhs[1]); - longStatus[0]=status; + longStatus[0]=ECAFE_INVALID_HANDLE; - if (status != ICAFE_NORMAL) { - if (withExceptions) { - mexErrMsgIdAndTxt(prepareExceptionID(status).c_str(), prepareExceptionText(handle,status).c_str()); - } - } + if (withExceptions) + { + mexErrMsgIdAndTxt(prepareExceptionID(ECAFE_INVALID_HANDLE).c_str(), prepareExceptionText(handle,ECAFE_INVALID_HANDLE).c_str()); + } + return; + } + + if(nelem!=ne) + { + cafe.getHandleHelper().setNelem(handle,ne); + } + + size_t neOne=1; //Only deal with first element for the waveform!! + + mxArray *fout; + switch(mxid) + { + case mxDOUBLE_CLASS: + inputDouble = (double *) mxGetPr (prhs[2]); + + plhs[0] = mxCreateDoubleMatrix(1,ne,mxREAL); + doubleArray = (double *) mxGetPr (plhs[0]); + + status=cafe.setAndGet(handle,inputDouble[0], doubleArray[0]); + break; + case mxSINGLE_CLASS: + inputFloat = (float *) mxGetData (prhs[2]); + + plhs[0] = mxCreateNumericMatrix(1,ne,mxSINGLE_CLASS, mxREAL); + floatArray = (float *) mxGetData (plhs[0]); + + status=cafe.setAndGet(handle,inputFloat[0], floatArray[0]); + break; + case mxLOGICAL_CLASS: + inputBool = (bool *) mxGetData (prhs[2]); + fout = mxCreateNumericMatrix(1,ne,mxINT8_CLASS, mxREAL); + inputShort = (short *) mxGetData ( fout ); + for (mwSignedIndex i=0; i hV; + hV.clear(); + hV.reserve(numberOfHandles); + vector hrbV; + hrbV.clear(); + hrbV.reserve(numberOfHandles); + for (size_t i=0; i doubleV; + doubleV.clear(); + vector floatV; + floatV.clear(); + vector shortV; + shortV.clear(); + vector ushortV; + ushortV.clear(); + vector ucharV; + ucharV.clear(); + vector longV; + longV.clear(); + vector longlongV; + longlongV.clear(); + vector stringV; + stringV.clear(); + + switch(mxid) + { + case mxDOUBLE_CLASS: + inputDouble = (double *) mxGetPr (prhs[2]); + doubleV.reserve(numberOfHandles); + for (size_t i=0; i hV; hV.clear(); hV.reserve(numberOfHandles); - vector hrbV; hrbV.clear(); hrbV.reserve(numberOfHandles); - for (size_t i=0; i doubleV; doubleV.clear(); - vector floatV; floatV.clear(); - vector shortV; shortV.clear(); - vector ushortV; ushortV.clear(); - vector ucharV; ucharV.clear(); - vector longV; longV.clear(); - vector longlongV; longlongV.clear(); - vector stringV; stringV.clear(); - - switch(mxid) { - case mxDOUBLE_CLASS: - inputDouble = (double *) mxGetPr (prhs[2]); - doubleV.reserve(numberOfHandles); - for (size_t i=0; i2) + { + + for (mwSize i=2; i numberOfHandles) + { + mexPrintf("Handle does not exists for monAction: %s\n", monAction); } - // Single String - case mxCHAR_CLASS: - dbr_string_t inputString;; - mxGetString(prhs[2], inputString, sizeof(dbr_string_t)); - - dbr_string_t toleranceString; - - //Convert tolerance to string if required - if (mxIsNumeric(prhs[4]) ) { - stringstream ss; - ss << mxGetScalar(prhs[4]); - - string strTol = ss.str(); - strcpy(toleranceString,strTol.c_str()); - - } - else { - - mxGetString(prhs[4], toleranceString, sizeof(dbr_string_t)); - } - - stringV.push_back(inputString); - - status=cafe.setAndMatchMany(hV, stringV, hrbV, (string) toleranceString, timeoutLocal, printFlag); - - break; - - default: - - break; - } - - - //status - plhs[0] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); - longStatus = (int32_T *) mxGetData (plhs[0]); - longStatus[0]=status; - - break; - } - - - case MONITOR: - { - if (nrhs<2) { - mexPrintf( - "Invalid Number of argument %d. Input: 'monitor', handle/pv, monitorAction(optional) \n", nrhs); - return; - } - - // - handleULong = checkHandleArray(prhs[1],true); - - if (handleULong==NULL) { - mexPrintf("MONITOR: Ignoring NULL value in input \n"); - mexPrintf("Input Invalid. Should be: 'monitor', handle/pv array \n"); - return; - } - - if(handleULong[0]==0) { - mexPrintf("Input Invalid. Should be: 'monitor', handle/pv array \n"); - return; - } - - - size_t numberOfHandles=mxGetNumberOfElements (prhs[1]); - - - if (mxIsChar(prhs[1]) ) { - numberOfHandles=1; - } - else if (mxIsCell(prhs[1]) ) { - numberOfHandles=neWithinAllCells; - } - - - //In case of multiple actions for multiple handles - - if (nrhs>2) { - - for (mwSize i=2; i numberOfHandles) { - mexPrintf("Handle does not exists for monAction: %s\n", monAction); - - } - - if (!mxIsChar(prhs[i]) ) { + if (!mxIsChar(prhs[i]) ) + { mexPrintf("monitorAction does not have a string value \n" ); mexPrintf("Input: 'monitor', handle/pv, monitorAction(optional)\n" ); return; @@ -4533,92 +5145,103 @@ void macchinettaFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prh //remove leadingTrailing Blanks const char * _monAction=monAction; - + cafe.getHandleHelper().removeLeadingAndTrailingSpaces(_monAction,monAction); cafe.getHandleHelper().addMonitorAction(handleULong[i-2],monAction); - if (nrhs > 3) { - mexPrintf("Handle: %d has monAction: %s\n", handleULong[i-2], monAction); + if (nrhs > 3) + { + mexPrintf("Handle: %d has monAction: %s\n", handleULong[i-2], monAction); } - } } + } - int * statusArray = new int [numberOfHandles]; - unsigned int * monitorID = new unsigned int[numberOfHandles]; - - status=cafe.monitorStart(handleULong, (unsigned int) numberOfHandles, statusArray, monitorID); + int * statusArray = new int [numberOfHandles]; + unsigned int * monitorID = new unsigned int[numberOfHandles]; - //monitorID - plhs[0] = mxCreateNumericMatrix(1,numberOfHandles,mxUINT32_CLASS,mxREAL); - ulongArray = (uint32_T *) mxGetData ( plhs[0]); - for (mwSignedIndex i=0; i stopping all monitors\n" ); + cafe.getHandleHelper().clearMonitorAction(); + status=cafe.monitorStop(); + + } + + else { - if (nrhs==1) { - //mexPrintf("Input: 'monitorStop' ==> stopping all monitors\n" ); - cafe.getHandleHelper().clearMonitorAction(); - status=cafe.monitorStop(); + handleULong = checkHandleArray(prhs[1],true); - } - - else { - - handleULong = checkHandleArray(prhs[1],true); - - if (handleULong==NULL) { - mexPrintf("MONITOR: Ignoring NULL value in input \n"); - mexPrintf("Input Invalid. Should be: 'monitor', handle/pv array \n"); - return; - } - - if(handleULong[0]==0) { + if (handleULong==NULL) + { + mexPrintf("MONITOR: Ignoring NULL value in input \n"); mexPrintf("Input Invalid. Should be: 'monitor', handle/pv array \n"); return; - } + } + + if(handleULong[0]==0) + { + mexPrintf("Input Invalid. Should be: 'monitor', handle/pv array \n"); + return; + } - size_t numberOfHandles=mxGetNumberOfElements (prhs[1]); + size_t numberOfHandles=mxGetNumberOfElements (prhs[1]); - - if (mxIsChar(prhs[1]) ) { + + if (mxIsChar(prhs[1]) ) + { numberOfHandles=1; - } - else if (mxIsCell(prhs[1]) ) { - numberOfHandles=neWithinAllCells; - } + } + else if (mxIsCell(prhs[1]) ) + { + numberOfHandles=neWithinAllCells; + } - //handle=checkForHandle(prhs[1]); - //if(handle==0) {return;} - handle=handleULong[0]; - if (numberOfHandles==1 && nrhs>2) { - - if (!mxIsNumeric(prhs[2]) ) { + //handle=checkForHandle(prhs[1]); + //if(handle==0) {return;} + handle=handleULong[0]; + if (numberOfHandles==1 && nrhs>2) + { + + if (!mxIsNumeric(prhs[2]) ) + { mexPrintf("MonitorID does not have a numeric value \n" ); mexPrintf("Input: 'monitorStop', handle/pv, monitorID(optional)\n" ); return; @@ -4627,1688 +5250,1885 @@ void macchinettaFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prh monitorID = (uint32_T) mxGetScalar(prhs[2]); cafe.getHandleHelper().clearMonitorAction(handle); status=cafe.monitorStop(handle,monitorID); - - if (status!=ICAFE_NORMAL) { - cafe.printStatus(handle,status); - } - - } - else if (numberOfHandles==1) { + + if (status!=ICAFE_NORMAL) + { + cafe.printStatus(handle,status); + } + + } + else if (numberOfHandles==1) + { cafe.getHandleHelper().clearMonitorAction(handle); status=cafe.monitorStop(handle); - if (status!=ICAFE_NORMAL) { - cafe.printStatus(handle,status); - } - - } - else { - - if (nrhs>2) { - mexPrintf("Ignoring third input argument; Stopping all monitors for given array of handles/pvs \n" ); - mexPrintf("Input: 'monitorStop', [handle/pv] array\n" ); - } - - int * statusArray = new int [numberOfHandles]; - - status=cafe.monitorStop(handleULong, (unsigned int) numberOfHandles, statusArray); - - if (status!=ICAFE_NORMAL) { - for (mwSignedIndex i=0; ial; - al=cafe.getHandleHelper().getMonitorAction(true); - - for (int i=0; ihwm; - vectoract; - - cafe.getHandleHelper().getMonitorHandlesAndActions(hwm,act); - - //return handle - plhs[0] = mxCreateNumericMatrix(1,hwm.size(),mxUINT32_CLASS,mxREAL); - ulongArray = (uint32_T *) mxGetData(plhs[0]); - - //return action - plhs[1] = mxCreateCellMatrix(1,act.size()); - - for (size_t i=0; ihwm; - hwm=cafe.getHandleHelper().getHandlesWithMonitors(); - - //return handle - plhs[0] = mxCreateNumericMatrix(1,hwm.size(),mxUINT32_CLASS,mxREAL); - ulongArray = (uint32_T *) mxGetData(plhs[0]); - - for (int i=0; i2) + { + mexPrintf("Ignoring third input argument; Stopping all monitors for given array of handles/pvs \n" ); + mexPrintf("Input: 'monitorStop', [handle/pv] array\n" ); + } + + int * statusArray = new int [numberOfHandles]; + + status=cafe.monitorStop(handleULong, (unsigned int) numberOfHandles, statusArray); + + if (status!=ICAFE_NORMAL) + { + for (mwSignedIndex i=0; i2) { - mexPrintf("Ignoring all input arguments to mocha after the first. \n"); - mexPrintf("Method returns all handles and their PV names \n"); + }// else at top + + //status + plhs[0] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); + longStatus = (int32_T *) mxGetData ( plhs[0]); + longStatus[0]=status; + break; + } + + case MONITOR_FLUSH_EVENT: + { + vectoral; + al=cafe.getHandleHelper().getMonitorAction(true); + + for (int i=0; i dhV; - vector pvV; - cafe.getHandleHelper().getHandles(dhV,pvV); - //return handle - plhs[0] = mxCreateNumericMatrix(1,dhV.size(),mxUINT32_CLASS,mxREAL); - ulongArray = (uint32_T *) mxGetData ( plhs[0]); - for (size_t i=0; i1) { - mexPrintf("Ignoring all input arguments to mocha after the first. \n"); - mexPrintf("Method returns all handles, their PV names and connection states \n"); - } - - - vector dhV; - vector pvV; - vector connV; - cafe.getHandleHelper().getHandleStates(dhV,pvV,connV); - //return handle - plhs[0] = mxCreateNumericMatrix(1,dhV.size(),mxUINT32_CLASS,mxREAL); - plhs[2] = mxCreateNumericMatrix(1,dhV.size(),mxUINT16_CLASS,mxREAL); - - ulongArray = (uint32_T *) mxGetData ( plhs[0]); - for (size_t i=0; i2) { - mexPrintf("Ignoring all input arguments to mocha after the first. \n"); - mexPrintf("Method returns all handles within a group \n"); - } - - - ghandle=checkForGroupHandle(prhs[1]); - if(ghandle==0) { - - //fill with data - mexPrintf("Group entered as input argument has not been defined!\n"); - plhs[0] = mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); - ulongArray = (uint32_T *) mxGetData ( plhs[0]); - - return; - } - - vector dhV = cafe.getHandlesFromWithinGroupV(ghandle); - //return handle - plhs[0] = mxCreateNumericMatrix(1,dhV.size(),mxUINT32_CLASS,mxREAL); - ulongArray = (uint32_T *) mxGetData ( plhs[0]); - for (size_t i=0; ihwm; + vectoract; + + cafe.getHandleHelper().getMonitorHandlesAndActions(hwm,act); + + //return handle + plhs[0] = mxCreateNumericMatrix(1,hwm.size(),mxUINT32_CLASS,mxREAL); + ulongArray = (uint32_T *) mxGetData(plhs[0]); + + //return action + plhs[1] = mxCreateCellMatrix(1,act.size()); + + for (size_t i=0; ihwm; + hwm=cafe.getHandleHelper().getHandlesWithMonitors(); + + //return handle + plhs[0] = mxCreateNumericMatrix(1,hwm.size(),mxUINT32_CLASS,mxREAL); + ulongArray = (uint32_T *) mxGetData(plhs[0]); + + for (int i=0; i dhV; - vector pvV; - cafe.getHandleHelper().getDisconnectedHandles(dhV,pvV); - //return handle - plhs[0] = mxCreateNumericMatrix(1,dhV.size(),mxUINT32_CLASS,mxREAL); - ulongArray = (uint32_T *) mxGetData ( plhs[0]); - for (size_t i=0; i dhV; - vector pvV; - - cafe.getHandleHelper().getConnectedHandles(dhV,pvV); - //return handle - plhs[0] = mxCreateNumericMatrix(1,dhV.size(),mxUINT32_CLASS,mxREAL); - ulongArray = (uint32_T *) mxGetData ( plhs[0]); - for (size_t i=0; i2) + { + mexPrintf("Ignoring all input arguments to mocha after the first. \n"); + mexPrintf("Method returns all handles and their PV names \n"); } - - case GET_CHANNEL_INFO: + + vector dhV; + vector pvV; + cafe.getHandleHelper().getHandles(dhV,pvV); + //return handle + plhs[0] = mxCreateNumericMatrix(1,dhV.size(),mxUINT32_CLASS,mxREAL); + ulongArray = (uint32_T *) mxGetData ( plhs[0]); + for (size_t i=0; i1) { - mexPrintf("Method limited to one handle/pv only. Reporting on first given"); - } - - handle=checkForHandle(prhs[1]); //NoOpen(prhs[1]); - - if (handle==0) { - mexPrintf("Handle does not exist!\n"); - return; - } - - ChannelRegalia channelInfo; - - status=cafe.getChannelInfo(handle, channelInfo); - - /* - cout << channelInfo.getConnectFlag() << endl; - cout << channelInfo.getHostName() << endl; - cout << channelInfo.getChannelID() << endl; - cout << channelInfo.getClassNameAsString() << endl; - cout << channelInfo.getDataType() << endl; - cout << channelInfo.getNelem() << endl; - cout << channelInfo.getConnectionStateAsString() << endl; - cout << channelInfo.getAccessRead() << endl; - cout << channelInfo.getAccessWrite() << endl; - */ - - if (status != ICAFE_SUCCESS) { - NS_MOCHA::printStatus(status); - return; - } - - - plhs[0]=mxCreateStructMatrix(1, 1, nfieldsInfo, fnamesInfo); - + ulongArray[i]=dhV[i]; + } + + plhs[1] = mxCreateCellMatrix(1,pvV.size()); + + for (size_t i=0; i1) + { + mexPrintf("Ignoring all input arguments to mocha after the first. \n"); + mexPrintf("Method returns all handles, their PV names and connection states \n"); + } + + + vector dhV; + vector pvV; + vector connV; + cafe.getHandleHelper().getHandleStates(dhV,pvV,connV); + //return handle + plhs[0] = mxCreateNumericMatrix(1,dhV.size(),mxUINT32_CLASS,mxREAL); + plhs[2] = mxCreateNumericMatrix(1,dhV.size(),mxUINT16_CLASS,mxREAL); + + ulongArray = (uint32_T *) mxGetData ( plhs[0]); + for (size_t i=0; i2) + { + mexPrintf("Ignoring all input arguments to mocha after the first. \n"); + mexPrintf("Method returns all handles within a group \n"); + } + + + ghandle=checkForGroupHandle(prhs[1]); + if(ghandle==0) + { + + //fill with data + mexPrintf("Group entered as input argument has not been defined!\n"); + plhs[0] = mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); + ulongArray = (uint32_T *) mxGetData ( plhs[0]); + + return; + } + + vector dhV = cafe.getHandlesFromWithinGroupV(ghandle); + //return handle + plhs[0] = mxCreateNumericMatrix(1,dhV.size(),mxUINT32_CLASS,mxREAL); + ulongArray = (uint32_T *) mxGetData ( plhs[0]); + for (size_t i=0; i dhV; + vector pvV; + cafe.getHandleHelper().getDisconnectedHandles(dhV,pvV); + //return handle + plhs[0] = mxCreateNumericMatrix(1,dhV.size(),mxUINT32_CLASS,mxREAL); + ulongArray = (uint32_T *) mxGetData ( plhs[0]); + for (size_t i=0; i dhV; + vector pvV; + + cafe.getHandleHelper().getConnectedHandles(dhV,pvV); + //return handle + plhs[0] = mxCreateNumericMatrix(1,dhV.size(),mxUINT32_CLASS,mxREAL); + ulongArray = (uint32_T *) mxGetData ( plhs[0]); + for (size_t i=0; i1) + { + mexPrintf("Method limited to one handle/pv only. Reporting on first given"); + } + + handle=checkForHandle(prhs[1]); //NoOpen(prhs[1]); + + if (handle==0) + { + mexPrintf("Handle does not exist!\n"); + return; + } + + ChannelRegalia channelInfo; + + status=cafe.getChannelInfo(handle, channelInfo); + + /* + cout << channelInfo.getConnectFlag() << endl; + cout << channelInfo.getHostName() << endl; + cout << channelInfo.getChannelID() << endl; + cout << channelInfo.getClassNameAsString() << endl; + cout << channelInfo.getDataType() << endl; + cout << channelInfo.getNelem() << endl; + cout << channelInfo.getConnectionStateAsString() << endl; + cout << channelInfo.getAccessRead() << endl; + cout << channelInfo.getAccessWrite() << endl; + */ + + if (status != ICAFE_SUCCESS) + { + NS_MOCHA::printStatus(status); + return; + } + + + plhs[0]=mxCreateStructMatrix(1, 1, nfieldsInfo, fnamesInfo); + //const char * fnamesInfo[9] ={"channelID","connectFlag","hostName","dataType", //"className","accessRead", "accessWrite","nelem","connectionState"}; - - - //fout0 = mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); - //ulongArray = (uint32_T *) mxGetData (fout1); - //ulongArray[0]=(chid) channelInfo.getChannelID(); - fout0 = mxCreateCellMatrix(1,1); - stringstream ss; - ss << channelInfo.getChannelID(); - string strH = ss.str(); - //mxSetCell (fout0, 0, mxCreateString( strH.c_str())); - - fout0 = mxCreateString( strH.c_str()); - fout1 = mxCreateLogicalScalar(channelInfo.getConnectFlag()); - - fout2 = mxCreateString( channelInfo.getHostName()); - - //fout2 = mxCreateCellMatrix(1,1); - //fout3 = mxCreateCellMatrix(1,1); - //fout4 = mxCreateCellMatrix(1,1); - //fout8 = mxCreateCellMatrix(1,1); - - switch (channelInfo.getDataType()){ - case CAFE_DOUBLE: - fout3 = mxCreateString("DBR_DOUBLE"); - break; - case CAFE_FLOAT: - fout3 = mxCreateString("DBR_FLOAT"); - break; - case CAFE_SHORT: - fout3 = mxCreateString("DBR_SHORT"); - break; - case CAFE_ENUM: - fout3 = mxCreateString("DBR_ENUM"); - break; - case CAFE_CHAR: - fout3 = mxCreateString("DBR_CHAR"); - break; - case CAFE_LONG: - fout3 = mxCreateString("DBR_LONG"); - break; - case CAFE_STRING: - fout3 = mxCreateString("DBR_STRING"); - break; - default: //If not connected for instance - fout3 = mxCreateString("DBR_UNKNOWN"); - break; - } - - - //mxSetCell (fout2, 0, mxCreateString( channelInfo.getHostName())); - //mxSetCell (fout4, 0, mxCreateString( channelInfo.getClassName())); - //mxSetCell (fout8, 0, mxCreateString( channelInfo.getConnectionStateAsString().c_str())); - - fout4 = mxCreateString( channelInfo.getClassNameAsString().c_str()); - fout8 = mxCreateString( channelInfo.getConnectionStateAsString().c_str()); - - fout5 = mxCreateLogicalScalar(channelInfo.getAccessRead()); - fout6 = mxCreateLogicalScalar(channelInfo.getAccessWrite()); - - fout7 = mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); - - inputULong = (uint32_T *) mxGetData (fout7); - inputULong[0]=channelInfo.getNelem(); - - - - fout16=mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); - fHandle = (uint32_T *) mxGetData(fout16); - fHandle[0]=handle; - string s = cafe.getPVFromHandle(handle); - fout17 =mxCreateString( s.c_str() ); - - - - //Prepare struct - - mxSetFieldByNumber(plhs[0], 0, 0, fout16); //handle - mxSetFieldByNumber(plhs[0], 0, 1, fout17); //pv - mxSetFieldByNumber(plhs[0], 0, 2, fout0); - mxSetFieldByNumber(plhs[0], 0, 3, fout1); - mxSetFieldByNumber(plhs[0], 0, 4, fout2); - mxSetFieldByNumber(plhs[0], 0, 5, fout3); - mxSetFieldByNumber(plhs[0], 0, 6, fout4); - mxSetFieldByNumber(plhs[0], 0, 7, fout5); - mxSetFieldByNumber(plhs[0], 0, 8, fout6); - mxSetFieldByNumber(plhs[0], 0, 9, fout7); - mxSetFieldByNumber(plhs[0], 0,10, fout8); + //fout0 = mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); + //ulongArray = (uint32_T *) mxGetData (fout1); + //ulongArray[0]=(chid) channelInfo.getChannelID(); + fout0 = mxCreateCellMatrix(1,1); + stringstream ss; + ss << channelInfo.getChannelID(); + string strH = ss.str(); + //mxSetCell (fout0, 0, mxCreateString( strH.c_str())); + fout0 = mxCreateString( strH.c_str()); + fout1 = mxCreateLogicalScalar(channelInfo.getConnectFlag()); + + fout2 = mxCreateString( channelInfo.getHostName()); + + //fout2 = mxCreateCellMatrix(1,1); + //fout3 = mxCreateCellMatrix(1,1); + //fout4 = mxCreateCellMatrix(1,1); + //fout8 = mxCreateCellMatrix(1,1); + + switch (channelInfo.getDataType()) + { + case CAFE_DOUBLE: + fout3 = mxCreateString("DBR_DOUBLE"); + break; + case CAFE_FLOAT: + fout3 = mxCreateString("DBR_FLOAT"); + break; + case CAFE_SHORT: + fout3 = mxCreateString("DBR_SHORT"); + break; + case CAFE_ENUM: + fout3 = mxCreateString("DBR_ENUM"); + break; + case CAFE_CHAR: + fout3 = mxCreateString("DBR_CHAR"); + break; + case CAFE_LONG: + fout3 = mxCreateString("DBR_LONG"); + break; + case CAFE_STRING: + fout3 = mxCreateString("DBR_STRING"); + break; + default: //If not connected for instance + fout3 = mxCreateString("DBR_UNKNOWN"); break; } + //mxSetCell (fout2, 0, mxCreateString( channelInfo.getHostName())); + //mxSetCell (fout4, 0, mxCreateString( channelInfo.getClassName())); + //mxSetCell (fout8, 0, mxCreateString( channelInfo.getConnectionStateAsString().c_str())); + + fout4 = mxCreateString( channelInfo.getClassNameAsString().c_str()); + fout8 = mxCreateString( channelInfo.getConnectionStateAsString().c_str()); + + fout5 = mxCreateLogicalScalar(channelInfo.getAccessRead()); + fout6 = mxCreateLogicalScalar(channelInfo.getAccessWrite()); + + fout7 = mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); + + inputULong = (uint32_T *) mxGetData (fout7); + inputULong[0]=channelInfo.getNelem(); - case GET_READ_ACCESS: + + fout16=mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); + fHandle = (uint32_T *) mxGetData(fout16); + fHandle[0]=handle; + string s = cafe.getPVFromHandle(handle); + fout17 =mxCreateString( s.c_str() ); + + + + //Prepare struct + + + + mxSetFieldByNumber(plhs[0], 0, 0, fout16); //handle + mxSetFieldByNumber(plhs[0], 0, 1, fout17); //pv + mxSetFieldByNumber(plhs[0], 0, 2, fout0); + mxSetFieldByNumber(plhs[0], 0, 3, fout1); + mxSetFieldByNumber(plhs[0], 0, 4, fout2); + mxSetFieldByNumber(plhs[0], 0, 5, fout3); + mxSetFieldByNumber(plhs[0], 0, 6, fout4); + mxSetFieldByNumber(plhs[0], 0, 7, fout5); + mxSetFieldByNumber(plhs[0], 0, 8, fout6); + mxSetFieldByNumber(plhs[0], 0, 9, fout7); + mxSetFieldByNumber(plhs[0], 0,10, fout8); + + break; + } + + + + + case GET_READ_ACCESS: + { + if (nrhs<2) { - if (nrhs<2) { - mexPrintf( - "Invalid Number of arguments %d. Input: 'getReadAccess', handle \n", nrhs); - return; - } - handle=checkForHandleNoOpen(prhs[1]); - plhs[0] = mxCreateLogicalScalar(cafe.getReadAccess(handle)); + mexPrintf( + "Invalid Number of arguments %d. Input: 'getReadAccess', handle \n", nrhs); + return; + } + handle=checkForHandleNoOpen(prhs[1]); + plhs[0] = mxCreateLogicalScalar(cafe.getReadAccess(handle)); - break; + break; + } + + case GET_WRITE_ACCESS: + { + if (nrhs<2) + { + mexPrintf( + "Invalid Number of arguments %d. Input: 'getWriteAccess', handle \n", nrhs); + return; + } + handle=checkForHandleNoOpen(prhs[1]); + plhs[0] = mxCreateLogicalScalar(cafe.getWriteAccess(handle)); + + break; + } + + + + case FETCH_INDEX_OF_COLLECTION_MEMBER: + { + if (nrhs<3) + { + mexPrintf("Invalid Number of argument %d. Input: message, collectionName, deviceName \n", nrhs); + return; } - case GET_WRITE_ACCESS: + if (!mxIsChar(prhs[1]) ) { - if (nrhs<2) { - mexPrintf( - "Invalid Number of arguments %d. Input: 'getWriteAccess', handle \n", nrhs); - return; - } - handle=checkForHandleNoOpen(prhs[1]); - plhs[0] = mxCreateLogicalScalar(cafe.getWriteAccess(handle)); - - break; + mexPrintf("collectionName does not have a string value \n" ); + return; + } + if (!mxIsChar(prhs[2]) ) + { + mexPrintf("deviceName does not have a string value \n" ); + return; } + //message groupName + yData = (mxArray *) prhs[1]; + pvLength = PVNAME_MAX_SIZE+1; + mxGetString(yData, groupName, pvLength); + //message pvname + xData = (mxArray *) prhs[2]; + mxGetString(xData, pv, pvLength); - case FETCH_INDEX_OF_COLLECTION_MEMBER: + long idx=cafe.fetchIndexOfCollectionMember(groupName, pv); + idx=idx+1; + + plhs[0] = mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); + uint32_T * idxArray = (uint32_T *) mxGetData ( plhs[0]); + + idxArray[0]=(uint32_T) idx; //+1 as first element is matlab array indexed by 1 not 0!! + + break; + } + + case FETCH_INDEX_OF_GROUP_MEMBER: + { + if (nrhs<3) { - if (nrhs<3) { - mexPrintf("Invalid Number of argument %d. Input: message, collectionName, deviceName \n", nrhs); - return; - } + mexPrintf("Invalid Number of argument %d. Input: message, groupName, pv \n", nrhs); + return; + } - if (!mxIsChar(prhs[1]) ) { - mexPrintf("collectionName does not have a string value \n" ); - return; - } - if (!mxIsChar(prhs[2]) ) { - mexPrintf("deviceName does not have a string value \n" ); - return; - } + if (!mxIsChar(prhs[1]) ) + { + mexPrintf("groupName does not have a string value \n" ); + return; + } + if (!mxIsChar(prhs[2]) ) + { + mexPrintf("pv does not have a string value \n"); + return; + } - //message groupName + //message groupName + yData = (mxArray *) prhs[1]; + pvLength = PVNAME_MAX_SIZE+1; + mxGetString(yData, groupName, pvLength); + + //message pvname + xData = (mxArray *) prhs[2]; + mxGetString(xData, pv, pvLength); + + long idx=cafe.fetchIndexOfGroupMember(groupName, pv); + idx=idx+1; + + plhs[0] = mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); + uint32_T * idxArray = (uint32_T *) mxGetData ( plhs[0]); + + idxArray[0]=(uint32_T) idx; //+1 as first element is matlab array indexed by 1 not 0!! + + break; + } + case LIST_GROUPS: + { + vector glist; + glist.clear(); + cafe.groupList(glist); + plhs[0] = mxCreateCellMatrix(1,glist.size()); + for (size_t i=0; i glist; + glist.clear(); + cafe.groupMemberList(groupName,glist); + plhs[0] = mxCreateCellMatrix(glist.size(),1); + for (size_t i=0; i inList; + inList.clear(); + + for (mwSignedIndex k=1; k glist; - glist.clear(); - cafe.groupList(glist); - plhs[0] = mxCreateCellMatrix(1,glist.size()); - for (size_t i=0; i outList= cafe.generateChannelList(inList); + + + plhs[0] = mxCreateCellMatrix(1,outList.size()); + for (size_t i=0; i clist; + clist.clear(); + cafe.collectionList(clist); + plhs[0] = mxCreateCellMatrix(1,clist.size()); + for (size_t i=0; i glist; - glist.clear(); - cafe.groupMemberList(groupName,glist); - plhs[0] = mxCreateCellMatrix(glist.size(),1); - for (size_t i=0; i clist; + clist.clear(); + cafe.collectionMemberList(groupName,clist); + plhs[0] = mxCreateCellMatrix(clist.size(),1); + for (size_t i=0; i/include/config.h is set to false.\n"); + mexPrintf("Please recompile the cafe library with qtxml to use this feature. \n"); + } +#endif } - - case LOAD_SF_GROUPS: - { - - - #ifdef HAVE_PYTHON_H - if (nrhs<2) { - mexPrintf("Loading Virtual Accelertaor groups with loadSFGroups('VA') \n"); - cafe.loadSFGroups("VA"); - } - else { - if (!mxIsChar(prhs[1]) ) { - mexPrintf("Accelerator base name does not have a string value \n" ); - return; - } - yData = (mxArray *) prhs[1]; - pvLength = PVNAME_MAX_SIZE+1; - mxGetString(yData, acceleratorBase, pvLength); - mexPrintf("Loading groups with loadSFGroups: \n"); - cafe.loadSFGroups(acceleratorBase); - } - - #else - mexPrintf("SwissFEL specific method.\n"); - mexPrintf("Requires pythonic version of cafe library.\n"); - mexPrintf("Not activated in this release\n"); - - #endif - - - break; - } - - - case GET_CHANNEL_LIST: - { - - #if HAVE_PYTHON_H - - vector inList; - inList.clear(); - - for (mwSignedIndex k=1; k outList= cafe.generateChannelList(inList); - - - plhs[0] = mxCreateCellMatrix(1,outList.size()); - for (size_t i=0; i clist; clist.clear(); cafe.collectionList(clist); - plhs[0] = mxCreateCellMatrix(1,clist.size()); - for (size_t i=0; i clist; - clist.clear(); - cafe.collectionMemberList(groupName,clist); - plhs[0] = mxCreateCellMatrix(clist.size(),1); - for (size_t i=0; i/include/config.h is set to false.\n"); - mexPrintf("Please recompile the cafe library with qtxml to use this feature. \n"); - } - #endif - - } - else { - mexPrintf("Collections already loaded from XML. Collection names are:\n"); - - vector clist; - clist.clear(); - cafe.collectionList(clist); - - for (size_t i=0; i/include/config.h is false.\n"); + mexPrintf("Please recompile the cafe library with qtxml to use this feature. \n"); + + } +#endif + } - - - case LOAD_XML_GROUPS: + else { - if (nrhs<2) { - mexPrintf("Invalid number of arguments %d. Input: 'loadXMLGroups', fileName \n", nrhs); - return; - } - if (!mxIsChar(prhs[1]) ) { - mexPrintf("filename does not have a string value \n" ); - return; - } - - //message groupName - yData = (mxArray *) prhs[1]; - pvLength = PVNAME_MAX_SIZE+1; - mxGetString(yData, groupName, pvLength); - - - if(!groupsLoaded) { - - #ifdef HAVE_LIBQTXML - { - status=cafe.loadGroupsFromXML((const char *) groupName); + mexPrintf("Groups already loaded from XML. Group names are listed.\n"); + mexPrintf("mocha ('listGroupMembers', ) will list the members of the given group. \n"); + vector glist; + glist.clear(); + cafe.groupList(glist); + + for (size_t i=0; i/include/config.h is false.\n"); - mexPrintf("Please recompile the cafe library with qtxml to use this feature. \n"); - - } - #endif - - } - else { - mexPrintf("Groups already loaded from XML. Group names are listed.\n"); - mexPrintf("mocha ('listGroupMembers', ) will list the members of the given group. \n"); - vector glist; - glist.clear(); - cafe.groupList(glist); - - for (size_t i=0; i2) + { + if( !mxIsLogical(prhs[2]) ) + { + mexPrintf("3rd input argument must be of Matlab type Logical, i.e.true/false \n" ); return; } - if (nrhs>2) { - if( !mxIsLogical(prhs[2]) ) { - mexPrintf("3rd input argument must be of Matlab type Logical, i.e.true/false \n" ); - return; - } - - handle=checkForHandleNoOpen(prhs[1]); - if (handle != 0) { - status=cafe.getPolicy().setSelfGoverningTimeout(handle,mxIsLogicalScalarTrue(prhs[2])); - } - else { - status=ECAFE_INVALID_HANDLE; - mexPrintf("handle=%d does not exist\n", handle); - } + handle=checkForHandleNoOpen(prhs[1]); + if (handle != 0) + { + status=cafe.getPolicy().setSelfGoverningTimeout(handle,mxIsLogicalScalarTrue(prhs[2])); } - else { - if( !mxIsLogical(prhs[1]) ) { - mexPrintf("If method is meant for all handles, then: \n" ); - mexPrintf("1st input argument must be of Matlab type Logical, i.e.true/false \n" ); - return; - } - status=cafe.getPolicy().setSelfGoverningTimeout(mxIsLogicalScalarTrue(prhs[1])); + else + { + status=ECAFE_INVALID_HANDLE; + mexPrintf("handle=%d does not exist\n", handle); } - //status - plhs[0] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); - longStatus = (int32_T *) mxGetData ( plhs[0]); - longStatus[0]=status; - break; - } - - - - - - case SET_TIMEOUT_DEFAULT: + else { - if (nrhs>2) { - mexPrintf("Ignoring all input arguments after the 2nd\n"); - } - - if (nrhs>1) { - - - handle=checkForHandleNoOpen(prhs[1]); - if (handle != 0) { - status=cafe.getPolicy().setTimeoutToDefault(handle); - } - else { - status=ECAFE_INVALID_HANDLE; - } + if( !mxIsLogical(prhs[1]) ) + { + mexPrintf("If method is meant for all handles, then: \n" ); + mexPrintf("1st input argument must be of Matlab type Logical, i.e.true/false \n" ); + return; } - else { - status=cafe.getPolicy().setTimeoutToDefault(); - + status=cafe.getPolicy().setSelfGoverningTimeout(mxIsLogicalScalarTrue(prhs[1])); + } + //status + plhs[0] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); + longStatus = (int32_T *) mxGetData ( plhs[0]); + longStatus[0]=status; + break; + + } + + + + + + case SET_TIMEOUT_DEFAULT: + { + if (nrhs>2) + { + mexPrintf("Ignoring all input arguments after the 2nd\n"); + } + + if (nrhs>1) + { + + + handle=checkForHandleNoOpen(prhs[1]); + if (handle != 0) + { + status=cafe.getPolicy().setTimeoutToDefault(handle); } - - plhs[0] = mxCreateDoubleMatrix(1,2,mxREAL); - doubleArray = mxGetPr ( plhs[0]); - - //Return default timeout - if (status==ICAFE_NORMAL) { - - - double ax=0,bx=0; - if (nrhs>1 && handle!=0) { - - cafe.getPolicy().getTimeout(handle,ax,bx); + else + { + status=ECAFE_INVALID_HANDLE; + } + } + else + { + status=cafe.getPolicy().setTimeoutToDefault(); + + } + + plhs[0] = mxCreateDoubleMatrix(1,2,mxREAL); + doubleArray = mxGetPr ( plhs[0]); + + //Return default timeout + if (status==ICAFE_NORMAL) + { + + + double ax=0,bx=0; + if (nrhs>1 && handle!=0) + { + + cafe.getPolicy().getTimeout(handle,ax,bx); doubleArray[0]=ax; doubleArray[1]=bx; break; - } - else { - double cx=0,dx=0; - cafe.getPolicy().getTimeoutRange(ax,bx,cx,dx); - - doubleArray[0]=min(ax,bx); //min put (min/max should be same) - doubleArray[1]=min(cx,dx); //min get (min/max should be same) - break; - } - } - else { - mexPrintf("Error in setting timeouts to default value!\n"); - doubleArray[0]=-1; - doubleArray[1]=-1; - } - break; - - } - - case SET_TIMEOUT: - { - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, handle, timeout \n", nrhs); - mexPrintf("or message, timeout (applied to all handles) \n"); - - return; } - - if (nrhs>2) { - if (!mxIsNumeric(prhs[2]) ) { - mexPrintf("Timeout does not have a numeric value \n" ); - return; - } - - handle=checkForHandleNoOpen(prhs[1]); - if (handle != 0) { - status=cafe.getPolicy().setTimeout(handle,mxGetScalar(prhs[2])); - } - else { - status=ECAFE_INVALID_HANDLE; - } - } - else { - status=cafe.getPolicy().setTimeout(mxGetScalar(prhs[1])); - } - //status - plhs[0] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); - longStatus = (int32_T *) mxGetData ( plhs[0]); - longStatus[0]=status; - break; - } - - case SET_TIMEOUT_PUT: - { - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, handle, timeout (for put) \n", nrhs); - mexPrintf("or message, timeout (for put, applied to all handles) \n"); - - return; - } - - if (nrhs>2) { - if (!mxIsNumeric(prhs[2]) ) { - mexPrintf("Timeout does not have a numeric value \n" ); - return; - } - - handle=checkForHandleNoOpen(prhs[1]); - if (handle != 0) { - status=cafe.getPolicy().setTimeoutPut(handle,mxGetScalar(prhs[2])); - } - else { - status=ECAFE_INVALID_HANDLE; - } - } - else { - status=cafe.getPolicy().setTimeoutPut(mxGetScalar(prhs[1])); - } - //status - plhs[0] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); - longStatus = (int32_T *) mxGetData ( plhs[0]); - longStatus[0]=status; - break; - } - - - case SET_TIMEOUT_GET: - { - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, handle, timeout (for get) \n", nrhs); - mexPrintf("or message, timeout (for get, applied to all handles) \n"); - - return; - } - - if (nrhs>2) { - if (!mxIsNumeric(prhs[2]) ) { - mexPrintf("Timeout does not have a numeric value \n"); - return; - } - - handle=checkForHandleNoOpen(prhs[1]); - if (handle != 0) { - status=cafe.getPolicy().setTimeoutGet(handle,mxGetScalar(prhs[2])); - } - else { - status=ECAFE_INVALID_HANDLE; - } - } - else { - status=cafe.getPolicy().setTimeoutGet(mxGetScalar(prhs[1])); - } - //status - plhs[0] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); - longStatus = (int32_T *) mxGetData ( plhs[0]); - longStatus[0]=status; - break; - } - - - case GET_TIMEOUT: - { - - plhs[0] = mxCreateDoubleMatrix(1,2,mxREAL); - doubleArray = mxGetPr ( plhs[0]); - - double ax=0,bx=0; - if (nrhs>1) { - handle=checkForHandleNoOpen(prhs[1]); - if (handle != 0) { - cafe.getPolicy().getTimeout(handle,ax,bx); - doubleArray[0]=ax; - doubleArray[1]=bx; - break; - } - else { - mexPrintf("handle=%d does not exist", handle); - } - } - else { + else + { double cx=0,dx=0; cafe.getPolicy().getTimeoutRange(ax,bx,cx,dx); - doubleArray[0]=min(ax,bx); //min put - doubleArray[1]=min(cx,dx); //min,get + doubleArray[0]=min(ax,bx); //min put (min/max should be same) + doubleArray[1]=min(cx,dx); //min get (min/max should be same) break; } - doubleArray[0]=0; - doubleArray[1]=0; - break; + } + else + { + mexPrintf("Error in setting timeouts to default value!\n"); + doubleArray[0]=-1; + doubleArray[1]=-1; + } + break; + + } + + case SET_TIMEOUT: + { + if (nrhs<2) + { + mexPrintf("Invalid Number of argument %d. Input: message, handle, timeout \n", nrhs); + mexPrintf("or message, timeout (applied to all handles) \n"); + + return; } - - case SET_SG_SELF_GOVERNING_TIMEOUT: + if (nrhs>2) { - - - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, gHandle, true/false \n", nrhs); - mexPrintf("or message, true/false (applied to all group handles) \n"); - + if (!mxIsNumeric(prhs[2]) ) + { + mexPrintf("Timeout does not have a numeric value \n" ); return; } - if (nrhs>2) { - if( !mxIsLogical(prhs[2]) ) { - mexPrintf("3rd input argument must be of Matlab type Logical, i.e.true/false \n" ); - return; - } - - ghandle=checkForGroupHandleNoOpen(prhs[1]); - if (ghandle != 0) { - status=cafe.getPolicy().setSGSelfGoverningTimeout(ghandle,mxIsLogicalScalarTrue(prhs[2])); - } - else { - status=ECAFE_INVALID_GROUP_HANDLE; - mexPrintf("ghandle=%d does not exist\n", ghandle); - } + handle=checkForHandleNoOpen(prhs[1]); + if (handle != 0) + { + status=cafe.getPolicy().setTimeout(handle,mxGetScalar(prhs[2])); } - else { - if( !mxIsLogical(prhs[1]) ) { - mexPrintf("If method is meant for all handles, then: \n" ); - mexPrintf("1st input argument must be of Matlab type Logical, i.e.true/false \n" ); - return; - } - status=cafe.getPolicy().setSGSelfGoverningTimeout(mxIsLogicalScalarTrue(prhs[1])); + else + { + status=ECAFE_INVALID_HANDLE; } - //status - plhs[0] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); - longStatus = (int32_T *) mxGetData ( plhs[0]); - longStatus[0]=status; - break; - } - - - - - case SET_SG_TIMEOUT_DEFAULT: + else { - - if (nrhs>2) { - mexPrintf("Ignoring all input arguments after the 2nd\n"); - } - - if (nrhs>1) { - + status=cafe.getPolicy().setTimeout(mxGetScalar(prhs[1])); + } + //status + plhs[0] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); + longStatus = (int32_T *) mxGetData ( plhs[0]); + longStatus[0]=status; + break; + } - ghandle=checkForGroupHandleNoOpen(prhs[1]); - if (ghandle != 0) { - status=cafe.getPolicy().setSGTimeoutToDefault(ghandle); - } - else { - status=ECAFE_INVALID_GROUP_HANDLE; - mexPrintf("ghandle=%d does not exist\n", ghandle); - } + case SET_TIMEOUT_PUT: + { + if (nrhs<2) + { + mexPrintf("Invalid Number of argument %d. Input: message, handle, timeout (for put) \n", nrhs); + mexPrintf("or message, timeout (for put, applied to all handles) \n"); + + return; + } + + if (nrhs>2) + { + if (!mxIsNumeric(prhs[2]) ) + { + mexPrintf("Timeout does not have a numeric value \n" ); + return; } - else { - status=cafe.getPolicy().setSGTimeoutToDefault(); + + handle=checkForHandleNoOpen(prhs[1]); + if (handle != 0) + { + status=cafe.getPolicy().setTimeoutPut(handle,mxGetScalar(prhs[2])); } - - plhs[0] = mxCreateDoubleMatrix(1,2,mxREAL); - doubleArray = mxGetPr ( plhs[0]); - - //Return default timeout - if (status==ICAFE_NORMAL) { - - - double ax=0,bx=0; - if (nrhs>1 && ghandle!=0) { - - cafe.getPolicy().getSGTimeout(ghandle,ax,bx); + else + { + status=ECAFE_INVALID_HANDLE; + } + } + else + { + status=cafe.getPolicy().setTimeoutPut(mxGetScalar(prhs[1])); + } + //status + plhs[0] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); + longStatus = (int32_T *) mxGetData ( plhs[0]); + longStatus[0]=status; + break; + } + + + case SET_TIMEOUT_GET: + { + if (nrhs<2) + { + mexPrintf("Invalid Number of argument %d. Input: message, handle, timeout (for get) \n", nrhs); + mexPrintf("or message, timeout (for get, applied to all handles) \n"); + + return; + } + + if (nrhs>2) + { + if (!mxIsNumeric(prhs[2]) ) + { + mexPrintf("Timeout does not have a numeric value \n"); + return; + } + + handle=checkForHandleNoOpen(prhs[1]); + if (handle != 0) + { + status=cafe.getPolicy().setTimeoutGet(handle,mxGetScalar(prhs[2])); + } + else + { + status=ECAFE_INVALID_HANDLE; + } + } + else + { + status=cafe.getPolicy().setTimeoutGet(mxGetScalar(prhs[1])); + } + //status + plhs[0] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); + longStatus = (int32_T *) mxGetData ( plhs[0]); + longStatus[0]=status; + break; + } + + + case GET_TIMEOUT: + { + + plhs[0] = mxCreateDoubleMatrix(1,2,mxREAL); + doubleArray = mxGetPr ( plhs[0]); + + double ax=0,bx=0; + if (nrhs>1) + { + handle=checkForHandleNoOpen(prhs[1]); + if (handle != 0) + { + cafe.getPolicy().getTimeout(handle,ax,bx); doubleArray[0]=ax; doubleArray[1]=bx; break; - } - else { - double cx=0,dx=0; - cafe.getPolicy().getSGTimeoutRange(ax,bx,cx,dx); - - doubleArray[0]=min(ax,bx); //min put (min/max should be same) - doubleArray[1]=min(cx,dx); //min get (min/max should be same) - break; - } - } - else { - mexPrintf("Error in setting timeouts to default value!\n"); - doubleArray[0]=-1; - doubleArray[1]=-1; - } + } + else + { + mexPrintf("handle=%d does not exist", handle); + } + } + else + { + double cx=0,dx=0; + cafe.getPolicy().getTimeoutRange(ax,bx,cx,dx); + + doubleArray[0]=min(ax,bx); //min put + doubleArray[1]=min(cx,dx); //min,get break; - + } + doubleArray[0]=0; + doubleArray[1]=0; + break; + } + + + case SET_SG_SELF_GOVERNING_TIMEOUT: + { + + + if (nrhs<2) + { + mexPrintf("Invalid Number of argument %d. Input: message, gHandle, true/false \n", nrhs); + mexPrintf("or message, true/false (applied to all group handles) \n"); + + return; } - case SET_SG_TIMEOUT: + if (nrhs>2) { - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, gHandle, timeout \n", nrhs); - mexPrintf("or message, timeout (applied to all group handles) \n"); - + if( !mxIsLogical(prhs[2]) ) + { + mexPrintf("3rd input argument must be of Matlab type Logical, i.e.true/false \n" ); return; } - if (nrhs>2) { - if (!mxIsNumeric(prhs[2]) ) { - mexPrintf("Timeout does not have a numeric value \n" ); - return; - } - - ghandle=checkForGroupHandleNoOpen(prhs[1]); - if (ghandle != 0) { - status=cafe.getPolicy().setSGTimeout(ghandle,mxGetScalar(prhs[2])); - } - else { - status=ECAFE_INVALID_GROUP_HANDLE; - mexPrintf("ghandle=%d does not exist\n", ghandle); - } + ghandle=checkForGroupHandleNoOpen(prhs[1]); + if (ghandle != 0) + { + status=cafe.getPolicy().setSGSelfGoverningTimeout(ghandle,mxIsLogicalScalarTrue(prhs[2])); } - else { - status=cafe.getPolicy().setSGTimeout(mxGetScalar(prhs[1])); + else + { + status=ECAFE_INVALID_GROUP_HANDLE; + mexPrintf("ghandle=%d does not exist\n", ghandle); } - //status - plhs[0] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); - longStatus = (int32_T *) mxGetData ( plhs[0]); - longStatus[0]=status; - break; } - - case SET_SG_TIMEOUT_PUT: + else { - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, gHandle, timeout (for put) \n", nrhs); - mexPrintf("or message, timeout (for put, applied to all group handles) \n"); - + if( !mxIsLogical(prhs[1]) ) + { + mexPrintf("If method is meant for all handles, then: \n" ); + mexPrintf("1st input argument must be of Matlab type Logical, i.e.true/false \n" ); return; } + status=cafe.getPolicy().setSGSelfGoverningTimeout(mxIsLogicalScalarTrue(prhs[1])); + } + //status + plhs[0] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); + longStatus = (int32_T *) mxGetData ( plhs[0]); + longStatus[0]=status; + break; - if (nrhs>2) { - if (!mxIsNumeric(prhs[2]) ) { - mexPrintf("Timeout does not have a numeric value \n" ); - return; - } + } - ghandle=checkForGroupHandleNoOpen(prhs[1]); - if (ghandle != 0) { - status=cafe.getPolicy().setSGTimeoutPut(ghandle,mxGetScalar(prhs[2])); - } - else { - status=ECAFE_INVALID_GROUP_HANDLE; - mexPrintf("ghandle=%d does not exist\n", ghandle); - } - } - else { - status=cafe.getPolicy().setSGTimeoutPut(mxGetScalar(prhs[1])); - } - //status - plhs[0] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); - longStatus = (int32_T *) mxGetData ( plhs[0]); - longStatus[0]=status; - break; + + + + case SET_SG_TIMEOUT_DEFAULT: + { + + if (nrhs>2) + { + mexPrintf("Ignoring all input arguments after the 2nd\n"); } - - case SET_SG_TIMEOUT_GET: + if (nrhs>1) { - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, gHandle, timeout (for get) \n", nrhs); - mexPrintf("or message, timeout (for get, applied to all group handles) \n"); - return; - } - if (nrhs>2) { - if (!mxIsNumeric(prhs[2]) ) { - mexPrintf("Timeout does not have a numeric value \n"); - return; - } - - ghandle=checkForGroupHandleNoOpen(prhs[1]); - if (ghandle != 0) { - status=cafe.getPolicy().setSGTimeoutGet(ghandle,mxGetScalar(prhs[2])); - } - else { - status=ECAFE_INVALID_GROUP_HANDLE; - mexPrintf("ghandle=%d does not exist\n", ghandle); - } + ghandle=checkForGroupHandleNoOpen(prhs[1]); + if (ghandle != 0) + { + status=cafe.getPolicy().setSGTimeoutToDefault(ghandle); } - else { - status=cafe.getPolicy().setSGTimeoutGet(mxGetScalar(prhs[1])); + else + { + status=ECAFE_INVALID_GROUP_HANDLE; + mexPrintf("ghandle=%d does not exist\n", ghandle); } - //status - plhs[0] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); - longStatus = (int32_T *) mxGetData ( plhs[0]); - longStatus[0]=status; - break; + } + else + { + status=cafe.getPolicy().setSGTimeoutToDefault(); } + plhs[0] = mxCreateDoubleMatrix(1,2,mxREAL); + doubleArray = mxGetPr ( plhs[0]); - case GET_SG_TIMEOUT: + //Return default timeout + if (status==ICAFE_NORMAL) { - plhs[0] = mxCreateDoubleMatrix(1,2,mxREAL); - doubleArray = mxGetPr ( plhs[0]); double ax=0,bx=0; - if (nrhs>1) { - ghandle=checkForGroupHandleNoOpen(prhs[1]); - if (ghandle != 0) { - cafe.getPolicy().getSGTimeout(ghandle,ax,bx); - doubleArray[0]=ax; - doubleArray[1]=bx; - break; - } - else { - mexPrintf("ghandle=%d does not exist\n", ghandle); - } + if (nrhs>1 && ghandle!=0) + { + + cafe.getPolicy().getSGTimeout(ghandle,ax,bx); + doubleArray[0]=ax; + doubleArray[1]=bx; + break; } - else { + else + { double cx=0,dx=0; cafe.getPolicy().getSGTimeoutRange(ax,bx,cx,dx); - doubleArray[0]=min(ax,bx); //min put - doubleArray[1]=min(cx,dx); //min,get + doubleArray[0]=min(ax,bx); //min put (min/max should be same) + doubleArray[1]=min(cx,dx); //min get (min/max should be same) break; } - doubleArray[0]=0; - doubleArray[1]=0; - break; } - - case SET_NELEM: + else { - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, handle, nelem (else to native if not given) \n", nrhs); + mexPrintf("Error in setting timeouts to default value!\n"); + doubleArray[0]=-1; + doubleArray[1]=-1; + } + break; + + } + + case SET_SG_TIMEOUT: + { + if (nrhs<2) + { + mexPrintf("Invalid Number of argument %d. Input: message, gHandle, timeout \n", nrhs); + mexPrintf("or message, timeout (applied to all group handles) \n"); + + return; + } + + if (nrhs>2) + { + if (!mxIsNumeric(prhs[2]) ) + { + mexPrintf("Timeout does not have a numeric value \n" ); return; } - uint32_T nDataTransfer= 0; - - if (!mxIsNumeric(prhs[2]) ) { - mexPrintf("nelem does not have a numeric value \n"); - return; - } - - handle=checkForHandleNoOpen(prhs[1]); - if (handle != 0) { - if (cacheFlag) { - if (nrhs >2) { - nDataTransfer=cafe.getHandleHelper().setNelemToRetrieveFromCache(handle,mxGetScalar(prhs[2])); - } - else if (nrhs==2) { - nDataTransfer=cafe.getHandleHelper().setNelemToRetrieveFromCache(handle); - } - //mexPrintf("nDataTransfer for Cache = %d", nDataTransfer); - } - else { - if (nrhs >2) { - nDataTransfer=cafe.getHandleHelper().setNelem(handle,mxGetScalar(prhs[2])); - } - else if (nrhs==2) { - nDataTransfer=cafe.getHandleHelper().setNelem(handle); - } - - } - } - - //nDataTransfer - plhs[0] = mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); - ulongArray = (uint32_T *) mxGetData ( plhs[0]); - ulongArray[0]= nDataTransfer; - break; + ghandle=checkForGroupHandleNoOpen(prhs[1]); + if (ghandle != 0) + { + status=cafe.getPolicy().setSGTimeout(ghandle,mxGetScalar(prhs[2])); + } + else + { + status=ECAFE_INVALID_GROUP_HANDLE; + mexPrintf("ghandle=%d does not exist\n", ghandle); + } } - - case SET_OFFSET: + else { - if (nrhs<3) { - mexPrintf("Invalid Number of argument %d. Input: message, handle, offset \n", nrhs); + status=cafe.getPolicy().setSGTimeout(mxGetScalar(prhs[1])); + } + //status + plhs[0] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); + longStatus = (int32_T *) mxGetData ( plhs[0]); + longStatus[0]=status; + break; + } + + case SET_SG_TIMEOUT_PUT: + { + if (nrhs<2) + { + mexPrintf("Invalid Number of argument %d. Input: message, gHandle, timeout (for put) \n", nrhs); + mexPrintf("or message, timeout (for put, applied to all group handles) \n"); + + return; + } + + if (nrhs>2) + { + if (!mxIsNumeric(prhs[2]) ) + { + mexPrintf("Timeout does not have a numeric value \n" ); return; } - uint32_T nOffset= 0; - - if (!mxIsNumeric(prhs[2]) ) { - mexPrintf("offset does not have a numeric value \n" ); - return; - } + ghandle=checkForGroupHandleNoOpen(prhs[1]); + if (ghandle != 0) + { + status=cafe.getPolicy().setSGTimeoutPut(ghandle,mxGetScalar(prhs[2])); + } + else + { + status=ECAFE_INVALID_GROUP_HANDLE; + mexPrintf("ghandle=%d does not exist\n", ghandle); + } + } + else + { + status=cafe.getPolicy().setSGTimeoutPut(mxGetScalar(prhs[1])); + } + //status + plhs[0] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); + longStatus = (int32_T *) mxGetData ( plhs[0]); + longStatus[0]=status; + break; + } - handle=checkForHandleNoOpen(prhs[1]); - if (handle != 0) { - nOffset=cafe.getHandleHelper().setOffset(handle,mxGetScalar(prhs[2])); - } - - - //nOffset - plhs[0] = mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); - ulongArray = (uint32_T *) mxGetData ( plhs[0]); - ulongArray[0]= nOffset; - break; + + case SET_SG_TIMEOUT_GET: + { + if (nrhs<2) + { + mexPrintf("Invalid Number of argument %d. Input: message, gHandle, timeout (for get) \n", nrhs); + mexPrintf("or message, timeout (for get, applied to all group handles) \n"); + + return; } - case GET_NELEM_NATIVE: + if (nrhs>2) { - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, handle\n", nrhs); + if (!mxIsNumeric(prhs[2]) ) + { + mexPrintf("Timeout does not have a numeric value \n"); return; } - uint32_T nElements= 0; - - - handle=checkForHandleNoOpen(prhs[1]); - if (handle != 0) { - nElements=cafe.getHandleHelper().getNelemNative(handle); - } - - - //nElements - plhs[0] = mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); - ulongArray = (uint32_T *) mxGetData ( plhs[0]); - ulongArray[0]= nElements; - break; - } - - case GET_NELEM_CLIENT: - { - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, handle\n", nrhs); - return; + ghandle=checkForGroupHandleNoOpen(prhs[1]); + if (ghandle != 0) + { + status=cafe.getPolicy().setSGTimeoutGet(ghandle,mxGetScalar(prhs[2])); } - - uint32_T nElements= 0; - - - handle=checkForHandleNoOpen(prhs[1]); - if (handle != 0) { - nElements=cafe.getHandleHelper().getNelemClient(handle); - } - - - //nElements - plhs[0] = mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); - ulongArray = (uint32_T *) mxGetData ( plhs[0]); - ulongArray[0]= nElements; - break; - } - - - case GET_NELEM_REQUEST: - { - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, handle\n", nrhs); - return; + else + { + status=ECAFE_INVALID_GROUP_HANDLE; + mexPrintf("ghandle=%d does not exist\n", ghandle); } - - uint32_T nElements= 0; - - handle=checkForHandleNoOpen(prhs[1]); - if (handle != 0) { - if(cacheFlag) { - nElements=cafe.getHandleHelper().getNelemToRetrieveFromCache(handle); - } - else { - nElements=cafe.getHandleHelper().getNelemRequest(handle); - } - } - - - //nElements - plhs[0] = mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); - ulongArray = (uint32_T *) mxGetData ( plhs[0]); - ulongArray[0]= nElements; - break; } - - - case GET_NELEM: + else { - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, handle\n", nrhs); - return; - } - - uint32_T nElements[3]; // client, native, requested - nElements[0]=0; nElements[1]=0; nElements[2]=0; - - handle=checkForHandleNoOpen(prhs[1]); - if (handle != 0) { - cafe.getHandleHelper().getNelem(handle, nElements[0], nElements[1], nElements[2]); - } - - - //nElements - plhs[0] = mxCreateNumericMatrix(1,3,mxUINT32_CLASS,mxREAL); - ulongArray = (uint32_T *) mxGetData ( plhs[0]); - ulongArray[0]= nElements[0]; - ulongArray[1]= nElements[1]; - ulongArray[2]= nElements[2]; - break; + status=cafe.getPolicy().setSGTimeoutGet(mxGetScalar(prhs[1])); } - - - case GET_OFFSET: + //status + plhs[0] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); + longStatus = (int32_T *) mxGetData ( plhs[0]); + longStatus[0]=status; + break; + } + + + case GET_SG_TIMEOUT: + { + + plhs[0] = mxCreateDoubleMatrix(1,2,mxREAL); + doubleArray = mxGetPr ( plhs[0]); + + double ax=0,bx=0; + if (nrhs>1) { - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, handle\n", nrhs); - return; + ghandle=checkForGroupHandleNoOpen(prhs[1]); + if (ghandle != 0) + { + cafe.getPolicy().getSGTimeout(ghandle,ax,bx); + doubleArray[0]=ax; + doubleArray[1]=bx; + break; } + else + { + mexPrintf("ghandle=%d does not exist\n", ghandle); + } + } + else + { + double cx=0,dx=0; + cafe.getPolicy().getSGTimeoutRange(ax,bx,cx,dx); - uint32_T nOffset= 0; - - handle=checkForHandleNoOpen(prhs[1]); - if (handle != 0) { - nOffset=cafe.getHandleHelper().getOffset(handle); - } - - //nOffset - plhs[0] = mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); - ulongArray = (uint32_T *) mxGetData (plhs[0]); - ulongArray[0]= nOffset; + doubleArray[0]=min(ax,bx); //min put + doubleArray[1]=min(cx,dx); //min,get break; } + doubleArray[0]=0; + doubleArray[1]=0; + break; + } + + case SET_NELEM: + { + if (nrhs<2) + { + mexPrintf("Invalid Number of argument %d. Input: message, handle, nelem (else to native if not given) \n", nrhs); + return; + } + + uint32_T nDataTransfer= 0; + + if (!mxIsNumeric(prhs[2]) ) + { + mexPrintf("nelem does not have a numeric value \n"); + return; + } + + handle=checkForHandleNoOpen(prhs[1]); + if (handle != 0) + { + if (cacheFlag) + { + if (nrhs >2) + { + nDataTransfer=cafe.getHandleHelper().setNelemToRetrieveFromCache(handle,mxGetScalar(prhs[2])); + } + else if (nrhs==2) + { + nDataTransfer=cafe.getHandleHelper().setNelemToRetrieveFromCache(handle); + } + //mexPrintf("nDataTransfer for Cache = %d", nDataTransfer); + } + else + { + if (nrhs >2) + { + nDataTransfer=cafe.getHandleHelper().setNelem(handle,mxGetScalar(prhs[2])); + } + else if (nrhs==2) + { + nDataTransfer=cafe.getHandleHelper().setNelem(handle); + } + + } + } + + //nDataTransfer + plhs[0] = mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); + ulongArray = (uint32_T *) mxGetData ( plhs[0]); + ulongArray[0]= nDataTransfer; + break; + } + + case SET_OFFSET: + { + if (nrhs<3) + { + mexPrintf("Invalid Number of argument %d. Input: message, handle, offset \n", nrhs); + return; + } + + uint32_T nOffset= 0; + + if (!mxIsNumeric(prhs[2]) ) + { + mexPrintf("offset does not have a numeric value \n" ); + return; + } + + handle=checkForHandleNoOpen(prhs[1]); + if (handle != 0) + { + nOffset=cafe.getHandleHelper().setOffset(handle,mxGetScalar(prhs[2])); + } + //nOffset + plhs[0] = mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); + ulongArray = (uint32_T *) mxGetData ( plhs[0]); + ulongArray[0]= nOffset; + break; + } + + case GET_NELEM_NATIVE: + { + if (nrhs<2) + { + mexPrintf("Invalid Number of argument %d. Input: message, handle\n", nrhs); + return; + } + + uint32_T nElements= 0; - default: - char * _messOriginal=messOriginal; - cafe.getHandleHelper().removeLeadingAndTrailingSpaces(_messOriginal,messOriginal); - mexPrintf("%s %s\n","Unknown message--->", messOriginal); - plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL); - doubleArray = mxGetPr ( plhs[0]); - doubleArray[0]=numeric_limits::signaling_NaN(); - break; + handle=checkForHandleNoOpen(prhs[1]); + if (handle != 0) + { + nElements=cafe.getHandleHelper().getNelemNative(handle); + } + + + //nElements + plhs[0] = mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); + ulongArray = (uint32_T *) mxGetData ( plhs[0]); + ulongArray[0]= nElements; + break; + } + + case GET_NELEM_CLIENT: + { + if (nrhs<2) + { + mexPrintf("Invalid Number of argument %d. Input: message, handle\n", nrhs); + return; + } + + uint32_T nElements= 0; + + + handle=checkForHandleNoOpen(prhs[1]); + if (handle != 0) + { + nElements=cafe.getHandleHelper().getNelemClient(handle); + } + + + //nElements + plhs[0] = mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); + ulongArray = (uint32_T *) mxGetData ( plhs[0]); + ulongArray[0]= nElements; + break; + } + + + case GET_NELEM_REQUEST: + { + if (nrhs<2) + { + mexPrintf("Invalid Number of argument %d. Input: message, handle\n", nrhs); + return; + } + + uint32_T nElements= 0; + + handle=checkForHandleNoOpen(prhs[1]); + if (handle != 0) + { + if(cacheFlag) + { + nElements=cafe.getHandleHelper().getNelemToRetrieveFromCache(handle); + } + else + { + nElements=cafe.getHandleHelper().getNelemRequest(handle); + } + } + + + //nElements + plhs[0] = mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); + ulongArray = (uint32_T *) mxGetData ( plhs[0]); + ulongArray[0]= nElements; + break; + } + + + case GET_NELEM: + { + if (nrhs<2) + { + mexPrintf("Invalid Number of argument %d. Input: message, handle\n", nrhs); + return; + } + + uint32_T nElements[3]; // client, native, requested + nElements[0]=0; + nElements[1]=0; + nElements[2]=0; + + handle=checkForHandleNoOpen(prhs[1]); + if (handle != 0) + { + cafe.getHandleHelper().getNelem(handle, nElements[0], nElements[1], nElements[2]); + } + + + //nElements + plhs[0] = mxCreateNumericMatrix(1,3,mxUINT32_CLASS,mxREAL); + ulongArray = (uint32_T *) mxGetData ( plhs[0]); + ulongArray[0]= nElements[0]; + ulongArray[1]= nElements[1]; + ulongArray[2]= nElements[2]; + break; + } + + + case GET_OFFSET: + { + if (nrhs<2) + { + mexPrintf("Invalid Number of argument %d. Input: message, handle\n", nrhs); + return; + } + + uint32_T nOffset= 0; + + handle=checkForHandleNoOpen(prhs[1]); + if (handle != 0) + { + nOffset=cafe.getHandleHelper().getOffset(handle); + } + + //nOffset + plhs[0] = mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); + ulongArray = (uint32_T *) mxGetData (plhs[0]); + ulongArray[0]= nOffset; + break; + } + + + + + default: + char * _messOriginal=messOriginal; + cafe.getHandleHelper().removeLeadingAndTrailingSpaces(_messOriginal,messOriginal); + mexPrintf("%s %s\n","Unknown message--->", messOriginal); + plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL); + doubleArray = mxGetPr ( plhs[0]); + doubleArray[0]=numeric_limits::signaling_NaN(); + break; }//End Big Switch -return; + return; }