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

This plugin sample serachs for events in the current system. User defined filters are used for searching. More...

#include <SearchEvents.h>

Public Member Functions

 SearchEvents (const std::string description)
 
 ~SearchEvents ()
 
CppSamples::Common::PluginRun (CppSamples::Common::DataModel *dataModel) override
 Serachs for events in the current system. User defined filters are used for searching. 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 DoSearchEvents (VxSdk::IVxSystem *vxSystem)
 Serachs for events in the current system. User defined filters are used for searching. More...
 
VxSdk::VxCollection< VxSdk::IVxEvent ** > Search (VxSdk::IVxSystem *vxSystem, std::string startTime, std::string endTime)
 Search for events with the given parameters. More...
 

Static Private Member Functions

static void PrintEventRow (VxSdk::IVxEvent *vxEvent)
 Print the details of the given event in a line. More...
 
static void PrintEventHeadings ()
 Print the headings for a table of events. More...
 

Detailed Description

This plugin sample serachs for events in the current system. User defined filters are used for searching.

Definition at line 12 of file SearchEvents.h.

Inherits CppSamples::Common::Plugin.

Constructor & Destructor Documentation

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

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

Definition at line 15 of file SearchEvents.h.

15 {}

Member Function Documentation

void CppSamples::Events::SearchEvents::DoSearchEvents ( VxSdk::IVxSystem vxSystem)
private

Serachs for events in the current system. User defined filters are used for searching.

Parameters
vxSystemPointer to the VideoExpert system.

Definition at line 23 of file SearchEvents.cpp.

23  {
24 
25  // Read Start Time for search
26  cout << "\n\n" << "Enter start time for event search (yyyy-mm-dd hh:mm:ss): ";
27  struct tm strtTime = Utility::GetDateAndTimeFromUser();
28  string startTimeInUTC = Utility::ConvertLocalTimetoUTC(strtTime);
29 
30  // End Time for search
31  cout << "\n" << "Enter end time for event search (yyyy-mm-dd hh:mm:ss): ";
32  struct tm endTime = Utility::GetDateAndTimeFromUser();
33  string endTimeInUTC = Utility::ConvertLocalTimetoUTC(endTime);
34 
35  // Start Searching Events
36  Utility::ClearScreen();
37 
38  cout << "Fetching events from " << startTimeInUTC << " to " << endTimeInUTC << " (UTC).";
39  cout << "\n\n";
40  VxCollection<IVxEvent**> events = Search(vxSystem, startTimeInUTC, endTimeInUTC);
41  if (events.collectionSize > 0) {
42  if (events.collectionSize < 500) {
43  // Print Events
45  for (int i = 0; i < events.collectionSize; i++)
46  PrintEventRow(events.collection[i]);
47  }
48  cout << "\n---------------------------------------------------------------------------------------------\n";
49  // Remove the memory allocated to the collection.
50  delete[] events.collection;
51  }
52 
53  cout << "\n";
54 }
static void PrintEventHeadings()
Print the headings for a table of events.
static void PrintEventRow(VxSdk::IVxEvent *vxEvent)
Print the details of the given event in a line.
VxSdk::VxCollection< VxSdk::IVxEvent ** > Search(VxSdk::IVxSystem *vxSystem, std::string startTime, std::string endTime)
Search for events with the given parameters.
void CppSamples::Events::SearchEvents::PrintEventHeadings ( )
staticprivate

Print the headings for a table of events.

Display the headings for a table of events

Definition at line 101 of file SearchEvents.cpp.

101  {
102  const int eventTimeWidth = 20;
103  const int eventStringWidth = 32;
104  cout << "\n---------------------------------------------------------------------------------------------\n";
105  cout << left << setw(eventTimeWidth) << setfill(' ') << "Time(UTC)";
106  cout << left << setw(eventStringWidth) << setfill(' ') << "Situation Type";
107  cout << left << setw(eventStringWidth) << setfill(' ') << "Source Device";
108  cout << "\n---------------------------------------------------------------------------------------------\n";
109 }
void CppSamples::Events::SearchEvents::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 89 of file SearchEvents.cpp.

89  {
90  const int eventTimeWidth = 20;
91  const int eventStringWidth = 32;
92  cout << left << setw(eventTimeWidth) << setfill(' ') << Utility::ConvertUTCTimeFormatToString(vxEvent->time);
93  cout << left << setw(eventStringWidth) << setfill(' ') << vxEvent->situationType;
94  cout << left << setw(eventStringWidth) << setfill(' ') << vxEvent->sourceDeviceId;
95  cout << "\n";
96 }
char situationType[256]
char sourceDeviceId[64]
Plugin * CppSamples::Events::SearchEvents::Run ( CppSamples::Common::DataModel dataModel)
overridevirtual

Serachs for events in the current system. User defined filters are used for searching.

Parameters
dataModelInstance of data model.

Implements CppSamples::Common::Plugin.

Definition at line 11 of file SearchEvents.cpp.

11  {
12 
13  DoSearchEvents(dataModel->VxSystem);
14 
15  // Wait for user response before going back to parent menu.
16  Utility::Pause();
17 
18  // Return reference of parent plugin to move back to parent menu.
19  return GetParent();
20 }
VxSdk::IVxSystem * VxSystem
Represents a VideoXpert system and allows the user to manage the system and devices.
Definition: Plugin.h:17
void DoSearchEvents(VxSdk::IVxSystem *vxSystem)
Serachs for events in the current system. User defined filters are used for searching.
Plugin * GetParent() const
Gets the reference to the parent of this plugin.
Definition: Plugin.h:46
VxCollection< IVxEvent ** > CppSamples::Events::SearchEvents::Search ( VxSdk::IVxSystem vxSystem,
std::string  startTime,
std::string  endTime 
)
private

Search for events with the given parameters.

Parameters
vxSystemPointer to the VideoExpert system.
startTimeStart time for event.
endTimeEnd time for event.
Returns
A collection of event.

Definition at line 57 of file SearchEvents.cpp.

57  {
58 
59  // Create new collection of events to search
61  events.filterSize = 2;
62  VxCollectionFilter filters[2];
63  filters[0].key = VxCollectionFilterItem::kSearchStartTime;
64  filters[1].key = VxCollectionFilterItem::kSearchEndTime;
65  Utilities::StrCopySafe(filters[0].value, startTime.c_str());
66  Utilities::StrCopySafe(filters[1].value, endTime.c_str());
67  events.filters = filters;
68 
69  // Read the size of collection from system.
70  VxResult::Value result = vxSystem->GetEvents(events);
71  if (result == VxResult::kInsufficientSize) {
72  if (events.collectionSize < 500) {
73  // Allocate memory for the requried collection.
74  events.collection = new IVxEvent*[events.collectionSize];
75  // Read the collection from system.
76  vxSystem->GetEvents(events);
77  }
78  else
79  cout << "Found " << events.collectionSize << " events. There are too many to display, please narrow your search.";
80  }
81 
82  return events;
83 }
VxCollectionFilterItem::Value key
virtual VxResult::Value GetEvents(VxCollection< IVxEvent ** > &eventCollection) const =0
VxCollectionFilter * filters

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