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
30namespace rpr = rogue::protocols::rssi;
32
33#ifndef NO_PYTHON
34 #include <boost/python.hpp>
35namespace bp = boost::python;
36#endif
37
39rpr::ApplicationPtr rpr::Application::create() {
40 rpr::ApplicationPtr r = std::make_shared<rpr::Application>();
41 return (r);
42}
43
44void rpr::Application::setup_python() {
45#ifndef NO_PYTHON
46
47 bp::class_<rpr::Application, rpr::ApplicationPtr, bp::bases<ris::Master, ris::Slave>, boost::noncopyable>(
48 "Application",
49 bp::init<>());
50
51 bp::implicitly_convertible<rpr::ApplicationPtr, ris::MasterPtr>();
52 bp::implicitly_convertible<rpr::ApplicationPtr, ris::SlavePtr>();
53#endif
54}
55
57rpr::Application::Application() {}
58
60rpr::Application::~Application() {
61 // No-op if setController() never ran.
62 if (thread_ != nullptr) {
63 threadEn_ = false;
64 // Release the GIL: worker may be mid-sendFrame to a Python slave.
66 cntl_->stopQueue();
67 thread_->join();
68 delete thread_;
69 thread_ = nullptr;
70 }
71}
72
74void rpr::Application::setController(rpr::ControllerPtr cntl) {
75 cntl_ = cntl;
76
77 // Start read thread
78 threadEn_ = true;
79 thread_ = new std::thread(&rpr::Application::runThread, this);
80
81 // Set a thread name
82#ifndef __MACH__
83 pthread_setname_np(thread_->native_handle(), "RssiApp");
84#endif
85}
86
88ris::FramePtr rpr::Application::acceptReq(uint32_t size, bool zeroCopyEn) {
89 return (cntl_->reqFrame(size));
90}
91
93void rpr::Application::acceptFrame(ris::FramePtr frame) {
94 cntl_->applicationRx(frame);
95}
96
98void rpr::Application::runThread() {
99 ris::FramePtr frame;
100 Logging log("rssi.Application");
101 log.logThreadId();
102
103 while (threadEn_) {
104 if ((frame = cntl_->applicationTx()) != NULL) sendFrame(frame);
105 }
106}
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::rssi::Application > ApplicationPtr
std::shared_ptr< rogue::protocols::rssi::Controller > ControllerPtr
Definition Controller.h:452