Skip to content
This repository has been archived by the owner on Nov 25, 2021. It is now read-only.

Commit

Permalink
Merge branch '1.4-rel' (758fc4a)
Browse files Browse the repository at this point in the history
Relate-to:
      I47ae68cbd633f0e8ffb38cde3e1b984e1c8505f5
      Ib4e768c7401247dc9dd4917ff5a611396e8e07a1
      I27bab5b348a4b0c52319447ce52e9ebdf3755628
      Ife04ffe93cd1780b448aa43072d7eba869a672fb
      I9bed4ade3fb12747e35d390b4a4e0339288ff564
      I29a2bafd1d163c4754cc3edcb77c15661399cbeb
      Ib48c441f4e07acbb4d9f74ba070ae427956e4178
      Id680843a04f69090b4ae7554e18d442f093debc7
      I5d43bc1e950811bbabceb1f42fd8cdcae31f87d0

Change-Id: Iaed67e1f8365f4d4cafea3a7cf149a73a7c601a4
Bug: https://jira.iotivity.org/browse/IOT-2453
Signed-off-by: Philippe Coval <philippe.coval@osg.samsung.com>
  • Loading branch information
rzr committed Sep 21, 2018
2 parents 8de4f43 + 758fc4a commit da40eb7
Show file tree
Hide file tree
Showing 12 changed files with 202 additions and 62 deletions.
2 changes: 1 addition & 1 deletion bridging/common/SConscript
Expand Up @@ -55,7 +55,7 @@ mpmcommon_env.PrependUnique(CPPPATH=[

if target_os not in ['windows']:
mpmcommon_env.AppendUnique(
CXXFLAGS=['-std=c++0x', '-Wall', '-Wextra', '-Werror', '-fpic'])
CXXFLAGS=['-std=c++0x', '-Wall', '-Wextra', '-fpic'])

mpmcommon_env['LINKFLAGS'] = maskFlags(mpmcommon_env['LINKFLAGS'])

Expand Down
8 changes: 8 additions & 0 deletions resource/csdk/include/octypes.h
Expand Up @@ -1447,6 +1447,13 @@ typedef enum
PAYLOAD_TYPE_INTROSPECTION
} OCPayloadType;

/** Enum to describe payload interface interface.*/
typedef enum
{
PAYLOAD_NON_BATCH_INTERFACE,
PAYLOAD_BATCH_INTERFACE
} OCPayloadInterfaceType;

