Skip to main content

Go Offline

The following code sample illustrates how to take a remote engine client off line from the key service.


Code Sample

See the C++ environment settings for details on setting the project environment.


<cpp_adminlocal_gooffline.cpp>
/*****************************************************************************************
*
* cpp_adminlocal_gooffline.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;

int main()
{
string strServer = "localhost"; // this is the remote engine
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 goOffLine().
conn->open(strServer, nPort, *ctx.operator->());

cout << "Connected to " << strServer << " as " << strUser
<< " at port " << nPort << endl;

// Local administrator
TEAdminLocal adminlocal;
adminlocal.attachConnection(conn.operator->());

uint32_t nNew = 5;
uint32_t nNewRet = (long)-1;
uint32_t nMark = (long)-1;
uint32_t nMarkRet = (long)-1;

// Go offline
adminlocal.goOffLine(nNew, &nNewRet, &nMark, &nMarkRet);

cout << "Client is now Offline:" << endl;
cout << "New keys genetated = " << nNewRet << endl;
cout << "Number of marked keys to be checked out = " << nMark << endl;
cout << "Number of marked keys checked out = " << nMarkRet << 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;
}
Output
Connected to localhost as ls at port 5050
Client is now Offline:
New keys genetated = 5
Number of marked keys to be checked out = 0
Number of marked keys checked out = 0
Disconnected from localhost