Skip to content

Commit

Permalink
added serializing control module info
Browse files Browse the repository at this point in the history
  • Loading branch information
mraduldubey committed Sep 30, 2024
1 parent 9fa858f commit bdb9776
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
3 changes: 2 additions & 1 deletion base/include/AbsControlModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AbsControlModule : public Module {
bool term();
bool enrollModule(std::string role, boost::shared_ptr<Module> module);
boost::shared_ptr<Module> getModuleofRole(std::string role);
virtual std::string getStatus() { return ""; };
std::string printStatus();
virtual void handleMp4MissingVideotrack(std::string previousVideoFile, std::string nextVideoFile) {}
virtual void handleMMQExport(Command cmd, bool priority = false) {}
virtual void handleMMQExportView(uint64_t startTS, uint64_t endTS = 9999999999999, bool playabckDirection = true, bool Mp4ReaderExport = false, bool priority = false) {}
Expand All @@ -45,6 +45,7 @@ class AbsControlModule : public Module {
virtual void sendEOS() {}
virtual void sendEOS(frame_sp& frame) {}
virtual void sendEOPFrame() {}
std::vector<std::string> serializeControlModule();
boost::function<void(const APHealthObject*, unsigned short)> healthCallbackExtention;
private:
class Detail;
Expand Down
2 changes: 1 addition & 1 deletion base/include/SimpleControlModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class SimpleControlModule : public AbsControlModule
~SimpleControlModule()
{
}

std::string printStatus();
void handleError(const APErrorObject &error) override;
void handleHealthCallback(const APHealthObject &healthObj) override;
// ErrorCallbacks
Expand Down
34 changes: 34 additions & 0 deletions base/src/AbsControlModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "Module.h"
#include "Command.h"
#include "PipeLine.h"
#include "boost/algorithm/string/join.hpp"

class AbsControlModule::Detail
{
Expand Down Expand Up @@ -57,6 +58,12 @@ bool AbsControlModule::process(frame_container& frames)
return true;
}

/**
* @brief Enroll your module to use healthcallback, errorcallback and other control module functions
* @param boost::shared_ptr<Module> the module to be registered
* @param role unique string for role of the module
* @return bool.
*/
bool AbsControlModule::enrollModule(std::string role, boost::shared_ptr<Module> module)
{
if (moduleRoles.find(role) != moduleRoles.end())
Expand Down Expand Up @@ -108,4 +115,31 @@ void AbsControlModule::handleHealthCallback(const APHealthObject& healthObj)
LOG_INFO << "Calling the registered Health Callback Extention...";
healthCallbackExtention(&healthObj, 1);
}
}

std::vector<std::string> AbsControlModule::serializeControlModule()
{
std::string spacedLineFmt = "\t-->";
std::vector<std::string> status;
status.push_back("Module <" + this->getId() + "> \n");
status.push_back("Enrolled Modules \n");
for (auto it : moduleRoles)
{
status.push_back("module <" + it.second.lock()->getId() + "> role <" + it.first + ">\n");
std::string cbStatus = "registered for...\n";
if (it.second.lock()->getProps().enableHealthCallBack)
{
cbStatus += spacedLineFmt + "<health callbacks> \n";
}
cbStatus += spacedLineFmt + "<error callbacks>";
status.push_back(spacedLineFmt + cbStatus);
}
return status;
}

std::string AbsControlModule::printStatus()
{
auto ser = boost::algorithm::join(serializeControlModule(), "|");
LOG_INFO << ser;
return ser;
}
5 changes: 5 additions & 0 deletions base/src/SimpleControlModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ void SimpleControlModule::sendEOPFrame()
return Module::sendEoPFrame();
}

std::string SimpleControlModule::printStatus()
{
return AbsControlModule::printStatus();
}

// Right Now, Just Logging But Can be used to Do bunch of other things
void SimpleControlModule::handleError(const APErrorObject &error)
{
Expand Down
1 change: 1 addition & 0 deletions base/test/simpleControlModuleTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ BOOST_AUTO_TEST_CASE(simpleControlModule_healthCallback)

t.startPipeline();
t.addControlModule();
t.simpleCtrl->printStatus();
boost::this_thread::sleep_for(boost::chrono::milliseconds(5000));
t.stopPipeline();
boost::this_thread::sleep_for(boost::chrono::milliseconds(3000));
Expand Down

0 comments on commit bdb9776

Please sign in to comment.