/**
* A generic struct representing a payload returned from a resource operation
*
Expand Down Expand Up @@ -1526,6 +1533,7 @@ typedef struct OCRepPayloadValue
typedef struct OCRepPayload
{
OCPayload base;
OCPayloadInterfaceType ifType;
char* uri;
OCStringLL* types;
OCStringLL* interfaces;
Expand Down
191 changes: 140 additions & 51 deletions resource/csdk/resource-directory/samples/rd_publishingClient.cpp
Expand Up @@ -22,20 +22,20 @@
#include <iostream>
#include <sstream>
#include <limits>
#include <condition_variable>
#include <mutex>
#include <thread>

#include "oic_string.h"
#include "rd_client.h"

/// This example is using experimental API, so there is no guarantee of support for future release,
/// nor any there any guarantee that breaking changes will not occur across releases.
/// logging part is not critical but convenient for developer
#include "experimental/payload_logging.h"

#define TAG ("RD_PublishClient")
#define DEFAULT_CONTEXT_VALUE 0x99

OCResourceHandle handles[2];
std::ostringstream rdAddress;
std::string rdAddress;
std::mutex mutex;
std::condition_variable cond;
int in = 0;

OCStackResult registerLocalResources()
{
Expand Down Expand Up @@ -74,11 +74,11 @@ void printHelp()
{
std::cout << std::endl;
std::cout << "********************************************" << std::endl;
std::cout << "* method Type : 1 - Discover RD *" << std::endl;
std::cout << "* method Type : 2 - Publish *" << std::endl;
std::cout << "* method Type : 3 - Update *" << std::endl;
std::cout << "* method Type : 4 - Delete *" << std::endl;
std::cout << "* method Type : 5 - Status *" << std::endl;
std::cout << "* method Type : 1 - Discover RD *" << std::endl;
std::cout << "* method Type : 2 - Publish *" << std::endl;
std::cout << "* method Type : 3 - Update *" << std::endl;
std::cout << "* method Type : 4 - Delete *" << std::endl;
std::cout << "* method Type : 99 - Exit *" << std::endl;
std::cout << "********************************************" << std::endl;
std::cout << std::endl;
}
Expand All @@ -88,9 +88,11 @@ static OCStackApplicationResult handleDiscoveryCB(__attribute__((unused))void *c
__attribute__((unused))
OCClientResponse *clientResponse)
{
OIC_LOG(DEBUG, TAG, "Successfully found RD.");
rdAddress << clientResponse->devAddr.addr << ":" << clientResponse->devAddr.port;
std::cout << "RD Address is : " << rdAddress.str() << std::endl;
std::cout << "Successfully found RD." << std::endl;
std::ostringstream oss;
oss << clientResponse->devAddr.addr << ":" << clientResponse->devAddr.port;
rdAddress = oss.str();
std::cout << "RD Address is : " << rdAddress << std::endl;
return OC_STACK_DELETE_TRANSACTION;
}

Expand All @@ -99,17 +101,127 @@ static OCStackApplicationResult handlePublishCB(__attribute__((unused))void *ctx
__attribute__((unused))
OCClientResponse *clientResponse)
{
OIC_LOG(DEBUG, TAG, "Successfully published resources.");
std::cout << "Successfully published resources." << std::endl;
return OC_STACK_DELETE_TRANSACTION;
}

int main(void)
static OCStackApplicationResult handleUpdateCB(__attribute__((unused))void *ctx,
__attribute__((unused)) OCDoHandle handle,
__attribute__((unused))
OCClientResponse *clientResponse)
{
std::cout << "Successfully updated resources." << std::endl;
return OC_STACK_DELETE_TRANSACTION;
}

static OCStackApplicationResult handleDeleteCB(__attribute__((unused))void *ctx,
__attribute__((unused)) OCDoHandle handle,
__attribute__((unused))
OCClientResponse *clientResponse)
{
std::cout << "Successfully deleted resources." << std::endl;
return OC_STACK_DELETE_TRANSACTION;
}

static void ocThread()
{
OCStackResult result;
bool run = true;
while (run)
{
std::unique_lock<std::mutex> lock(mutex);
if (cond.wait_for(lock, std::chrono::milliseconds(100)) == std::cv_status::no_timeout)
{
switch (in)
{
case 1:
{
OCCallbackData cbData;
cbData.cb = &handleDiscoveryCB;
cbData.cd = NULL;
cbData.context = (void*) DEFAULT_CONTEXT_VALUE;
result = OCRDDiscover(nullptr, CT_ADAPTER_IP, &cbData, OC_LOW_QOS);
if (OC_STACK_OK != result)
{
std::cout << "OCRDDiscover Failed " << result << std::endl;
}
break;
}
case 2:
{
OCCallbackData cbData;
cbData.cb = &handlePublishCB;
cbData.cd = NULL;
cbData.context = (void*) DEFAULT_CONTEXT_VALUE;
result = OCRDPublish(nullptr, rdAddress.c_str(), CT_ADAPTER_IP, handles,
2, OIC_RD_PUBLISH_TTL, &cbData, OC_LOW_QOS);
if (OC_STACK_OK != result)
{
std::cout << "OCRDPublish Failed " << result << std::endl;
}
break;
}
case 3:
{
/* Update the TTL */
OCCallbackData cbData;
cbData.cb = &handleUpdateCB;
cbData.cd = NULL;
cbData.context = (void*) DEFAULT_CONTEXT_VALUE;
result = OCRDPublish(nullptr, rdAddress.c_str(), CT_ADAPTER_IP, handles,
2, OIC_RD_PUBLISH_TTL, &cbData, OC_LOW_QOS);
if (OC_STACK_OK != result)
{
std::cout << "OCRDPublish Failed " << result << std::endl;
}
break;
}
case 4:
{
/* Delete all resources */
OCCallbackData cbData;
cbData.cb = &handleDeleteCB;
cbData.cd = NULL;
cbData.context = (void*) DEFAULT_CONTEXT_VALUE;
result = OCRDDelete(nullptr, rdAddress.c_str(), CT_ADAPTER_IP, NULL,
0, &cbData, OC_LOW_QOS);
if (OC_STACK_OK != result)
{
std::cout << "OCRDDelete Failed " << result << std::endl;
}
break;
}
case 99:
run = false;
break;
default:
std::cout << "Invalid input, please try again" << std::endl;
break;
}
printHelp();
}
result = OCProcess();
if (OC_STACK_OK != result)
{
std::cout << "OCProcess Failed " << result << std::endl;
break;
}
}
}

int main()
{
std::cout << "Initializing IoTivity Platform" << std::endl;
OCStackResult result = OCInit(NULL, 0, OC_CLIENT_SERVER);
if (OC_STACK_OK != result)
{
std::cout << "OCInit Failed" << result << std::endl;
std::cout << "OCInit Failed " << result << std::endl;
return -1;
}
result = OCStopMulticastServer();
if (OC_STACK_OK != result)
{
std::cout << "OCStopMulticastServer Failed " << result << std::endl;
return -1;
}

Expand All @@ -121,15 +233,12 @@ int main(void)
return -1;
}

printHelp();

std::thread t(ocThread);

while (1)
{
if (handles[0] == NULL || handles[1] == NULL)
{
continue;
}
printHelp();

int in = 0;
std::cin >> in;

if (std::cin.fail())
Expand All @@ -140,34 +249,14 @@ int main(void)
continue;
}

