Repository navigation
Expand file tree
/
Copy pathecmcCppLogicCmd.cpp
More file actions
110 lines (89 loc) · 2.87 KB
/
Copy pathecmcCppLogicCmd.cpp
File metadata and controls
110 lines (89 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*************************************************************************\
* Copyright (c) 2026 Paul Scherrer Institute
* ecmc is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
*
* ecmcCppLogicCmd.cpp
*
\*************************************************************************/
#include "ecmcCppLogicCmd.h"
#include "ecmcCppLogicLib.h"
#include "ecmcDefinitions.h"
#include "ecmcError.h"
#include "ecmcErrorsList.h"
#include "ecmcGlobalsExtern.h"
#include "ecmcOctetIF.h"
#include <string>
namespace {
std::string g_lastCppLogicErrorMessage;
}
const char* getLastCppLogicErrorMessage(void) {
return g_lastCppLogicErrorMessage.empty() ? "" : g_lastCppLogicErrorMessage.c_str();
}
int loadCppLogic(int logicId, const char* filenameWP, const char* configStr) {
LOGINFO4("%s/%s:%d logicId=%d filenameWP=%s configStr=%s\n",
__FILE__,
__FUNCTION__,
__LINE__,
logicId,
filenameWP ? filenameWP : "(null)",
configStr ? configStr : "(null)");
g_lastCppLogicErrorMessage.clear();
if ((logicId < 0) || (logicId >= ECMC_MAX_PLUGINS)) {
return ERROR_MAIN_CPP_LOGIC_INDEX_OUT_OF_RANGE;
}
if (cppLogics[logicId]) {
delete cppLogics[logicId];
cppLogics[logicId] = NULL;
}
cppLogics[logicId] = new ecmcCppLogicLib(logicId);
if (!cppLogics[logicId]) {
return ERROR_MAIN_CPP_LOGIC_OBJECT_NULL;
}
int errorCode = cppLogics[logicId]->load(filenameWP, configStr ? configStr : "");
if (errorCode) {
g_lastCppLogicErrorMessage = cppLogics[logicId]->getLastErrorMessage();
LOGERR("%s/%s:%d: LoadCppLogic(%d, %s) failed: %s (0x%x).\n",
__FILE__,
__FUNCTION__,
__LINE__,
logicId,
filenameWP ? filenameWP : "(null)",
ecmcError::convertErrorIdToString(errorCode),
errorCode);
delete cppLogics[logicId];
cppLogics[logicId] = NULL;
return errorCode;
}
return 0;
}
int appendCppLogicMacros(int logicId, const char* macrosText) {
LOGINFO4("%s/%s:%d logicId=%d macrosText=%s\n",
__FILE__,
__FUNCTION__,
__LINE__,
logicId,
macrosText ? macrosText : "(null)");
if ((logicId < 0) || (logicId >= ECMC_MAX_PLUGINS)) {
return ERROR_MAIN_CPP_LOGIC_INDEX_OUT_OF_RANGE;
}
if (!cppLogics[logicId]) {
return ERROR_MAIN_CPP_LOGIC_OBJECT_NULL;
}
return cppLogics[logicId]->appendMacros(macrosText ? macrosText : "");
}
int reportCppLogic(int logicId) {
LOGINFO4("%s/%s:%d logicId=%d\n",
__FILE__,
__FUNCTION__,
__LINE__,
logicId);
if ((logicId < 0) || (logicId >= ECMC_MAX_PLUGINS)) {
return ERROR_MAIN_CPP_LOGIC_INDEX_OUT_OF_RANGE;
}
if (!cppLogics[logicId]) {
return ERROR_MAIN_CPP_LOGIC_OBJECT_NULL;
}
cppLogics[logicId]->report();
return 0;
}