C++ Samples
Demonstrates how to create a C++ application using the VideoXpert SDK
CppSamples::Events::MonitorEvents Class Reference

This plugin sample shows how to subscribe for a notification, monitor for a call back and unsubscribe that. More...

#include <MonitorEvents.h>

Public Member Functions

 MonitorEvents (const std::string description)
 
 ~MonitorEvents ()
 
CppSamples::Common::PluginRun (CppSamples::Common::DataModel *dataModel) override
 Subscribe for a notification, monitor for a call back and unsubscribe that. More...
 
- Public Member Functions inherited from CppSamples::Common::Plugin
 Plugin (const std::string description)
 
virtual ~Plugin ()
 
std::string GetDescription () const
 Gets the description of this plugin. More...
 
PluginGetParent () const
 Gets the reference to the parent of this plugin. More...
 
void SetParent (Plugin *parent)
 Sets the reference to the parent of this plugin. More...
 

Private Member Functions

void StartMonitorEvents (VxSdk::IVxSystem *vxSystem)
 Subscribe for a notification, monitor for a call back and unsubscribe that. More...
 
void PrintEventHeadings ()
 Print the headings for a table of events. More...
 
bool SubscribeEvents (VxSdk::IVxSystem *vxSystem)
 Subscribe to event notifications More...
 
bool UnSubscribeEvents (VxSdk::IVxSystem *vxSystem)
 Unsubscribe to event notifications More...
 

Static Private Member Functions

static void PrintEventRow (VxSdk::IVxEvent *vxEvent)
 Print the details of the given event in a line. More...
 
static void EventsCallBack (VxSdk::IVxEvent *vxEvent)
 Callback method to handle events received from VxSDK More...
 

Detailed Description

This plugin sample shows how to subscribe for a notification, monitor for a call back and unsubscribe that.

Definition at line 12 of file MonitorEvents.h.

Inherits CppSamples::Common::Plugin.

Constructor & Destructor Documentation

CppSamples::Events::MonitorEvents::MonitorEvents ( const std::string  description)
inline

Definition at line 14 of file MonitorEvents.h.

14 : CppSamples::Common::Plugin(description) { }
Plugin is the abstract class which can be a menu item and/or a sample. Every sample and menu item mus...
Definition: Plugin.h:33
CppSamples::Events::MonitorEvents::~MonitorEvents ( )
inline

Definition at line 15 of file MonitorEvents.h.

15 {}

Member Function Documentation

void CppSamples::Events::MonitorEvents::EventsCallBack ( VxSdk::IVxEvent vxEvent)
staticprivate

Callback method to handle events received from VxSDK

Parameters
vxEventPointer to the event containing newly received event details.
Parameters
vxEventIVxEvent pointer containing newly received event details

Definition at line 73 of file MonitorEvents.cpp.

73  {
74  // Only log acknowledgement needed events. Skip others
75  if (vxEvent->ackState != VxAckState::kAutoAcked)
76  PrintEventRow(vxEvent);
77 }
VxAckState::Value ackState
static void PrintEventRow(VxSdk::IVxEvent *vxEvent)
Print the details of the given event in a line.
void CppSamples::Events::MonitorEvents::PrintEventHeadings ( )
private

Print the headings for a table of events.

Display the headings for a table of events

Definition at line 59 of file MonitorEvents.cpp.

59  {
60  const int eventTimeWidth = 20;
61  const int eventStringWidth = 32;
62  cout << "\n--------------------------------------------------\n";
63  cout << left << setw(eventTimeWidth) << setfill(' ') << "Time(UTC)";
64  cout << left << setw(eventStringWidth) << setfill(' ') << "Situation Type";
65  cout << left << setw(eventStringWidth) << setfill(' ') << "Source Device";
66  cout << "\n--------------------------------------------------\n";
67 }
void CppSamples::Events::MonitorEvents::PrintEventRow ( VxSdk::IVxEvent vxEvent)
staticprivate

Print the details of the given event in a line.

Display a row of event details

Parameters
vxEventPointer to the event to display
Parameters
vxEventCPPConsole::Event pointer containing the event to display

Definition at line 47 of file MonitorEvents.cpp.

