rogue
Loading...
Searching...
No Matches
Application.cpp
Go to the documentation of this file.
1
17#include "rogue/Directives.h"
18
20
21#include <memory>
22
23#include "rogue/GeneralError.h"
24#include "rogue/GilRelease.h"
25#include "rogue/Logging.h"
29
32
33#ifndef NO_PYTHON
34 #include <boost/python.hpp>
35namespace bp = boost::python;
36#endif
37
39rpp::ApplicationPtr rpp::Application::create(uint8_t id) {
40 rpp::ApplicationPtr r = std::make_shared<rpp::Application>(id);
41 return (r);
42}
43
44void rpp::Application::setup_python() {
45#ifndef NO_PYTHON
46
47 bp::class_<rpp::Application, rpp::ApplicationPtr, bp::bases<ris::Master, ris::Slave>, boost::noncopyable>(
48 "Application",
49 bp::init<uint8_t>());
50
51 bp::implicitly_convertible<rpp::ApplicationPtr, ris::MasterPtr>();
52 bp::implicitly_convertible<rpp::ApplicationPtr, ris::SlavePtr>();
53#endif
54}
55
57rpp::Application::Application(uint8_t id) {
58 id_ = id;
59 queue_.setMax(8);
60}
61
63rpp::Application::~Application() {
64 // No-op if setController() never ran.
65 if (thread_ != nullptr) {
66 threadEn_ = false;
68 queue_.stop();
69 thread_->join();
70 delete thread_;
71 thread_ = nullptr;
72 }
73}
74
76void rpp::Application::setController(rpp::ControllerPtr cntl) {
77 cntl_ = cntl;
78
79 // Start read thread
80 threadEn_ = true;
81 thread_ = new std::thread(&rpp::Application::runThread, this);
82
83 // Set a thread name
84#ifndef __MACH__
85 pthread_setname_np(thread_->native_handle(), "PackApp");
86#endif
87}
88
90ris::FramePtr rpp::Application::acceptReq(uint32_t size, bool zeroCopyEn) {
91 return (cntl_->reqFrame(size));
92}
93
95void rpp::Application::acceptFrame(ris::FramePtr frame) {
96 cntl_->applicationRx(frame, id_);
97}
98
100void rpp::Application::pushFrame(ris::FramePtr frame) {
101 queue_.push(frame);
102}
103
105void rpp::Application::runThread() {
106 ris::FramePtr frame;
107 Logging log("packetizer.Application");
108 log.logThreadId();
109
110 while (threadEn_) {
111 if ((frame = queue_.pop()) != NULL) sendFrame(frame);
112 }
113}
RAII helper that releases the Python GIL for a scope.
Definition GilRelease.h:36
Structured Rogue logging helper.
Definition Logging.h:59
std::shared_ptr< rogue::interfaces::stream::Frame > FramePtr
Shared pointer alias for Frame.
Definition Frame.h:549
std::shared_ptr< rogue::protocols::packetizer::Application > ApplicationPtr
std::shared_ptr< rogue::protocols::packetizer::Controller > ControllerPtr
Definition Controller.h:141