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

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

#include <AddNotification.h>

Public Member Functions

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

std::vector< std::string > GetSelectedRoles (VxSdk::IVxSystem *vxSystem)
 Get a list of selected roles from the given VideoExpert system. More...
 
VxSdk::VxCollection< VxSdk::IVxRole ** > GetRoles (VxSdk::IVxSystem *vxSystem)
 Get a collection of roles from the given VideoExpert system. More...
 

Detailed Description

This plugin sample adds a notification to the current system.

Definition at line 14 of file AddNotification.h.

Inherits CppSamples::Common::Plugin.

Constructor & Destructor Documentation

CppSamples::Notifications::AddNotification::AddNotification ( const std::string  description)
inline

Definition at line 16 of file AddNotification.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::Notifications::AddNotification::~AddNotification ( )
inline

Definition at line 17 of file AddNotification.h.

17 {}

Member Function Documentation

VxCollection< IVxRole ** > CppSamples::Notifications::AddNotification::GetRoles ( VxSdk::IVxSystem vxSystem)
private

Get a collection of roles from the given VideoExpert system.

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

Definition at line 79 of file AddNotification.cpp.

79  {
81  // Read the size of collection from system.
82  VxResult::Value result = vxSystem->GetRoles(roles);
83  if (result == VxResult::kInsufficientSize) {
84  // Allocate memory for the requried collection.
85  roles.collection = new IVxRole*[roles.collectionSize];
86  // Read the collection from system.
87  vxSystem->GetRoles(roles);
88  }
89  return roles;
90 }
virtual VxResult::Value GetRoles(VxCollection< IVxRole ** > &roleCollection) const =0
vector< string > CppSamples::Notifications::AddNotification::GetSelectedRoles ( VxSdk::IVxSystem vxSystem)
private

Get a list of selected roles from the given VideoExpert system.

Parameters
vxSystemPointer to the VideoExpert system.
Returns
A list of selected roles.

Definition at line 51 of file AddNotification.cpp.

51  {
52 
53  vector<string> selectedRoles;
54 
55  VxCollection<IVxRole**> allRoles = GetRoles(vxSystem);
56  for (int i = 0; i < allRoles.collectionSize; i++) {
57  IVxRole* role = allRoles.collection[i];
58 
59  if (role->isReadOnly && (strcmp(role->name, "administrator") != 0))
60  continue;
61 
62  cout << "\n" << "Select role (" << role->name<< ") y/n : ";
63  string option = Utility::ReadString();
64  if (option.size() > 0 && (option[0] == 'y' || option[0] == 'Y')) {
65  selectedRoles.push_back(string(role->id));
66  cout << role->name << " is selected. \n";
67  }
68  else
69  cout << role->name << " is NOT selected. \n";
70  }
71  return selectedRoles;
72 }
VxSdk::VxCollection< VxSdk::IVxRole ** > GetRoles(VxSdk::IVxSystem *vxSystem)
Get a collection of roles from the given VideoExpert system.
Plugin * CppSamples::Notifications::AddNotification::Run ( CppSamples::Common::DataModel dataModel)
overridevirtual

Adds a notification to the current system.

Parameters
dataModelInstance of data model.

Implements CppSamples::Common::Plugin.

Definition at line 14 of file AddNotification.cpp.

14  {
15  // Get a list of selected roles from the system
16  vector<string> roleIds = GetSelectedRoles(dataModel->VxSystem);
17 
18  // Create a notification object and populate its fields using newNotification
19  VxNewNotification vxNotification;
20  vxNotification.roleIdSize = static_cast<int>(roleIds.size());
21  if (vxNotification.roleIdSize > 0) {
22  // Allocate memory for the role Ids.
23  vxNotification.roleIds = new char*[vxNotification.roleIdSize];
24  for (int i = 0; i < vxNotification.roleIdSize; i++) {
25  string roleId = roleIds[i];
26  vxNotification.roleIds[i] = new char[roleId.size() + 1];
27  Utilities::StrCopySafe(vxNotification.roleIds[i], roleId.c_str(), roleId.size() + 1);
28  }
29  }
30 
31  // Make the call to add the notification into VideoXpert
32  IVxNotification* notificationItem = nullptr;
33  VxResult::Value result = dataModel->VxSystem->AddNotification(vxNotification, notificationItem);
34  if (result == VxResult::kOK)
35  cout << "\n" << "Notification added succesfully.\n";
36  else
37  cout << "\n" << "Failed to add notification.\n";
38 
39  // Wait for user response before going back to parent menu.
40  Utility::Pause();
41 
42  // Return reference of parent plugin to move back to parent menu.
43  return GetParent();
44 }
virtual VxResult::Value AddNotification(VxNewNotification &newNotification, IVxNotification *&notificationItem) const =0
std::vector< std::string > GetSelectedRoles(VxSdk::IVxSystem *vxSystem)
Get a list of selected roles from the given VideoExpert system.
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

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