47  {
48  const int eventTimeWidth = 20;
49  const int eventStringWidth = 32;
50  cout << left << setw(eventTimeWidth) << setfill(' ') << Utility::ConvertUTCTimeFormatToString(vxEvent->time);
51  cout << left << setw(eventStringWidth) << setfill(' ') << vxEvent->situationType;
52  cout << left << setw(eventStringWidth) << setfill(' ') << vxEvent->sourceDeviceId;
53  cout << "\n";
54 }
char situationType[256]
char sourceDeviceId[64]
Plugin * CppSamples::Events::MonitorEvents::Run ( CppSamples::Common::DataModel dataModel)
overridevirtual

Subscribe for a notification, monitor for a call back and unsubscribe that.

Parameters
dataModelInstance of data model.

Implements CppSamples::Common::Plugin.

Definition at line 10 of file MonitorEvents.cpp.

10  {
11 
12  StartMonitorEvents(dataModel->VxSystem);
13 
14  // Return reference of parent plugin to move back to parent menu.
15  return GetParent();
16 }
VxSdk::IVxSystem * VxSystem
Represents a VideoXpert system and allows the user to manage the system and devices.
Definition: Plugin.h:17
void StartMonitorEvents(VxSdk::IVxSystem *vxSystem)
Subscribe for a notification, monitor for a call back and unsubscribe that.
Plugin * GetParent() const
Gets the reference to the parent of this plugin.
Definition: Plugin.h:46
void CppSamples::Events::MonitorEvents::StartMonitorEvents ( VxSdk::IVxSystem vxSystem)
private

Subscribe for a notification, monitor for a call back and unsubscribe that.

Parameters
vxSystemPointer to the VideoExpert system.

Definition at line 18 of file MonitorEvents.cpp.

18  {
19 
20  cout << "\n\n" << "Subscribing to events";
21  if (!SubscribeEvents(vxSystem)) {
22  cout << "Error subscribing to events! \n";
23 
24  // Wait for user response before going back to parent menu.
25  Utility::Pause();
26 
27  return;
28  }
29 
30  cout << "Monitoring events. Press any key to stop . . .\n\n";
32  cin.ignore(256, '\n');
33  cin.get();
34  cout << "Unsubscribing to events";
35  if (!UnSubscribeEvents(vxSystem))
36  cout << "Error unsubscribing to events!\n";
37 
38  cout << "\n";
39  // Wait for user response before going back to parent menu.
40  Utility::Pause();
41 }
void PrintEventHeadings()
Print the headings for a table of events.
bool SubscribeEvents(VxSdk::IVxSystem *vxSystem)
Subscribe to event notifications
bool UnSubscribeEvents(VxSdk::IVxSystem *vxSystem)
Unsubscribe to event notifications
bool CppSamples::Events::MonitorEvents::SubscribeEvents ( VxSdk::IVxSystem vxSystem)
private

Subscribe to event notifications

Parameters
vxSystemPointer to the VideoExpert system.
Parameters
vxSystemsystem pointer

Definition at line 83 of file MonitorEvents.cpp.

83  {
84 
86  if (result == VxResult::kOK) {
87  cout << "\n" << "Events subscription successful.\n";
88  return true;
89  }
90  else {
91  cout << "\n" << "Failed to subscribe events!!\n";
92  return false;
93  }
94 }
virtual VxResult::Value StartNotifications(VxEventCallback callback) const =0
static void EventsCallBack(VxSdk::IVxEvent *vxEvent)
Callback method to handle events received from VxSDK
bool CppSamples::Events::MonitorEvents::UnSubscribeEvents ( VxSdk::IVxSystem vxSystem)
private

Unsubscribe to event notifications

Parameters
vxSystemPointer to the VideoExpert system.
Parameters
vxSystemsystem pointer

Definition at line 100 of file MonitorEvents.cpp.

100  {
101 
102  VxResult::Value result = vxSystem->StopNotifications();
103  if (result == VxResult::kOK) {
104  cout << "\n" << "Events unsubscription successful.\n";
105  return true;
106  }
107  else {
108  cout << "\n" << "Failed to unsubscribe events!!\n";
109  return false;
110  }
111 }
virtual VxResult::Value StopNotifications() const =0

The documentation for this class was generated from the following files: