MCPcopy Create free account
hub / github.com/SoarGroup/Soar / Message_Library

Method Message_Library

Core/SoarKernel/src/soar_instance.cpp:84–153  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

82}
83
84std::string Soar_Instance::Message_Library(const char* pMessage)
85{
86 std::string resultString("CLI extension command failed.");
87 Soar_Loaded_Library* libraryInfo;
88
89 /* -- Convert command to lower case -- */
90 std::string lFullCommand(pMessage);
91 std::transform(lFullCommand.begin(), lFullCommand.end(), lFullCommand.begin(), ::tolower);
92
93 /* -- Compose the library name = CLI extension name + SoarLib.
94 * Note that the LoadExternalLibrary command will take care of any platform-specific
95 * extensions. -- */
96 std::string lCLIExtensionName = lFullCommand.substr(0, lFullCommand.find(' '));
97 std::string lMessage = lFullCommand.substr(lCLIExtensionName.size() + 1, lFullCommand.size() - 1);
98 lCLIExtensionName += "soarlib";
99
100 std::map< std::string, Soar_Loaded_Library* >::iterator iter = (*m_loadedLibraries).find(lCLIExtensionName.c_str());
101 if (iter == (*m_loadedLibraries).end())
102 {
103 // load library
104 std::string result = m_Kernel->LoadExternalLibrary(lCLIExtensionName.c_str());
105
106 // zero length is success
107 if (result.size() != 0)
108 {
109 resultString = "Could not load library " + lCLIExtensionName + ": " + result;
110 return resultString;
111 }
112 }
113 /* -- A new library will register itself, so it will now have a
114 * libraryInfo entry even if it was not found above. -- */
115 libraryInfo = (*m_loadedLibraries)[lCLIExtensionName.c_str()];
116
117 if (((lMessage == "on") && libraryInfo->isOn) || ((lMessage == "off") && !libraryInfo->isOn))
118 {
119 resultString = "CLI extension " + lCLIExtensionName + "is already " + lMessage + ". Ignoring command.";
120 return resultString;
121 }
122 if (lMessage == "off")
123 {
124 resultString = "Turning off CLI modules is currently disabled. Will be fixed in future version. Restart Soar to turn off for now.";
125 return resultString;
126 }
127 void* success = libraryInfo->libMessageFunction(lMessage.c_str(), NULL);
128 if (!success)
129 {
130 resultString = "Message " + lMessage + " to CLI library " + lCLIExtensionName + " returned unsuccessful.";
131 return resultString;
132 }
133 else
134 {
135 // Note that may be other possible messages in the future, so these
136 // arent' the only two cases.
137 if (lMessage == "on")
138 {
139 libraryInfo->isOn = true;
140 resultString = "\n" + lCLIExtensionName + " CLI module loaded and enabled.\n";
141 m_Output_Manager->print_trace(resultString.c_str());

Callers 1

Calls 5

endMethod · 0.80
LoadExternalLibraryMethod · 0.80
print_traceMethod · 0.80
findMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected