13 #include <msgpack.hpp>
14 #include <Poco/Timestamp.h>
15 #include <Poco/Exception.h>
31 #define COMPONENTS_COUNT 4
34 using namespace HCE::component;
35 using namespace HCE::exception;
39 extern Poco::AutoPtr<Poco::Util::AbstractConfiguration>
_config;
44 Application::Application():exitFlag(false), componentManagerPool(nullptr), crossThreadBufPtr(nullptr), contentsStoragePtr(nullptr)
68 Poco::SharedPtr<Poco::ThreadPool> thPool = Poco::SharedPtr<Poco::ThreadPool>(
new Poco::ThreadPool());
69 Poco::SharedPtr<ComponentBase> localComponent =
nullptr;
70 Poco::SharedPtr<ComponentManager> localComponentManager =
nullptr;
73 localComponentManager = Poco::SharedPtr<ComponentManager>(
new ComponentManager());
74 localComponentManager->setThreadPool(thPool);
82 localComponentManager->addComponent(localComponent);
85 localComponentManager->start();
98 if(wcacheString.length() > 0)
101 msgpack::unpacked msg;
102 msgpack::unpack(&msg, wcacheString.c_str(), wcacheString.length());
103 msgpack::object obj = msg.get();
107 if(serializeCacheData.
resCrc != resCrc)
109 std::cerr <<
">>> Bad Resource cache CRC "<< std::endl;
114 (*wordPosPtr) = serializeCacheData.
data;
118 catch(msgpack::type_error &err)
120 std::cerr <<
">>> Bad MSGPACK format "<< std::endl;
127 std::string inBuff(msgPackBuf.data(), msgPackBuf.size());
128 std::string base64Buff = ((msgPackBuf.size() > 0 ) ?
HCE::encodeBase64(inBuff) :
"");
129 outDataStructPtr->addWcache(base64Buff);
143 Poco::SharedPtr<DataBase> outData =
nullptr;
144 Poco::SharedPtr<InDataHighlight> inDataHighlight =
nullptr;
149 for(
unsigned int y = 0; y < inDataStructPtr->getContentsCount(); y++)
151 unsigned long long resCrc = 0llu;
153 resCrc = crc64.
calc(inDataStructPtr->getContent(y).c_str(), inDataStructPtr->getContent(y).length());
156 if(inDataStructPtr->getWcachesCount() > y)
158 addWCache(resCrc, inDataStructPtr->getWcache(y));
161 inOutDataElem.
setInData(inDataStructPtr->getContent(y));
163 inOutDataElem.
setId(y);
168 if(inDataStructPtr->getParamsCount() > 0 && inDataStructPtr->getParams(0).timeout != 0)
170 timeout = inDataStructPtr->getParams(0).timeout;
174 for(
unsigned int y = 0; y < inDataStructPtr->getContentsCount(); y++)
177 inDataHighlight->setInDataStructPtr(inDataStructPtr);
191 unsigned int tOut = 0;
217 unsigned int highlightCounterSum = 0;
227 outDataStructPtr->addContent(outputStr);
235 outDataStructPtr->addWcache(
"");
238 outDataStructPtr->setFoundCounter(highlightCounterSum);
239 outDataStructPtr->setHighlightedCounter(highlightCounterSum);
255 int ret = Poco::Util::Application::EXIT_OK;
263 Poco::Timestamp timer;
267 std::string incomeString;
268 Poco::SharedPtr<InDataStruct> inDataStructPtr =
nullptr;
269 Poco::SharedPtr<OutDataStruct> outDataStructPtr = Poco::SharedPtr<OutDataStruct>(
new OutDataStruct());
273 if(!incomeString.empty())
277 inDataStructPtr = highlightJsonWrapper.inDataFromJsomString(incomeString);
281 std::cerr <<
">>> Error with parsing incoming JSON = ["<< excpt.
what() <<
"]" << std::endl;
283 if(!inDataStructPtr.isNull() && inDataStructPtr->getParamsCount() > 0)
292 outDataStructPtr->setHighlightedCounter(outDataStructPtr->getHighlightedCounter());
293 outDataStructPtr->setFoundCounter(outDataStructPtr->getFoundCounter());
297 highlightJsonWrapper.jsonStringFromOutData(outDataStructPtr, outDataString, timer.elapsed());
301 std::cerr <<
">>> Error with creating outgoing JSON String = "<< std::endl;
303 std::cout << outDataString << std::endl;
309 ret = Poco::Util::Application::EXIT_CONFIG;
316 std::stringbuf sBuff;
317 std::cin.get(sBuff, BREAK_SYMBOL);
318 incomeString = sBuff.str();
334 catch(
const Poco::NotFoundException& exception)
350 Poco::Util::HelpFormatter helpFormatter(options());
351 helpFormatter.setCommand(commandName());
352 helpFormatter.setUsage(
"OPTIONS");
353 helpFormatter.setHeader(
"Some options that demonstrates some of the features of the Highlighter application");
354 helpFormatter.format(std::cout);
355 ::_exit(Poco::Util::Application::EXIT_OK);
364 std::string appVersion = std::string(APP_VERSION) +
" " + std::string(__DATE__) +
" " + std::string(__TIME__);
365 std::cout << appVersion << std::endl;
366 ::_exit(Poco::Util::Application::EXIT_OK);