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

This plugin sample delete a selected user from the current system. More...

#include <DeleteUser.h>

Public Member Functions

 DeleteUser (const std::string description)
 
 ~DeleteUser ()
 
CppSamples::Common::PluginRun (CppSamples::Common::DataModel *dataModel) override
 Delete a selected user from 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...
 

Protected Member Functions

int SelectUserIndex (VxSdk::VxCollection< VxSdk::IVxUser ** > &users)
 Select a user from the given collection by user input. More...
 

Static Protected Member Functions

static VxSdk::VxCollection< VxSdk::IVxUser ** > GetUsers (VxSdk::IVxSystem *vxSystem)
 Get a collection of users from the given VideoExpert system. More...
 
static void PrintUsers (VxSdk::VxCollection< VxSdk::IVxUser ** > userCollection)
 Prints the given collection of users to the screen. More...
 

Detailed Description

This plugin sample delete a selected user from the current system.

Definition at line 12 of file DeleteUser.h.

Inherits CppSamples::Common::Plugin.

Constructor & Destructor Documentation

CppSamples::Users::DeleteUser::DeleteUser ( const std::string  description)
inline

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

Definition at line 15 of file DeleteUser.h.

15 { }

Member Function Documentation

VxCollection< IVxUser ** > CppSamples::Users::DeleteUser::GetUsers ( VxSdk::IVxSystem vxSystem)
staticprotected

Get a collection of users from the given VideoExpert system.

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

Definition at line 45 of file DeleteUser.cpp.

45  {
47  VxResult::Value result = vxSystem->GetUsers(users);
48  if (result == VxResult::kInsufficientSize) {
49  users.collection = new IVxUser*[users.collectionSize];
50  vxSystem->GetUsers(users);
51  }
52  return users;
53 }
virtual VxResult::Value GetUsers(VxCollection< IVxUser ** > &userCollection) const =0
void CppSamples::Users::DeleteUser::PrintUsers ( VxSdk::VxCollection< VxSdk::IVxUser ** >  userCollection)
staticprotected

Prints the given collection of users to the screen.

Parameters
userCollectionCollection of users.

Definition at line 59 of file DeleteUser.cpp.

59  {
60 
61  cout << userCollection.collectionSize << " users found." << "\n";
62  if (userCollection.collectionSize == 0)
63  return;
64 
65  cout << "---------------------------------------------------------------------------------------------";
66  for (int i = 0; i < userCollection.collectionSize; i++) {
67  IVxUser* user = userCollection.collection[i];
68 
69  cout << "\n" << (i + 1);
70  cout << "\t" << user->id;
71  cout << "\t" << user->name;
72  cout << "\t" << user->domain;
73  }
74  cout << "\n---------------------------------------------------------------------------------------------\n";
75 }
char domain[64]
Plugin * CppSamples::Users::DeleteUser::Run ( CppSamples::Common::DataModel dataModel)
overridevirtual

Delete a selected user from the current system.

Parameters
dataModelInstance of data model.

Implements CppSamples::Common::Plugin.

Definition at line 13 of file DeleteUser.cpp.

13  {
14  Utility::ClearScreen();
15 
16  VxCollection<IVxUser**> users = GetUsers(dataModel->VxSystem);
17  PrintUsers(users);
18 
19  if (users.collectionSize > 0) {
20  int index = SelectUserIndex(users);
21  if (index >= 0) {
22  IVxUser* user = users.collection[index];
23  VxResult::Value result = user->DeleteUser();
24  if (result == VxResult::kOK)
25  cout << "\n" << "User deleted succesfully.\n";
26  else
27  cout << "\n" << "Failed to delete user!!\n";
28  }
29  }
30 
31  // Remove the memory allocated to the collection.
32  delete[] users.collection;
33  // Wait for user response before going back to parent menu.
34  Utility::Pause();
35 
36  // Return reference of parent plugin to move back to parent menu.
37  return GetParent();
38 }
int SelectUserIndex(VxSdk::VxCollection< VxSdk::IVxUser ** > &users)
Select a user from the given collection by user input.
Definition: DeleteUser.cpp:82
VxSdk::IVxSystem * VxSystem
Represents a VideoXpert system and allows the user to manage the system and devices.
Definition: Plugin.h:17
static void PrintUsers(VxSdk::VxCollection< VxSdk::IVxUser ** > userCollection)
Prints the given collection of users to the screen.
Definition: DeleteUser.cpp:59
virtual VxResult::Value DeleteUser() const =0
Plugin * GetParent() const
Gets the reference to the parent of this plugin.
Definition: Plugin.h:46
static VxSdk::VxCollection< VxSdk::IVxUser ** > GetUsers(VxSdk::IVxSystem *vxSystem)
Get a collection of users from the given VideoExpert system.
Definition: DeleteUser.cpp:45
int CppSamples::Users::DeleteUser::SelectUserIndex ( VxSdk::VxCollection< VxSdk::IVxUser ** > &  users)
protected

Select a user from the given collection by user input.

Parameters
usersCollection of user.
Returns
Index of the selected user in the given collection.

Definition at line 82 of file DeleteUser.cpp.

82  {
83  while (true) {
84  cout << "\n" << "Enter user number [1-" << users.collectionSize << "] : ";
85  int index = Utility::ReadInt();
86  if (index == 0)
87  break;
88  if (index > 0 && index <= users.collectionSize)
89  return index - 1;
90  else
91  cout << "\n" << "Invalid Option !!!";
92 
93  cout << "\n" << "Enter 0 to go back.";
94  }
95 
96  return -1;
97 }

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