Commit 1704c7bd authored by Mandeep Shetty's avatar Mandeep Shetty Committed by Erich Keane

Update sample apps to include platform discovery at oic/p

Added platform discovery to go woth changeset moving oc/d to oic/p.
Updated ocserver/client and devicediscoveryserver/client to make
platform discovery requests.

Change-Id: I972fa8585c966a7d047f82d0cc0f18c01dcd6508
Signed-off-by: default avatarMandeep Shetty <mandeep.shetty@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1008Reviewed-by: default avatarErich Keane <erich.keane@intel.com>
Tested-by: default avatarjenkins-iotivity <jenkins-iotivity@opendaylight.org>
parent d60f4f48
...@@ -33,7 +33,9 @@ static int UNICAST_DISCOVERY = 0; ...@@ -33,7 +33,9 @@ static int UNICAST_DISCOVERY = 0;
static int TEST_CASE = 0; static int TEST_CASE = 0;
static const char * UNICAST_DISCOVERY_QUERY = "coap://%s:6298/oc/core"; static const char * UNICAST_DISCOVERY_QUERY = "coap://%s:6298/oc/core";
static const char * UNICAST_DEVICE_DISCOVERY_QUERY = "coap://%s:6298/oc/core/d"; static const char * UNICAST_DEVICE_DISCOVERY_QUERY = "coap://%s:6298/oc/core/d";
static const char * UNICAST_PLATFORM_DISCOVERY_QUERY = "coap://%s:6298/oic/p";
static const char * MULTICAST_DEVICE_DISCOVERY_QUERY = "/oc/core/d"; static const char * MULTICAST_DEVICE_DISCOVERY_QUERY = "/oc/core/d";
static const char * MULTICAST_PLATFORM_DISCOVERY_QUERY = "/oic/p";
static const char * MULTICAST_RESOURCE_DISCOVERY_QUERY = "/oc/core"; static const char * MULTICAST_RESOURCE_DISCOVERY_QUERY = "/oc/core";
//The following variable determines the interface protocol (IPv4, IPv6, etc) //The following variable determines the interface protocol (IPv4, IPv6, etc)
//to be used for sending unicast messages. Default set to IPv4. //to be used for sending unicast messages. Default set to IPv4.
...@@ -104,7 +106,7 @@ static void PrintUsage() ...@@ -104,7 +106,7 @@ static void PrintUsage()
"then cancel immediately with High QOS"); "then cancel immediately with High QOS");
OC_LOG(INFO, TAG, "-t 18 : Discover Resources and Initiate Nonconfirmable Get Request and "\ OC_LOG(INFO, TAG, "-t 18 : Discover Resources and Initiate Nonconfirmable Get Request and "\
"add vendor specific header options"); "add vendor specific header options");
OC_LOG(INFO, TAG, "-t 19 : Discover Devices"); OC_LOG(INFO, TAG, "-t 19 : Discover Platform");
} }
OCStackResult InvokeOCDoResource(std::ostringstream &query, OCStackResult InvokeOCDoResource(std::ostringstream &query,
...@@ -423,12 +425,12 @@ OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle handle, ...@@ -423,12 +425,12 @@ OCStackApplicationResult discoveryReqCB(void* ctx, OCDoHandle handle,
return OC_STACK_KEEP_TRANSACTION; return OC_STACK_KEEP_TRANSACTION;
} }
OCStackApplicationResult DeviceDiscoveryReqCB (void* ctx, OCDoHandle handle, OCStackApplicationResult PlatformDiscoveryReqCB (void* ctx, OCDoHandle handle,
OCClientResponse * clientResponse) OCClientResponse * clientResponse)
{ {
if (ctx == (void*) DEFAULT_CONTEXT_VALUE) if (ctx == (void*) DEFAULT_CONTEXT_VALUE)
{ {
OC_LOG(INFO, TAG, "Callback Context for Device DISCOVER query recvd successfully"); OC_LOG(INFO, TAG, "Callback Context for Platform DISCOVER query recvd successfully");
} }
if(clientResponse) if(clientResponse)
...@@ -439,7 +441,7 @@ OCStackApplicationResult DeviceDiscoveryReqCB (void* ctx, OCDoHandle handle, ...@@ -439,7 +441,7 @@ OCStackApplicationResult DeviceDiscoveryReqCB (void* ctx, OCDoHandle handle,
} }
else else
{ {
OC_LOG_V(INFO, TAG, "DeviceDiscoveryReqCB received Null clientResponse"); OC_LOG_V(INFO, TAG, "PlatformDiscoveryReqCB received Null clientResponse");
} }
return (UNICAST_DISCOVERY) ? OC_STACK_DELETE_TRANSACTION : OC_STACK_KEEP_TRANSACTION; return (UNICAST_DISCOVERY) ? OC_STACK_DELETE_TRANSACTION : OC_STACK_KEEP_TRANSACTION;
...@@ -656,17 +658,17 @@ int InitDeviceDiscovery(OCQualityOfService qos) ...@@ -656,17 +658,17 @@ int InitDeviceDiscovery(OCQualityOfService qos)
OCCallbackData cbData; OCCallbackData cbData;
char szQueryUri[64] = { 0 }; char szQueryUri[64] = { 0 };
cbData.cb = DeviceDiscoveryReqCB; cbData.cb = PlatformDiscoveryReqCB;
cbData.context = (void*)DEFAULT_CONTEXT_VALUE; cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
cbData.cd = NULL; cbData.cd = NULL;
if(UNICAST_DISCOVERY) if(UNICAST_DISCOVERY)
{ {
snprintf(szQueryUri, sizeof(szQueryUri), UNICAST_DEVICE_DISCOVERY_QUERY, ipv4addr); snprintf(szQueryUri, sizeof(szQueryUri), UNICAST_PLATFORM_DISCOVERY_QUERY, ipv4addr);
} }
else else
{ {
strncpy(szQueryUri, MULTICAST_DEVICE_DISCOVERY_QUERY, strncpy(szQueryUri, MULTICAST_PLATFORM_DISCOVERY_QUERY,
sizeof(szQueryUri) -1 ); sizeof(szQueryUri) -1 );
szQueryUri[sizeof(szQueryUri) -1] = '\0'; szQueryUri[sizeof(szQueryUri) -1] = '\0';
} }
......
...@@ -73,19 +73,23 @@ const char *deviceName = "myDeviceName"; ...@@ -73,19 +73,23 @@ const char *deviceName = "myDeviceName";
const char *deviceUUID = "myDeviceUUID"; const char *deviceUUID = "myDeviceUUID";
const char *firmwareVersion = "myFirmwareVersion"; const char *firmwareVersion = "myFirmwareVersion";
const char *hostName = "myHostName"; const char *hostName = "myHostName";
const char *manufacturerName = "myManufacturerNa"; const char *manufacturerName = "myName";
const char *operatingSystemVersion = "myOS";
const char *hardwareVersion = "myHardwareVersion";
const char* platformID = "myPlatformID";
const char *manufacturerUrl = "myManufacturerUrl"; const char *manufacturerUrl = "myManufacturerUrl";
const char *modelNumber = "myModelNumber"; const char *modelNumber = "myModelNumber";
const char *platformVersion = "myPlatformVersion"; const char *platformVersion = "myPlatformVersion";
const char *supportUrl = "mySupportUrl"; const char *supportUrl = "mySupportUrl";
const char *version = "myVersion"; const char *version = "myVersion";
const char *systemTime = "2015-05-15T11.04";
// Entity handler should check for resourceTypeName and ResourceInterface in order to GET // Entity handler should check for resourceTypeName and ResourceInterface in order to GET
// the existence of a known resource // the existence of a known resource
const char *resourceTypeName = "core.light"; const char *resourceTypeName = "core.light";
const char *resourceInterface = OC_RSRVD_INTERFACE_DEFAULT; const char *resourceInterface = OC_RSRVD_INTERFACE_DEFAULT;
OCDeviceInfo deviceInfo; OCPlatformInfo platformInfo;
//This function takes the request as an input and returns the response //This function takes the request as an input and returns the response
//in JSON format. //in JSON format.
...@@ -848,6 +852,143 @@ void *presenceNotificationGenerator(void *param) ...@@ -848,6 +852,143 @@ void *presenceNotificationGenerator(void *param)
} }
#endif #endif
int createLightResource (char *uri, LightResource *lightResource)
{
if (!uri)
{
OC_LOG(ERROR, TAG, "Resource URI cannot be NULL");
return -1;
}
lightResource->state = false;
lightResource->power= 0;
OCStackResult res = OCCreateResource(&(lightResource->handle),
"core.light",
"oc.mi.def",
uri,
OCEntityHandlerCb,
OC_DISCOVERABLE|OC_OBSERVABLE);
OC_LOG_V(INFO, TAG, "Created Light resource with result: %s", getResult(res));
return 0;
}
void DeletePlatformInfo()
{
free (platformInfo.platformID);
free (platformInfo.manufacturerName);
free (platformInfo.manufacturerUrl);
free (platformInfo.modelNumber);
free (platformInfo.dateOfManufacture);
free (platformInfo.platformVersion);
free (platformInfo.operatingSystemVersion);
free (platformInfo.hardwareVersion);
free (platformInfo.firmwareVersion);
free (platformInfo.supportUrl);
free (platformInfo.systemTime);
}
bool DuplicateString(char** targetString, const char* sourceString)
{
if(!sourceString)
{
return false;
}
else
{
*targetString = (char *) malloc(strlen(sourceString) + 1);
if(*targetString)
{
strncpy(*targetString, sourceString, (strlen(sourceString) + 1));
return true;
}
}
return false;
}
OCStackResult SetPlatformInfo(const char* platformID, const char *manufacturerName,
const char *manufacturerUrl, const char *modelNumber, const char *dateOfManufacture,
const char *platformVersion, const char* operatingSystemVersion, const char* hardwareVersion,
const char *firmwareVersion, const char* supportUrl, const char* systemTime)
{
bool success = true;
if(manufacturerName != NULL && (strlen(manufacturerName) > MAX_MANUFACTURER_NAME_LENGTH))
{
return OC_STACK_INVALID_PARAM;
}
if(manufacturerUrl != NULL && (strlen(manufacturerUrl) > MAX_MANUFACTURER_URL_LENGTH))
{
return OC_STACK_INVALID_PARAM;
}
if(!DuplicateString(&platformInfo.platformID, platformID))
{
success = false;
}
if(!DuplicateString(&platformInfo.manufacturerName, manufacturerName))
{
success = false;
}
if(!DuplicateString(&platformInfo.manufacturerUrl, manufacturerUrl))
{
success = false;
}
if(!DuplicateString(&platformInfo.modelNumber, modelNumber))
{
success = false;
}
if(!DuplicateString(&platformInfo.dateOfManufacture, dateOfManufacture))
{
success = false;
}
if(!DuplicateString(&platformInfo.platformVersion, platformVersion))
{
success = false;
}
if(!DuplicateString(&platformInfo.operatingSystemVersion, operatingSystemVersion))
{
success = false;
}
if(!DuplicateString(&platformInfo.hardwareVersion, hardwareVersion))
{
success = false;
}
if(!DuplicateString(&platformInfo.firmwareVersion, firmwareVersion))
{
success = false;
}
if(!DuplicateString(&platformInfo.supportUrl, supportUrl))
{
success = false;
}
if(!DuplicateString(&platformInfo.systemTime, systemTime))
{
success = false;
}
if(success)
{
return OC_STACK_OK;
}
DeletePlatformInfo();
return OC_STACK_ERROR;
}
static void PrintUsage() static void PrintUsage()
{ {
OC_LOG(INFO, TAG, "Usage : ocserver -o <0|1>"); OC_LOG(INFO, TAG, "Usage : ocserver -o <0|1>");
...@@ -897,21 +1038,22 @@ int main(int argc, char* argv[]) ...@@ -897,21 +1038,22 @@ int main(int argc, char* argv[])
OCSetDefaultDeviceEntityHandler(OCDeviceEntityHandlerCb); OCSetDefaultDeviceEntityHandler(OCDeviceEntityHandlerCb);
OCStackResult deviceResult = SetDeviceInfo(contentType, dateOfManufacture, deviceName, OCStackResult platformRegistrationResult =
deviceUUID, firmwareVersion, hostName, manufacturerName, SetPlatformInfo(platformID, manufacturerName, manufacturerUrl, modelNumber,
manufacturerUrl, modelNumber, platformVersion, supportUrl, version); dateOfManufacture, platformVersion, operatingSystemVersion, hardwareVersion,
firmwareVersion, supportUrl, systemTime);
if (deviceResult != OC_STACK_OK) if (platformRegistrationResult != OC_STACK_OK)
{ {
OC_LOG(INFO, TAG, "Device Registration failed!"); OC_LOG(INFO, TAG, "Platform info setting failed locally!");
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
deviceResult = OCSetDeviceInfo(deviceInfo); platformRegistrationResult = OCSetPlatformInfo(platformInfo);
if (deviceResult != OC_STACK_OK) if (platformRegistrationResult != OC_STACK_OK)
{ {
OC_LOG(INFO, TAG, "Device Registration failed!"); OC_LOG(INFO, TAG, "Platform Registration failed!");
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
...@@ -942,7 +1084,7 @@ int main(int argc, char* argv[]) ...@@ -942,7 +1084,7 @@ int main(int argc, char* argv[])
// Break from loop with Ctrl-C // Break from loop with Ctrl-C
OC_LOG(INFO, TAG, "Entering ocserver main loop..."); OC_LOG(INFO, TAG, "Entering ocserver main loop...");
DeleteDeviceInfo(); DeletePlatformInfo();
signal(SIGINT, handleSigInt); signal(SIGINT, handleSigInt);
while (!gQuitFlag) while (!gQuitFlag)
{ {
...@@ -971,148 +1113,4 @@ int main(int argc, char* argv[]) ...@@ -971,148 +1113,4 @@ int main(int argc, char* argv[])
} }
return 0; return 0;
} }
\ No newline at end of file
int createLightResource (char *uri, LightResource *lightResource)
{
if (!uri)
{
OC_LOG(ERROR, TAG, "Resource URI cannot be NULL");
return -1;
}
lightResource->state = false;
lightResource->power= 0;
OCStackResult res = OCCreateResource(&(lightResource->handle),
"core.light",
OC_RSRVD_INTERFACE_DEFAULT,
uri,
OCEntityHandlerCb,
OC_DISCOVERABLE|OC_OBSERVABLE);
OC_LOG_V(INFO, TAG, "Created Light resource with result: %s", getResult(res));
return 0;
}
void DeleteDeviceInfo()
{
free(deviceInfo.contentType);
free(deviceInfo.dateOfManufacture);
free(deviceInfo.deviceName);
free(deviceInfo.deviceUUID);
free(deviceInfo.firmwareVersion);
free(deviceInfo.hostName);
free(deviceInfo.manufacturerName);
free(deviceInfo.manufacturerUrl);
free(deviceInfo.modelNumber);
free(deviceInfo.platformVersion);
free(deviceInfo.supportUrl);
free(deviceInfo.version);
}
bool DuplicateString(char** targetString, const char* sourceString)
{
if(!sourceString)
{
return false;
}
else
{
*targetString = (char *) malloc(strlen(sourceString) + 1);
if(*targetString)
{
strncpy(*targetString, sourceString, (strlen(sourceString) + 1));
return true;
}
}
return false;
}
OCStackResult SetDeviceInfo(const char *contentType, const char *dateOfManufacture,
const char *deviceName, const char *deviceUUID, const char *firmwareVersion,
const char *hostName, const char *manufacturerName, const char *manufacturerUrl,
const char *modelNumber, const char *platformVersion, const char *supportUrl,
const char *version)
{
bool success = true;
if(manufacturerName != NULL && (strlen(manufacturerName) > MAX_MANUFACTURER_NAME_LENGTH))
{
return OC_STACK_INVALID_PARAM;
}
if(manufacturerUrl != NULL && (strlen(manufacturerUrl) > MAX_MANUFACTURER_URL_LENGTH))
{
return OC_STACK_INVALID_PARAM;
}
if(!DuplicateString(&deviceInfo.contentType, contentType))
{
success = false;
}
if(!DuplicateString(&deviceInfo.dateOfManufacture, dateOfManufacture))
{
success = false;
}
if(!DuplicateString(&deviceInfo.deviceName, deviceName))
{
success = false;
}
if(!DuplicateString(&deviceInfo.deviceUUID, deviceUUID))
{
success = false;
}
if(!DuplicateString(&deviceInfo.firmwareVersion, firmwareVersion))
{
success = false;
}
if(!DuplicateString(&deviceInfo.hostName, hostName))
{
success = false;
}
if(!DuplicateString(&deviceInfo.manufacturerName, manufacturerName))
{
success = false;
}
if(!DuplicateString(&deviceInfo.manufacturerUrl, manufacturerUrl))
{
success = false;
}
if(!DuplicateString(&deviceInfo.modelNumber, modelNumber))
{
success = false;
}
if(!DuplicateString(&deviceInfo.platformVersion, platformVersion))
{
success = false;
}
if(!DuplicateString(&deviceInfo.supportUrl, supportUrl))
{
success = false;
}
if(!DuplicateString(&deviceInfo.version, version))
{
success = false;
}
if(success)
{
return OC_STACK_OK;
}
DeleteDeviceInfo();
return OC_STACK_ERROR;
}
...@@ -33,88 +33,46 @@ ...@@ -33,88 +33,46 @@
using namespace OC; using namespace OC;
//Callback after device information is received //Callback after device information is received
void receivedDeviceInfo(const OCRepresentation& rep) void receivedPlatformInfo(const OCRepresentation& rep)
{ {
std::cout << "\nDevice Information received ---->\n"; std::cout << "\nPlatform Information received ---->\n";
std::string value;
std::string contentType; std::string values[22] =
std::string dateOfManufacture; {
std::string deviceName; "pi", "Platform ID ",
std::string deviceUUID; "mnmn", "Manufacturer name ",
std::string firmwareVersion; "mnml", "Manufacturer url ",
std::string hostName; "mnmo", "Manufacturer Model No ",
std::string manufacturerName; "mndt", "Manufactured Date ",
std::string manufacturerUrl; "mnpv", "Manufacturer Platform Version ",
std::string modelNumber; "mnos", "Manufacturer OS version ",
std::string platformVersion; "mnhw", "Manufacturer hardware version ",
std::string supportUrl; "mnfv", "Manufacturer firmware version ",
std::string version; "mnsl", "Manufacturer support url ",
"st", "Manufacturer system time "
if(rep.getValue("ct", contentType)) };
{
std::cout << "Content Type: " << contentType << std::endl;
}
if(rep.getValue("mndt", dateOfManufacture))
{
std::cout << "Date of manufacture: " << dateOfManufacture << std::endl;
}
if(rep.getValue("dn", deviceName))
{
std::cout << "Device Name: " << deviceName << std::endl;
}
if(rep.getValue("di", deviceUUID))
{
std::cout << "Device UUID: " << deviceUUID << std::endl;
}
if(rep.getValue("mnfv", firmwareVersion))
{
std::cout << "Firmware Version: " << firmwareVersion << std::endl;
}
if(rep.getValue("hn", hostName))
{
std::cout << "Host Name: " << hostName << std::endl;
}
if(rep.getValue("mnmn", manufacturerName))
{
std::cout << "Manufacturer Name: " << manufacturerName << std::endl;
}
if(rep.getValue("mnml", manufacturerUrl))
{
std::cout << "Manufacturer Url: " << manufacturerUrl << std::endl;
}
if(rep.getValue("mnmo", modelNumber))
{
std::cout << "Model No. : " << modelNumber << std::endl;
}
if(rep.getValue("mnpv", platformVersion))
{
std::cout << "Platform Version: " << platformVersion << std::endl;
}
if(rep.getValue("mnsl", supportUrl)) for (int i = 0; i < 22; i += 2)
{ {
std::cout << "Support URL: " << supportUrl << std::endl; if(rep.getValue(values[i], value))
{
std::cout << values[i + 1] << " : "<< value << std::endl;
}
} }
}
if(rep.getValue("icv", version)) void receivedDeviceInfo(const OCRepresentation& rep)
{ {
std::cout << "Version: " << version << std::endl; std::cout << "Implement me !" << std::endl;
}
} }
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
std::ostringstream requestURI; std::ostringstream platformDiscoveryRequest;
std::string deviceDiscoveryURI = "/oc/core/d"; std::ostringstream deviceDiscoveryRequest;
std::string platformDiscoveryURI = "/oic/p";
std::string deviceDiscoveryURI = "/oic/d";
OCConnectivityType connectivityType = OC_IPV4; OCConnectivityType connectivityType = OC_IPV4;