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 threadEn_ = false;
66 queue_.stop();
67 thread_->join();
68}
69
71void rpp::Application::setController(rpp::ControllerPtr cntl) {
72 cntl_ = cntl;
73
74 // Start read thread
75 threadEn_ = true;
76 thread_ = new std::thread(&rpp::Application::runThread, this);
77
78 // Set a thread name
79#ifndef __MACH__
80 pthread_setname_np(thread_->native_handle(), "PackApp");
81#endif
82}
83
85ris::FramePtr rpp::Application::acceptReq(uint32_t size, bool zeroCopyEn) {
86 return (cntl_->reqFrame(size));
87}
88
90void rpp::Application::acceptFrame(ris::FramePtr frame) {
91 cntl_->applicationRx(frame, id_);
92}
93
95void rpp::Application::pushFrame(ris::FramePtr frame) {
96 queue_.push(frame);
97}
98
100void rpp::Application::runThread() {
101 ris::FramePtr frame;
102 Logging log("packetizer.Application");
103 log.logThreadId();
104
105 while (threadEn_) {
106 if ((frame = queue_.pop()) != NULL) sendFrame(frame);
107 }
108}
RAII helper that releases the Python GIL for a scope.
Definition GilRelease.h:36
Structured Rogue logging helper.
Definition Logging.h:58
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:140