switch ((int)in)
cond.notify_one();

if (in == 99)
{
case 1:
{
OCCallbackData cbData;
cbData.cb = &handleDiscoveryCB;;
cbData.cd = NULL;
cbData.context = (void*) DEFAULT_CONTEXT_VALUE;
OCRDDiscover(nullptr, 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(nullptr, address.c_str(), CT_ADAPTER_IP, handles,
2, OIC_RD_PUBLISH_TTL, &cbData, OC_LOW_QOS);
break;
}
case 3:
break;
default:
std::cout << "Invalid input, please try again" << std::endl;
break;
break;
}
}

t.join();
return 0;
}
9 changes: 7 additions & 2 deletions resource/csdk/resource-directory/samples/rd_queryClient.cpp
Expand Up @@ -36,11 +36,11 @@ OCStackApplicationResult foundResource(void* ctx,
OCClientResponse *clientResponse)
{
(void)handle;
(void) ctx;
(void)ctx;
if (clientResponse == NULL)
{
std::cout << "foundResource received NULL clientResponse" << std::endl;
return OC_STACK_DELETE_TRANSACTION;
return OC_STACK_DELETE_TRANSACTION;
}

std::cout << "Found resource response." << std::endl;
Expand Down Expand Up @@ -102,5 +102,10 @@ int main(void)
sendRequest = true;
}
}
if (OCProcess() != OC_STACK_OK)
{
std::cout << "OCStack process error" << std::endl;
return -1;
}
}
}
2 changes: 2 additions & 0 deletions resource/csdk/stack/include/ocpayload.h
Expand Up @@ -114,6 +114,8 @@ void OC_CALL OCRepPayloadAppend(OCRepPayload* parent, OCRepPayload* child);

bool OC_CALL OCRepPayloadSetUri(OCRepPayload* payload, const char* uri);

bool OC_CALL OCRepPayloadSetInterfaceType(OCRepPayload* payload, OCPayloadInterfaceType type);

bool OC_CALL OCRepPayloadAddResourceType(OCRepPayload* payload, const char* resourceType);
bool OC_CALL OCRepPayloadAddInterface(OCRepPayload* payload, const char* iface);

Expand Down
1 change: 1 addition & 0 deletions resource/csdk/stack/octbstack_product.def
Expand Up @@ -120,6 +120,7 @@ OCRepPayloadSetPropStringAsOwner
OCRepPayloadSetStringArray
OCRepPayloadSetStringArrayAsOwner
OCRepPayloadSetUri
OCRepPayloadSetInterfaceType
OCResourcePayloadAddNewEndpoint
OCResourcePayloadAddStringLL
OCSecurityPayloadCreate
Expand Down
Expand Up @@ -211,6 +211,7 @@ OCEntityHandlerResult OCEntityHandlerRoomCb(OCEntityHandlerFlag flag,
{

OCRepPayloadSetUri(payload, gRoomResourceUri);
OCRepPayloadSetInterfaceType(payload, PAYLOAD_BATCH_INTERFACE);

OCRepPayload *tempPayload = OCRepPayloadCreate();
OCRepPayloadSetUri(tempPayload, gLightResourceUri);
Expand Down
13 changes: 13 additions & 0 deletions resource/csdk/stack/src/ocpayload.c
Expand Up @@ -85,6 +85,7 @@ OCRepPayload* OC_CALL OCRepPayloadCreate(void)
return NULL;
}

payload->ifType = PAYLOAD_NON_BATCH_INTERFACE;
payload->base.type = PAYLOAD_TYPE_REPRESENTATION;

return payload;
Expand Down Expand Up @@ -495,6 +496,17 @@ bool OC_CALL OCRepPayloadSetUri(OCRepPayload* payload, const char* uri)
return payload->uri != NULL;
}

bool OC_CALL OCRepPayloadSetInterfaceType(OCRepPayload* payload, OCPayloadInterfaceType type)
{
if (!payload)
{
return false;
}

payload->ifType = type;
return true;
}

bool OC_CALL OCRepPayloadIsNull(const OCRepPayload* payload, const char* name)
{
OCRepPayloadValue* val = OCRepPayloadFindValue(payload, name);
Expand Down Expand Up @@ -1622,6 +1634,7 @@ OCRepPayload* OC_CALL OCRepPayloadBatchClone(const OCRepPayload* repPayload)
}

clone->types = CloneOCStringLL(repPayload->types);
clone->ifType = repPayload->ifType;
clone->interfaces = CloneOCStringLL(repPayload->interfaces);
clone->values = OCRepPayloadValueClone(repPayload->values);
OCRepPayloadSetPropObjectAsOwner(newPayload, OC_RSRVD_REPRESENTATION, clone);
Expand Down

0 comments on commit da40eb7

Please sign in to comment.