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

This plugin sample creates a new event and insert it into the system. More...

#include <InjectEvents.h>

Public Member Functions

 InjectEvents (const std::string description)
 
 ~InjectEvents ()
 
CppSamples::Common::PluginRun (CppSamples::Common::DataModel *dataModel) override
 Creates a new event and insert it into the system. 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 Inject (VxSdk::IVxSystem *vxSystem)
 Creates a new event and insert it into the system. More...
 
VxSdk::VxCollection< VxSdk::IVxSituation ** > GetSituations (VxSdk::IVxSystem *vxSystem)
 Get a collection of situations from the given VideoExpert system. More...
 
void DisplaySituationDetailsOnScreen (VxSdk::VxCollection< VxSdk::IVxSituation ** > situations)
 Print the given collection of situations on screen More...
 

Detailed Description

This plugin sample creates a new event and insert it into the system.

Definition at line 12 of file InjectEvents.h.

Inherits CppSamples::Common::Plugin.

Constructor & Destructor Documentation

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

Definition at line 14 of file InjectEvents.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::InjectEvents::~InjectEvents ( )
inline

Definition at line 15 of file InjectEvents.h.

15 {}

Member Function Documentation

void CppSamples::Events::InjectEvents::DisplaySituationDetailsOnScreen ( VxSdk::VxCollection< VxSdk::IVxSituation ** >  situations)
private

Print the given collection of situations on screen

Method for displaying situation details

Parameters
situationsCollection of Situations to be printed.
Parameters
situationsSituations list to iterate

Definition at line 93 of file InjectEvents.cpp.

93  {
94 
95  if (situations.collectionSize > 0) {
96  cout << situations.collectionSize << " situations found.\n";
97 
98  cout << "\n\n";
99  cout << setfill(' ') << " INDEX " << setw(60) << left << " TYPE" << "\n";
100  cout << "\n--------------------------------------------------\n";
101 
102  int index = 0;
103  for (int i = 0; i < situations.collectionSize; i++) {
104  IVxSituation* situation = situations.collection[i];
105  cout << setfill(' ') << "\n\t" << index + 1 << "\t" << left << setw(60) << left << situation->type;
106  index++;
107  }
108  cout << "\n--------------------------------------------------\n";
109  }
110  else
111  cout << "No situations found!!\n";
112 }
VxCollection< IVxSituation ** > CppSamples::Events::InjectEvents::GetSituations ( VxSdk::IVxSystem vxSystem)
private

Get a collection of situations from the given VideoExpert system.

Parameters
vxSystemPointer to the VideoExpert system.
Returns
A collection of situations.

Definition at line 74 of file InjectEvents.cpp.

74  {
75 
76  // Read the size of collection from system.
78  VxResult::Value result = vxSystem->GetSituations(situations);
79  if (result == VxResult::kInsufficientSize) {
80  // Allocate memory for the requried collection.
81  situations.collection = new IVxSituation*[situations.collectionSize];
82  // Read the collection from system.
83  result = vxSystem->GetSituations(situations);
84  }
85 
86  return situations;
87 }
virtual VxResult::Value GetSituations(VxCollection< IVxSituation ** > &situationCollection) const =0
void CppSamples::Events::InjectEvents::Inject ( VxSdk::IVxSystem vxSystem)
private

Creates a new event and insert it into the system.

Menu function for deleting situation from server

Parameters
vxSystemPointer to the VideoExpert system.
Parameters
vxSystemsystem pointer

Definition at line 25 of file InjectEvents.cpp.

25  {
26 
27  // Get all situations from the system
28  cout << "\n\n" << "Fetching situations from system..Please wait..\n";
29  VxCollection<IVxSituation**> situations = GetSituations(vxSystem);
31 
32  // User selects a situation
33  cout << "\n" << "Enter the id of the situation to be associated with the event [1-" << situations.collectionSize << "] : ";
34  int situationId = Utility::ReadInt();
35 
36  if (situationId < 1 || situationId > situations.collectionSize) {
37  cout << "\n" << "Invalid option is given.";
38  return;
39  }
40 
41  // Print details of selected situation
42  IVxSituation* situation = situations.collection[situationId - 1];
43  cout << "\n" << "Situation selected to insert is:" << situation->type << "\n";
44 
45  // Read generator Device ID
46  cout << "\n" << "Enter generator device id: ";
47  string generatorDeviceId = Utility::ReadString();
48 
49  // Read source Device ID
50  cout << "\n" << "Enter source device id: ";
51  string sourceDeviceId = Utility::ReadString();
52 
53  // Read event time
54  cout << "\n" << "Enter event time(yyyy-mm-dd hh:mm:ss): ";
55  struct tm strtTime = Utility::GetDateAndTimeFromUser();
56  string startTimeInUTC = Utility::ConvertLocalTimetoUTC(strtTime);
57 
58  // Create new instance of event structure and set the user inputs to it.
59  VxNewEvent newEvent;
60  Utilities::StrCopySafe(newEvent.situationType, situation->type);
61  Utilities::StrCopySafe(newEvent.generatorDeviceId, generatorDeviceId.c_str());
62  Utilities::StrCopySafe(newEvent.sourceDeviceId, sourceDeviceId.c_str());
63  Utilities::StrCopySafe(newEvent.time, startTimeInUTC.c_str());
64 
65  // Insert the new event to the system.
66  VxResult::Value result = vxSystem->InsertEvent(newEvent);
67  if (result == VxResult::kOK)
68  cout << "\n" << "Succesfully injected new event.\n";
69  else
70  cout << "\n" << "Failed to inject event.\n";
71 }
char generatorDeviceId[64]
VxSdk::VxCollection< VxSdk::IVxSituation ** > GetSituations(VxSdk::IVxSystem *vxSystem)
Get a collection of situations from the given VideoExpert system.
char situationType[64]
virtual VxResult::Value InsertEvent(VxNewEvent &newEvent) const =0
char sourceDeviceId[64]
void DisplaySituationDetailsOnScreen(VxSdk::VxCollection< VxSdk::IVxSituation ** > situations)
Print the given collection of situations on screen
Plugin * CppSamples::Events::InjectEvents::Run ( CppSamples::Common::DataModel dataModel)
overridevirtual

Creates a new event and insert it into the system.

Parameters
dataModelInstance of data model.

Implements CppSamples::Common::Plugin.

Definition at line 10 of file InjectEvents.cpp.

10  {
11 
12  Inject(dataModel->VxSystem);
13 
14  // Wait for user response before going back to parent menu.
15  Utility::Pause();
16 
17  // Return reference of parent plugin to move back to parent menu.
18  return GetParent();
19 }
VxSdk::IVxSystem * VxSystem
Represents a VideoXpert system and allows the user to manage the system and devices.
Definition: Plugin.h:17
Plugin * GetParent() const
Gets the reference to the parent of this plugin.
Definition: Plugin.h:46
void Inject(VxSdk::IVxSystem *vxSystem)
Creates a new event and insert it into the system.

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