rd_sample_app_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-Wextra', '-std=c++0x'])
rd_sample_app_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
rd_sample_app_env.AppendUnique(RPATH = [env.get('BUILD_DIR')])
-rd_sample_app_env.PrependUnique(LIBS = ['resource_directory', 'oc', 'octbstack'])
+rd_sample_app_env.PrependUnique(LIBS = ['resource_directory', 'octbstack'])
if env.get('SECURED') == '1':
rd_sample_app_env.AppendUnique(LIBS = ['mbedtls', 'mbedx509', 'mbedcrypto'])
if 'CLIENT' in rd_sample_app_env.get('RD_MODE'):
rd_publishingClient = rd_sample_app_env.Program('rd_publishingClient', 'rd_publishingClient.cpp')
- rd_client = rd_sample_app_env.Program('rd_client', 'rdclient.cpp')
- Alias("resource_directory", [rd_publishingClient, rd_client, rd_queryClient])
+ Alias("resource_directory", [rd_publishingClient, rd_queryClient])
env.AppendTarget('resource_directory')
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include <iostream>
+#include <sstream>
+#include <limits>
-#include "OCPlatform.h"
-#include "OCApi.h"
#include "oic_string.h"
#include "rd_client.h"
#define TAG ("RD_PublishClient")
#define DEFAULT_CONTEXT_VALUE 0x99
-using namespace OC;
-
OCResourceHandle handles[2];
std::ostringstream rdAddress;
-
-void registerLocalResources()
+OCStackResult registerLocalResources()
{
std::string resourceURI_thermostat = "/a/thermostat";
std::string resourceTypeName_thermostat = "core.thermostat";
std::string resourceURI_light = "/a/light";
std::string resourceTypeName_light = "core.light";
- std::string resourceInterface = DEFAULT_INTERFACE;
+ std::string resourceInterface = OC_RSRVD_INTERFACE_DEFAULT;
uint8_t resourceProperty = OC_DISCOVERABLE;
- OCStackResult result = OCPlatform::registerResource(handles[0],
- resourceURI_thermostat,
- resourceTypeName_thermostat,
- resourceInterface,
- NULL,
- resourceProperty);
+ OCStackResult result = OCCreateResource(&handles[0],
+ resourceTypeName_thermostat.c_str(),
+ resourceInterface.c_str(),
+ resourceURI_thermostat.c_str(),
+ NULL,
+ NULL,
+ resourceProperty);
if (OC_STACK_OK != result)
{
- throw std::runtime_error(
- std::string("Device Resource failed to start") + std::to_string(result));
+ return result;
}
- result = OCPlatform::registerResource(handles[1],
- resourceURI_light,
- resourceTypeName_light,
- resourceInterface,
- NULL,
- resourceProperty);
+ result = OCCreateResource(&handles[1],
+ resourceTypeName_light.c_str(),
+ resourceInterface.c_str(),
+ resourceURI_light.c_str(),
+ NULL,
+ NULL,
+ resourceProperty);
- if (OC_STACK_OK != result)
- {
- throw std::runtime_error(
- std::string("Device Resource failed to start") + std::to_string(result));
- }
+ return result;
}
void printHelp()
int main()
{
- int in;
- PlatformConfig cfg;
-
- OCPlatform::Configure(cfg);
-
- std::cout << "Created Platform..." << std::endl;
-
- try
+ std::cout << "Initializing IoTivity Platform" << std::endl;
+ OCStackResult result = OCInit(NULL, 0, OC_CLIENT_SERVER);
+ if (OC_STACK_OK != result)
{
- registerLocalResources();
+ std::cout << "OCInit Failed" << result << std::endl;
+ return -1;
}
- catch (std::runtime_error e)
+
+ std::cout << "Created Platform..." << std::endl;
+ result = registerLocalResources();
+ if (OC_STACK_OK != result)
{
- std::cout << "Caught OCException [Code: " << e.what() << std::endl;
+ std::cout << "Could not create the resource " << result << std::endl;
+ return -1;
}
while (1)
{
- sleep(2);
-
if (handles[0] == NULL || handles[1] == NULL)
{
continue;
}
printHelp();
- in = 0;
+ int in = 0;
std::cin >> in;
if (std::cin.fail())
continue;
}
- try
+ switch ((int)in)
{
- switch ((int)in)
+ case 1:
{
- case 1:
- {
- OCCallbackData cbData;
- cbData.cb = &handleDiscoveryCB;;
- cbData.cd = NULL;
- cbData.context = (void*) DEFAULT_CONTEXT_VALUE;
- OCRDDiscover(CT_ADAPTER_IP, &cbData, OC_LOW_QOS);
- break;
- }
- case 2:
- {
- OCCallbackData cbData;
- cbData.cb = &handlePublishCB;
- cbData.cd = NULL;
- cbData.context = (void*) DEFAULT_CONTEXT_VALUE;
- std::string address = rdAddress.str();
- OCRDPublish(address.c_str(), CT_ADAPTER_IP, handles,
- 2, &cbData, OC_LOW_QOS);
- break;
- }
- case 3:
- break;
- default:
- std::cout << "Invalid input, please try again" << std::endl;
- break;
+ OCCallbackData cbData;
+ cbData.cb = &handleDiscoveryCB;;
+ cbData.cd = NULL;
+ cbData.context = (void*) DEFAULT_CONTEXT_VALUE;
+ OCRDDiscover(CT_ADAPTER_IP, &cbData, OC_LOW_QOS);
+ break;
}
- }
- catch (OCException e)
- {
- std::cout << "Caught OCException [Code: " << e.code() << " Reason: " << e.reason() << std::endl;
+ case 2:
+ {
+ OCCallbackData cbData;
+ cbData.cb = &handlePublishCB;
+ cbData.cd = NULL;
+ cbData.context = (void*) DEFAULT_CONTEXT_VALUE;
+ std::string address = rdAddress.str();
+ OCRDPublish(address.c_str(), CT_ADAPTER_IP, handles,
+ 2, &cbData, OC_LOW_QOS);
+ break;
+ }
+ case 3:
+ break;
+ default:
+ std::cout << "Invalid input, please try again" << std::endl;
+ break;
}
}
return 0;
// limitations under the License.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-#include "OCApi.h"
-#include "OCPlatform.h"
+#include <iostream>
+#include "octypes.h"
+#include "ocstack.h"
+#include "payload_logging.h"
bool g_foundResource = true;
static int count = 0;
-using namespace OC;
+#define DEFAULT_CONTEXT_VALUE (0x99)
-void foundResource(std::shared_ptr< OC::OCResource > resource)
+OCStackApplicationResult foundResource(void* ctx,
+ OCDoHandle handle,
+ OCClientResponse *clientResponse)
{
- try
+ (void)handle;
+ (void) ctx;
+ if (clientResponse == NULL)
{
- std::cout << "Found resource response." << std::endl;
- if (resource)
- {
- // if (resource->uri() == "/a/light")
- {
- std::cout << "Found Resource at @ URI: " << resource->uri() << "\tHost Address: " <<
- resource->host() << std::endl;
- }
- count++;
- }
- else
- {
- std::cout << "Resource is invalid " << resource->uri() << std::endl;
- }
- if (count == 3)
- {
- g_foundResource = false;
- exit(0);
- }
+ std::cout << "foundResource received NULL clientResponse" << std::endl;
+ return OC_STACK_DELETE_TRANSACTION;
}
- catch (std::exception &ex)
+
+ std::cout << "Found resource response." << std::endl;
+ OIC_LOG_PAYLOAD(INFO, clientResponse->payload);
+ count++;
+
+ if (count == 3)
{
- std::cout << "Exception: " << ex.what() << " in foundResource" << std::endl;
- exit(1);
+ g_foundResource = false;
+ exit(0);
}
+ return OC_STACK_KEEP_TRANSACTION;
+}
+
+OCStackResult findResource(std::string str, OCClientResponseHandler cb)
+{
+ OCCallbackData cbData;
+ cbData.context = (void *)DEFAULT_CONTEXT_VALUE;
+ cbData.cb = cb;
+
+ return OCDoResource(nullptr, OC_REST_DISCOVER,
+ str.c_str(), nullptr, nullptr, CT_DEFAULT,
+ static_cast<OCQualityOfService>(OC_LOW_QOS),
+ &cbData, nullptr, 0);
}
int main()
{
- OC::PlatformConfig cfg;
- OC::OCPlatform::Configure(cfg);
bool sendRequest = true;
+ std::cout << "Initializing IoTivity Platform" << std::endl;
+ OCStackResult result = OCInit(NULL, 0, OC_CLIENT_SERVER);
+ if (result != OC_STACK_OK)
+ {
+ std::cout << "OCInit Failed" << result << std::endl;
+ return -1;
+ }
std::cout << "Created Platform..." << std::endl;
while (g_foundResource)
{
- try
+ if (sendRequest)
{
- if (sendRequest)
+ sendRequest = false;
+ std::cout << "Finding Resource light" << std::endl;
+ if (OC_STACK_OK != findResource("/oic/res?rt=core.light", foundResource))
{
- sendRequest = false;
- std::cout << "Finding Resource light" << std::endl;
- OC::OCPlatform::findResource("", "/oic/res?rt=core.light", CT_DEFAULT, &foundResource);
- OC::OCPlatform::findResource("", "/oic/res?if=oic.if.baseline", CT_DEFAULT, &foundResource);
- OC::OCPlatform::findResource("", "/oic/res", CT_DEFAULT, &foundResource);
+ std::cout << "Exception finding resources : " << std::endl;
+ sendRequest = true;
+ }
+ if (OC_STACK_OK != findResource("/oic/res?if=oic.if.baseline", foundResource))
+ {
+ std::cout << "Exception finding resources : " << std::endl;
+ sendRequest = true;
+ }
+ if (OC_STACK_OK != findResource("/oic/res", foundResource))
+ {
+ std::cout << "Exception finding resources : " << std::endl;
+ sendRequest = true;
}
- }
- catch (OC::OCException &ex)
- {
- sendRequest = true;
- std::cout << "Exception finding resources : " << ex.reason() << std::endl;
}
}
}
#include "rd_client.h"
#include <stdlib.h>
+#include <string.h>
#include "oic_malloc.h"
#include "oic_string.h"
}
}
- OCRepPayloadSetPropObjectArray(rdPayload, OC_RSRVD_LINKS, linkArr, dimensions);
+ OCRepPayloadSetPropObjectArray(rdPayload, OC_RSRVD_LINKS, (const OCRepPayload **)linkArr, dimensions);
OIC_LOG_PAYLOAD(DEBUG, (OCPayload *) rdPayload);
for (uint8_t i = 0; i < nPubResHandles; i++)
src_dir + '/resource/csdk/stack/test/',
src_dir + '/resource/oc_logger/include',])
-
rd_test_env.AppendUnique(LIBPATH = [lib_env.get('BUILD_DIR')])
rd_test_env.AppendUnique(RPATH = [lib_env.get('BUILD_DIR')])
rd_test_env.PrependUnique(LIBS = ['resource_directory', 'octbstack' ])
'groupserver',
'groupclient',
'lightserver',
- 'threadingsample'
+ 'threadingsample',
+ ]
+
+if 'CLIENT' in examples_env.get('RD_MODE'):
+ examples_env.AppendUnique(CPPDEFINES = ['RD_CLIENT'])
+ example_names += [
+ 'rdclient'
]
examples = map(make_single_file_cpp_program, example_names)