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

This plugin sample creates a trigger and add it to a selected schedule in the current system. More...

#include <AddTriggerToSchedule.h>

Public Member Functions

 AddTriggerToSchedule (const std::string description)
 
 ~AddTriggerToSchedule ()
 
CppSamples::Common::PluginRun (CppSamples::Common::DataModel *dataModel) override
 Creates a trigger and add it to a selected schedule in the current 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

VxSdk::VxCollection< VxSdk::IVxSchedule ** > GetSchedules (VxSdk::IVxSystem *vxSystem)
 Get a collection of schedules from the given VideoExpert system. More...
 

Static Private Member Functions

static std::string ReadTime (std::string message)
 Reads a time from user input More...
 
static std::string ReadDate (std::string message)
 Reads a date from user input in DD-MM-YY format. More...
 

Detailed Description

This plugin sample creates a trigger and add it to a selected schedule in the current system.

Definition at line 12 of file AddTriggerToSchedule.h.

Inherits CppSamples::Common::Plugin.

Constructor & Destructor Documentation

CppSamples::Schedules::AddTriggerToSchedule::AddTriggerToSchedule ( const std::string  description)
inline

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

Definition at line 15 of file AddTriggerToSchedule.h.

15 {}

Member Function Documentation

VxCollection< IVxSchedule ** > CppSamples::Schedules::AddTriggerToSchedule::GetSchedules ( VxSdk::IVxSystem vxSystem)
private

Get a collection of schedules from the given VideoExpert system.

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

Definition at line 110 of file AddTriggerToSchedule.cpp.

110  {
111  VxCollection<IVxSchedule**> schedules;
112  VxResult::Value result = vxSystem->GetSchedules(schedules);
113  if (result == VxResult::kInsufficientSize) {
114  schedules.collection = new IVxSchedule*[schedules.collectionSize];
115  vxSystem->GetSchedules(schedules);
116  }
117  return schedules;
118 }
virtual VxResult::Value GetSchedules(VxCollection< IVxSchedule ** > &scheduleCollection) const =0
string CppSamples::Schedules::AddTriggerToSchedule::ReadDate ( std::string  message)
staticprivate

Reads a date from user input in DD-MM-YY format.

Parameters
messageMessage to be printed while before reading date

Definition at line 147 of file AddTriggerToSchedule.cpp.

147  {
148  cout << message << "(dd-mm-yy) : ";
149  string utcFormat = Utility::ReadString();
150 
151  std::stringstream dateStream(utcFormat);
152  struct tm parseDate;
153  //Here parse date string value to date structure
154  dateStream >> std::get_time(&parseDate, "%d-%m-%Y");
155 
156  parseDate.tm_hour = 0;
157  parseDate.tm_min = 0;
158  parseDate.tm_sec = 0;
159 
160  char buffer[9];
161  strftime(buffer, 9, "%x", &parseDate);
162 
163  return string(buffer);
164 }
string CppSamples::Schedules::AddTriggerToSchedule::ReadTime ( std::string  message)
staticprivate

Reads a time from user input

Parameters
messageMessage to be printed while before reading time

Definition at line 124 of file AddTriggerToSchedule.cpp.

124  {
125  cout << message << "(HH:MM:SS) : ";
126  string utcFormat = Utility::ReadString();
127 
128  std::stringstream dateStream(utcFormat);
129  struct tm parseTime;
130  //Here parse time string value to time structure
131  dateStream >> std::get_time(&parseTime, "%H:%M:%S");
132 
133  parseTime.tm_mday = 1;
134  parseTime.tm_mon = 0;
135  parseTime.tm_year = 0;
136 
137  char buffer[9];
138  strftime(buffer, 9, "%X", &parseTime);
139 
140  return string(buffer);
141 }
Plugin * CppSamples::Schedules::AddTriggerToSchedule::Run ( CppSamples::Common::DataModel dataModel)
overridevirtual

Creates a trigger and add it to a selected schedule in the current system.

Parameters
dataModelInstance of data model.

Implements CppSamples::Common::Plugin.

Definition at line 15 of file AddTriggerToSchedule.cpp.

