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

This plugin sample adds a bookmark to the current system. More...

#include <AddBookmark.h>

Public Member Functions

 AddBookmark (const std::string description)
 
 ~AddBookmark ()
 
CppSamples::Common::PluginRun (CppSamples::Common::DataModel *dataModel) override
 Adds a bookmark to 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

void AddNew (VxSdk::IVxSystem *vxSystem)
 Add a new bookmark to server. More...
 
VxSdk::VxCollection< VxSdk::IVxDataSource ** > GetDataSources (VxSdk::IVxSystem *vxSystem)
 Get a collection of data source from the given VideoExpert system. More...
 
int SelectDataSourceIndex (VxSdk::VxCollection< VxSdk::IVxDataSource ** > &dataSources)
 Select a data source from the given collection by user input. More...
 

Detailed Description

This plugin sample adds a bookmark to the current system.

Definition at line 12 of file AddBookmark.h.

Inherits CppSamples::Common::Plugin.

Constructor & Destructor Documentation

CppSamples::Bookmarks::AddBookmark::AddBookmark ( const std::string  description)
inline

Definition at line 16 of file AddBookmark.h.

16 : 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::Bookmarks::AddBookmark::~AddBookmark ( )
inline

Definition at line 17 of file AddBookmark.h.

17 {}

Member Function Documentation

void CppSamples::Bookmarks::AddBookmark::AddNew ( VxSdk::IVxSystem vxSystem)
private

Add a new bookmark to server.

Parameters
vxSystemPointer to the VideoExpert system.

Definition at line 25 of file AddBookmark.cpp.

25  {
26  // Data Source ID
27  VxCollection<IVxDataSource**> dataSources = GetDataSources(vxSystem);
28  int dataSourceIndex = SelectDataSourceIndex(dataSources);
29  if (dataSourceIndex < 0)
30  return;
31 
32  string dataSourceId = dataSources.collection[dataSourceIndex]->id;
33 
34  // Description
35  cout << "\n\n" << "Enter description for bookmark: ";
36  string description = Utility::ReadString();
37 
38  // Time
39  cout << "\n" << "Enter time (yyyy-mm-dd hh:mm:ss): ";
40  struct tm strtTime = Utility::GetDateAndTimeFromUser();
41  string time = Utility::ConvertLocalTimetoUTC(strtTime);
42 
43  VxNewBookmark bookmark;
44  Utilities::StrCopySafe(bookmark.dataSourceId, dataSourceId.c_str());
45  Utilities::StrCopySafe(bookmark.description, description.c_str());
46  Utilities::StrCopySafe(bookmark.time, time.c_str());
47 
48  VxResult::Value result = vxSystem->AddBookmark(bookmark);
49  if (result == VxResult::kOK)
50  cout << "\n" << "Bookmark added succesfully.\n";
51  else
52  cout << "\n" << "Failed to add bookmark.\n";
53 
54  // Wait for user response before going back to parent menu.
55  Utility::Pause();
56 }
VxSdk::VxCollection< VxSdk::IVxDataSource ** > GetDataSources(VxSdk::IVxSystem *vxSystem)
Get a collection of data source from the given VideoExpert system.
Definition: AddBookmark.cpp:63
int SelectDataSourceIndex(VxSdk::VxCollection< VxSdk::IVxDataSource ** > &dataSources)
Select a data source from the given collection by user input.
Definition: AddBookmark.cpp:84
virtual VxResult::Value AddBookmark(VxNewBookmark &newBookmark) const =0
VxCollection< IVxDataSource ** > CppSamples::Bookmarks::AddBookmark::GetDataSources ( VxSdk::IVxSystem vxSystem)
private

Get a collection of data source from the given VideoExpert system.

Parameters
vxSystemPointer to the VideoExpert system.
Returns
A collection of data source.

Definition at line 63 of file AddBookmark.cpp.

63  {
64  cout << "\nFetching datasources from system, Please wait...\n";
65  // Read the size of collection from system.
67  VxResult::Value result = vxSystem->GetDataSources(dataSources);
68  if (result == VxResult::kInsufficientSize) {
69  // Allocate memory for the requried collection.
70  dataSources.collection = new IVxDataSource*[dataSources.collectionSize];
71  // Read the collection from system.
72  vxSystem->GetDataSources(dataSources);
73  }
74  // Print the number of data source items read from the system.
75  cout << dataSources.collectionSize << " datasources found.\n";
76  return dataSources;
77 }
virtual VxResult::Value GetDataSources(VxCollection< IVxDataSource ** > &dataSourceCollection) const =0
Plugin * CppSamples::Bookmarks::AddBookmark::Run ( CppSamples::Common::DataModel dataModel)
overridevirtual

Adds a bookmark to the current system.

Parameters
dataModelInstance of data model.

Implements CppSamples::Common::Plugin.

Definition at line 14 of file AddBookmark.cpp.

14  {
15  AddNew(dataModel->VxSystem);
16 
17  // Return reference of parent plugin to move back to parent menu.
18  return GetParent();
19 }
void AddNew(VxSdk::IVxSystem *vxSystem)
Add a new bookmark to server.
Definition: AddBookmark.cpp:25
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
int CppSamples::Bookmarks::AddBookmark::SelectDataSourceIndex ( VxSdk::VxCollection< VxSdk::IVxDataSource ** > &  dataSources)
private

Select a data source from the given collection by user input.

Parameters
dataSourcesCollection of data source.
Returns
Index of the selected data source in the given collection.

Definition at line 84 of file AddBookmark.cpp.

84  {
85  while (true) {
86  // Select a Data source
87  cout << "\n" << "Enter data source number [1-" << dataSources.collectionSize << "] : ";
88  int dataSourceNumber = Utility::ReadInt();
89  if (dataSourceNumber == 0)
90  break;
91  // Verify input
92  if (dataSourceNumber > 0 && dataSourceNumber <= dataSources.collectionSize)
93  return dataSourceNumber - 1;
94  else
95  cout << "\n" << "Invalid Option !!!";
96 
97  cout << "\n" << "Enter 0 to go back.";
98  }
99 
100  return -1;
101 }

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