This sample demonstrates the usage of the Session Scheduler functionality.
#include "../Common/Helpers.h"
using namespace Samples;
{
const int MinutesPerHour = 60;
sinceMidnight / SecondsPerHour,
(sinceMidnight / SecondsPerMinute) % MinutesPerHour,
sinceMidnight % SecondsPerMinute);
}
{
{
}
};
{
public:
{
}
{
std::cout << "Scheduler reported a warning for the session " << session->toString() << ": " << warningReason;
}
{
std::cout << "Error occurred while scheduling session " << session->toString() << ": " << errorReason;
}
};
class Sample
{
public:
Sample()
{
about();
}
~Sample()
{
if(session_)
session_->disconnect();
delete session_;
delete scheduler_;
}
{
constructSession();
constructScheduler();
std::cout << "Scheduling session " << session_->toString() << " for automatic connection." << std::endl;
const SessionSchedule sessionSchedule = constructShortTimeActivitySchedule();
scheduler_->add(session_, sessionSchedule, sessionConnectivity);
std::cout << "Waiting for activity on scheduled session " << session_->toString() << '.' << std::endl << std::endl;
waitUntilLogout(session_);
std::cout << std::endl << "Removing session " << session_->toString() << " from scheduling service." << std::endl;
scheduler_->remove(session_);
}
void useConfigurationFile()
{
scheduler.add(session_, "ScheduleId", "ConnectionId");
scheduler_->remove(session_);
}
private:
SessionStateChangeTracer sessionStateChangeTracer_;
SchedulingIssueDetector schedulingIssueDetector_;
void constructScheduler()
{
}
void constructSession()
{
session_ =
new Session(settings, &sessionStateChangeTracer_);
}
{
}
static void waitUntilLogout(
Session * session)
{
const unsigned oneSecondPause = 1000;
}
static int sessionActivityTimeInSeconds()
{
return 30;
}
static void about()
{
std::cout << "OnixS C++ B3 BOE Session Scheduling Sample." << std::endl << std::endl;
}
};
void usage()
{
std::cerr << "usage: [MarketSegmentId] [Host] [Port]" << std::endl;
}
int main(int argc, char * argv[])
{
try
{
std::string host;
if (argc >= 2)
marketSegmentId = atoi(argv[1]);
if (argc >= 3)
host = argv[2];
if (argc >= 4)
port = atoi(argv[3]);
if (marketSegmentId == 0 || host.empty() || port == 0)
{
usage();
return 1;
}
Sample sample;
sample.run(host, port);
std::cout << std::endl << "Done." << std::endl;
}
catch(const std::exception & ex)
{
std::cerr << "Error: " << ex.what() << std::endl;
return 1;
}
return 0;
}