Context C++
Context API related documentation. More...
Classes | |
| class | Context |
| Allows to interact with a Context service. More... | |
Detailed Description
A quick overview of basic Context API capabilities and examples is given.
If you find Context API useful and would like to know more details, please check out further sections of the Context API documentation or contact the Deepsy team.
Examples
Getting Context device parameters
/*
* @example getParametersExample.cpp
* This is an example of how to obtain context memory device paramters (type and size)
*/
#include <dpy/contextApi.h>
#include <iostream>
volatile bool waiting = true;
void get_memory_type_handler(boost::system::error_code error_code, std::string memoryType)
{
if (error_code.value() != 0) {
std::cout << "\rError : " << error_code.message() << std::endl;
} else {
if (memoryType.length() != 0) {
std::cout << "Memory Type: " << memoryType << std::endl;
} else {
std::cout << "Unknown Type" << std::endl;
}
}
waiting = false;
}
void get_context_size_handler(boost::system::error_code error_code, unsigned int contextSize)
{
if (error_code.value() != 0) {
std::cout << "\rError : " << error_code.message() << std::endl;
} else {
std::cout << "Context Size: " << contextSize << std::endl;
}
waiting = false;
}
int main()
{
ContextManager contextManager;
const std::string& deviceid = "CONTEXT";
contextManager.asyncGetMemoryType(get_memory_type_handler, deviceid);
while (waiting == true)
{
}
waiting = true;
contextManager.asyncGetContextSize(get_context_size_handler, deviceid);
while (waiting == true)
{
}
return 0;
}
Setting Memory values
/*
* @example setMemoryValuesExample.cpp
* This example reads some bytes from a certain memory device position,
* then write some values and finally read them again to check they were properly written
*/
#include <dpy/contextApi.h>
#include <iostream>
volatile bool waiting = true;
void get_context_handler(boost::system::error_code error_code, std::string data)
{
if (error_code.value() != 0) {
std::cout << "\rError : " << error_code.message() << std::endl;
} else {
if (data.length() != 0) {
std::cout << "Data: " << data << std::endl;
} else {
std::cout << "No data obtained" << std::endl;
}
}
waiting = false;
}
void result_handler(boost::system::error_code error_code)
{
if (error_code) {
std::cout << "\rError : " << error_code.message() << std::endl;
} else {
std::cout << "\rAsynchronous operation performed successfully" << std::endl;
}
waiting = false;
}
int main()
{
ContextManager contextManager;
const std::string& deviceid = "CONTEXT";
std::string valuesRead;
std::string valuesToWrite("This is a number sequence: ");
//Append some hex values (in this case they are ASCII character to make them printable)
valuesToWrite.append(1,0x31);
valuesToWrite.append(1,0x32);
valuesToWrite.append(1,0x33);
contextManager.asyncGetMemoryValues(get_context_handler, deviceid, 16, valuesToWrite.length());
while (waiting == true)
{
}
waiting = true;
std::cout << "Writing: '" << valuesToWrite << "'" << std::endl;
sleep(1);
contextManager.asyncSetMemoryValues(result_handler, deviceid, 16, valuesToWrite);
while (waiting == true)
{
}
waiting = true;
contextManager.asyncGetMemoryValues(get_context_handler, deviceid, 16, valuesToWrite.length());
while (waiting == true)
{
}
return 0;
}
Dump context
/*
* @example dumpContextExample.cpp
* This example reads the full context memory device
*/
#include <dpy/contextApi.h>
#include <iostream>
volatile bool waiting = true;
void get_context_handler(boost::system::error_code error_code, std::string data)
{
if (error_code.value() != 0) {
std::cout << "\rError : " << error_code.message() << std::endl;
} else {
if (data.length() != 0) {
std::cout << "Data: " << data << std::endl;
} else {
std::cout << "No data obtained" << std::endl;
}
}
waiting = false;
}
int main()
{
ContextManager contextManager;
const std::string& deviceid = "CONTEXT";
contextManager.asyncDumpContext(get_context_handler, deviceid);
while (waiting == true)
{
}
return 0;
}
void asyncGetContextSize(dpyContext::context_size_handler_function handler, std::string deviceid)
Get context size.
void asyncGetMemoryType(dpyContext::memory_type_handler_function handler, std::string deviceid)
Get context memory type.
void asyncSetMemoryValues(dpyContext::result_handler_function handler, std::string deviceid, unsigned int position, const std::string &data)
Set context memory values.
void asyncGetMemoryValues(dpyContext::get_context_handler_function handler, std::string deviceid, unsigned int position, unsigned int length)
Get context memory values.
boost::function< void(boost::system::error_code &ec)> result_handler
Handler for result function callback. This type of function is called when the status callback is don...
Definition: rtcApi.h:40
Definition: contextApi.h:67
void asyncDumpContext(dpyContext::get_context_handler_function handler, std::string deviceid)
Get all context memory data.