15  {
16  cout << "\n";
17  VxCollection<IVxSchedule**> schedules = GetSchedules(dataModel->VxSystem);
18  OptionSelector<IVxSchedule*> optionSelector;
19  optionSelector.Heading = "Select a schedule to add trigger";
20  for (int i = 0; i < schedules.collectionSize; i++) {
21  IVxSchedule* schedule = schedules.collection[i];
22  string name = schedule->id + string("\t") + schedule->name;
23  optionSelector.AddItem(name, schedule);
24  }
25 
26  IVxSchedule* selectedSchedule = nullptr;
27  if (optionSelector.SelectOption(&selectedSchedule)) {
28 
29  // Create a new schedule trigger
30  VxNewScheduleTrigger scheduleTrigger;
31  string newGuid = Utility::GetNewGuid();
32  Utilities::StrCopySafe(scheduleTrigger.id, newGuid.c_str());
33 
34  cout << "\n";
35 
36  // Start Time
37  VxSdk::Utilities::StrCopySafe(scheduleTrigger.dailyStartTime, ReadTime("Enter Start Time ").c_str());
38 
39  // End Time
40  VxSdk::Utilities::StrCopySafe(scheduleTrigger.dailyEndTime, ReadTime("Enter End Time ").c_str());
41 
42  // Start Date
43  VxSdk::Utilities::StrCopySafe(scheduleTrigger.startDate, ReadDate("Enter Start Date ").c_str());
44 
45  // End Date
46  VxSdk::Utilities::StrCopySafe(scheduleTrigger.endDate, ReadDate("Enter End Date ").c_str());
47 
48  // Framerate
50  framerateSelector.Heading = "Select a type of frame rate";
51  framerateSelector.AddItem("Log", VxRecordingFramerate::kLow);
52  framerateSelector.AddItem("Normal", VxRecordingFramerate::kNormal);
53  if (!framerateSelector.SelectOption(&scheduleTrigger.framerate))
54  scheduleTrigger.framerate = VxRecordingFramerate::kUnknown;
55 
56  // Event
57  cout << "\n";
59  eventSelector.Heading = "\nSelect a type of event";
60  eventSelector.AddItem("AlarmActive", VxSituationType::kAlarmActive);
61  eventSelector.AddItem("AlarmInactive", VxSituationType::kAlarmInactive);
62  eventSelector.AddItem("Motion", VxSituationType::kMotion);
63  eventSelector.AddItem("NoMotion", VxSituationType::kNoMotion);
64  if (!eventSelector.SelectOption(&scheduleTrigger.event))
65  scheduleTrigger.event = VxSituationType::kUnknown;
66 
67  // Recurrence
68  cout << "\n";
69  OptionSelector<VxRecurrenceType::Value> recurrenceSelector;
70  recurrenceSelector.Heading = "\nSelect a type of recurrence";
71  recurrenceSelector.AddItem("Daily", VxRecurrenceType::kDaily);
72  recurrenceSelector.AddItem("Monthly", VxRecurrenceType::kMonthly);
73  recurrenceSelector.AddItem("Weekly", VxRecurrenceType::kWeekly);
74  recurrenceSelector.AddItem("Yearly", VxRecurrenceType::kYearly);
75  if (!recurrenceSelector.SelectOption(&scheduleTrigger.recurrence))
76  scheduleTrigger.recurrence = VxRecurrenceType::kUnknown;
77 
78  // PreTrigger
79  cout << "\n" << "Enter PreTrigger value : ";
80  scheduleTrigger.preTrigger = Utility::ReadInt();
81 
82  // PostTrigger
83  cout << "Enter PostTrigger value : ";
84  scheduleTrigger.postTrigger = Utility::ReadInt();
85 
86  // Timeout
87  cout << "Enter Timeout Duration : ";
88  scheduleTrigger.timeout = Utility::ReadInt();
89 
90  // Make the call to add the schedule into VideoXpert
91  VxResult::Value result = selectedSchedule->AddScheduleTrigger(scheduleTrigger);
92  if (result == VxResult::kOK)
93  cout << "\n" << "Schedule added succesfully.\n";
94  else
95  cout << "\n" << "Failed to add schedule.\n";
96  }
97 
98  // Wait for user response before going back to parent menu.
99  Utility::Pause();
100 
101  // Return reference of parent plugin to move back to parent menu.
102  return GetParent();
103 }
bool SelectOption(T *result)
Prints a collection of options and chose a user defined one.
static std::string ReadDate(std::string message)
Reads a date from user input in DD-MM-YY format.
VxSdk::IVxSystem * VxSystem
Represents a VideoXpert system and allows the user to manage the system and devices.
Definition: Plugin.h:17
virtual VxResult::Value AddScheduleTrigger(VxNewScheduleTrigger &newTrigger) const =0
static void StrCopySafe(char(&dst)[dstSize], const char *src)
VxSdk::VxCollection< VxSdk::IVxSchedule ** > GetSchedules(VxSdk::IVxSystem *vxSystem)
Get a collection of schedules from the given VideoExpert system.
VxSituationType::Value event
VxRecurrenceType::Value recurrence
VxRecordingFramerate::Value framerate
Plugin * GetParent() const
Gets the reference to the parent of this plugin.
Definition: Plugin.h:46
static std::string ReadTime(std::string message)
Reads a time from user input
void AddItem(std::string name, T item)
The given name and item will be added to the collection.
This helper class prints a collection of options and chose a user defined option. ...

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