Set the Status of a T-tag
The following code sample illustrates how to set status information for a client.
Code Sample
See the C++ environment settings for details on setting the project environment.
<cpp_adminlocal_setstatus.cpp>
/*****************************************************************************************
*
* cpp_adminlocal_setstatus.cpp
*
*
******************************************************************************************/
#include<string>
#include<iostream>
#include "teagent.h"
#include "teconnection.h"
#include "teexception.h"
#include "teauthuserctx.h"
#include "teauthwinctx.h"
#include "teobject.h"
#include "teadmin_local.h"
using namespace ERUCES;
using namespace std;
string generateHiddenLink( string strServerName, long lPort, string strUsername, string strPassword );
int main()
{
string strServer = "localhost"; // this is the remote engine, not the TE server.
long nPort = 5050; // this is the local admin port.
string strUser = "ls"; // this is a normal TE user, not necessarily a TE admin user.
string strPswd = "password";
try
{
// Connect to local server
auto_ptr<TEConnection> conn = TEConnection::createInstance(TEConnection::SecureConnection);
auto_ptr<TEUserAuthenticationContext> ctx = TEUserAuthenticationContext::getInstance();
ctx->setUser(strUser);
ctx->setPasswd(strPswd);
ctx->setMode(2); // set to 2 if going to call setStatus().
conn->open(strServer, nPort, *ctx.operator->());
cout << "Connected to " << strServer << " as " << strUser
<< " at port " << nPort << endl;
// Local administrator
TEAdminLocal adminlocal;
adminlocal.attachConnection(conn.operator->());
// Prepare for set status
TEObjectContainer container;
_TESTD string strHL = generateHiddenLink( strServer, nPort, strUser, strPswd );
cout << "Hiddenlink: " << strHL << endl;
TESTR2UINT data1(_TESTD make_pair(strHL, 1)); // 1 = mark, 0 = unmark
container.add(&data1);
strHL = generateHiddenLink( strServer, nPort, strUser, strPswd );
cout << "Hiddenlink: " << strHL << endl;
TESTR2UINT data2(_TESTD make_pair(strHL, 1));
container.add(&data2);
// Set status, current client must be online.
adminlocal.setStatus(container, true);
cout << "Hiddenlink status was set." << endl;
// Check the result
adminlocal.getStatus(container, true);
cout << "Hiddenlink status were got." << endl;
uint32_t nStatus = static_cast<const TESTR2UINT*>(container[0])->getValue().second;
cout << "Status = " << nStatus << endl;
nStatus = static_cast<const TESTR2UINT*>(container[1])->getValue().second;
cout << "Status = " << nStatus << endl;
adminlocal.detachConnection();
// Disconnect from local server
conn->close();
cout << "Disconnected from " << strServer << endl;
}
catch (TEException &e)
{
cout << e.getAllMessages().c_str() << endl;
}
catch (...)
{
cout << "Unexpected error" << endl;
}
return 0;
}
string generateHiddenLink( string strServerName, long lPort, string strUsername, string strPassword )
{
string strHiddenLink = "";
auto_ptr<TEConnection> conn = TEConnection::createInstance(TEConnection::SecureConnection);
// Open connection to the server
conn->open(strServerName, lPort, strUsername, strPassword);
cout << "Connected to " << strServerName << " at " << lPort
<< " as " << strUsername << "\n" << endl;
// Create TEAgentMatrix object
TEAgentMatrix matrix;
// Original data for encryption
string str1_1 = "test string (1, 1)";
// Set matrix for encryption
matrix.setElement(1, 1, str1_1); // set element (1, 1)
// Encrypt matrix
matrix.attachConnection(conn.operator->()); // Attach connection
matrix.encrypt();
matrix.detachConnection(); // Detach connection
// Get hiddenlink
matrix.setEncodeMode(true);
matrix.getHiddenLink(1, strHiddenLink); // hiddenlink for first row
// Close conneciton
conn->close();
cout << "Disconnected from " << strServerName << endl;
return strHiddenLink;
}
Output
Connected to localhost as ls at port 5050
Connected to localhost at 5050 as ls
Disconnected from localhost
Hiddenlink: AAAAAYlokTXZh8S5wORhl6imcSwj7D+8Dbjirst97S0Ns45CGFKmPw==
Connected to localhost at 5050 as ls
Disconnected from localhost
Hiddenlink: AAAAAVXnjUysLoQlZ2eH96M3EvoRlmktpVVIeF0Orz0RIgT9Q1I2Bg==
Hiddenlink status was set.
Hiddenlink status were got.
Status = 1
Status = 1
Disconnected from localhost