std::shared_ptr<OCResource> curResource;
+static int TEST_CASE = 0;
+
+/**
+ * List of methods that can be inititated from the client
+ */
+typedef enum {
+ TEST_UNICAST_PRESENCE_NORMAL = 1,
+ TEST_UNICAST_PRESENCE_WITH_FILTER,
+ TEST_MULTICAST_PRESENCE_NORMAL,
+ TEST_MULTICAST_PRESENCE_WITH_FILTER,
+ MAX_TESTS
+} CLIENT_TEST;
+
+void printUsage()
+{
+ std::cout << "Usage : presenceclient -t <1|2>" << std::endl;
+ std::cout << "-t 1 : Discover Resources and Initiate Unicast Presence" << std::endl;
+ std::cout << "-t 2 : Discover Resources and Initiate Unicast Presence with Filter"
+ << std::endl;
+ std::cout << "-t 3 : Discover Resources and Initiate Multicast Presence" << std::endl;
+ std::cout << "-t 4 : Discover Resources and Initiate Multicast Presence with Filter"
+ << std::endl;
+}
+
// Callback to presence
void presenceHandler(OCStackResult result, const unsigned int nonce)
{
{
curResource = resource;
OCPlatform::OCPresenceHandle presenceHandle;
- OCPlatform::subscribePresence(presenceHandle, hostAddress, &presenceHandler);
- std::cout<< "subscribing for unicast presence... " <<std::endl;
+ switch(TEST_CASE)
+ {
+ case TEST_UNICAST_PRESENCE_NORMAL:
+ OCPlatform::subscribePresence(presenceHandle, hostAddress,
+ &presenceHandler);
+ break;
+ case TEST_UNICAST_PRESENCE_WITH_FILTER:
+ OCPlatform::subscribePresence(presenceHandle, hostAddress, "core.light",
+ &presenceHandler);
+ break;
+ case TEST_MULTICAST_PRESENCE_NORMAL:
+ OCPlatform::subscribePresence(presenceHandle, OC_MULTICAST_IP, presenceHandler);
+ break;
+ case TEST_MULTICAST_PRESENCE_WITH_FILTER:
+ OCPlatform::subscribePresence(presenceHandle, OC_MULTICAST_IP, "core.light",
+ &presenceHandler);
+ break;
+ default:
+ printUsage();
+ break;
+ }
}
}
else
}
}
-void PrintUsage()
-{
- std::cout << std::endl;
- std::cout << "Usage : presenceclient <isMulticastAddress>\n";
- std::cout << " 0 - unicast subcribe presence\n";
- std::cout << " 1 - multicast subscribe presence\n\n";
-}
-
-// 0 - unicast subcribe presence
-// 1 - multicast subscribe presence
-int isMulticastAddress = 0;
+int main(int argc, char* argv[]) {
+ int opt;
-int main(int argc, char* argv[1])
-{
- PrintUsage();
-
- if (argc == 1)
+ while ((opt = getopt(argc, argv, "t:")) != -1)
{
- isMulticastAddress = 0;
- }
- else if (argc == 2)
- {
- int value = atoi(argv[1]);
- if (value == 1)
- isMulticastAddress = 1;
- else
- isMulticastAddress = 0;
+ switch(opt)
+ {
+ case 't':
+ TEST_CASE = atoi(optarg);
+ break;
+ default:
+ printUsage();
+ return -1;
+ }
}
- else
+ if(TEST_CASE >= MAX_TESTS || TEST_CASE <= 0)
{
+ printUsage();
return -1;
}
OC::QualityOfService::LowQos
};
+ OCPlatform::Configure(cfg);
+
try
{
- OCPlatform::Configure(cfg);
-
- if(isMulticastAddress)
- {
- OCPlatform::OCPresenceHandle presenceHandle;
- OCPlatform::subscribePresence(presenceHandle, OC_MULTICAST_IP, presenceHandler);
- std::cout<< "subscribing for multicast presence... " <<std::endl;
- }
- else
- {
- // Find all resources
- OCPlatform::findResource("", "coap://224.0.1.187/oc/core", &foundResource);
- std::cout<< "Finding Resource... " <<std::endl;
- }
-
+ std::cout << "Created Platform..."<<std::endl;
+ // Find all resources
+ OCPlatform::findResource("", "coap://224.0.1.187/oc/core", &foundResource);
+ std::cout<< "Finding Resource... " <<std::endl;
while(true)
{
// some operations
const std::string& uri, const HeaderOptions& headerOptions, QualityOfService QoS)=0;
virtual OCStackResult SubscribePresence(OCDoHandle* handle, const std::string& host,
- SubscribeCallback& presenceHandler)=0;
+ const std::string& resourceType, SubscribeCallback& presenceHandler)=0;
virtual OCStackResult UnsubscribePresence(OCDoHandle handle) =0;
const std::string& uri, const HeaderOptions& headerOptions, QualityOfService QoS);
virtual OCStackResult SubscribePresence(OCDoHandle* handle, const std::string& host,
- SubscribeCallback& presenceHandler);
+ const std::string& resourceType, SubscribeCallback& presenceHandler);
virtual OCStackResult UnsubscribePresence(OCDoHandle handle);
// Note: this should never be called by anyone but the handler for the listen command.
* request. It can be used to unsubscribe from these events in the future.
* It will be set upon successful return of this method.
* @param host - The IP address/addressable name of the server to subscribe to.
+ * @param resourceType - a resource type specified as a filter for subscription callbacks.
* @param presenceHandler - callback function that will receive notifications/subscription
* events
*
*/
OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
SubscribeCallback presenceHandler);
+ OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
+ const std::string& resourceType, SubscribeCallback presenceHandler);
/**
* unsubscribes from a previously subscribed server's presence events. Note that
* request. It can be used to unsubscribe from these events in the future.
* It will be set upon successful return of this method.
* @param host - The IP address/addressable name of the server to subscribe to.
+ * @param resourceType - a resource type specified as a filter for subscription callbacks.
* @param presenceHandler - callback function that will receive notifications/subscription
* events
*
*/
OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
SubscribeCallback presenceHandler);
+ OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
+ const std::string& resourceType, SubscribeCallback presenceHandler);
/**
* unsubscribes from a previously subscribed server's presence events. Note that
}
virtual OCStackResult SubscribePresence(OCDoHandle* handle, const std::string& host,
- SubscribeCallback& presenceHandler){return OC_STACK_NOTIMPL;}
+ const std::string& resourceType, SubscribeCallback& presenceHandler)
+ {return OC_STACK_NOTIMPL;}
virtual OCStackResult UnsubscribePresence(OCDoHandle handle){return OC_STACK_NOTIMPL;}
}
OCStackResult InProcClientWrapper::SubscribePresence(OCDoHandle* handle,
- const std::string& host, SubscribeCallback& presenceHandler)
+ const std::string& host, const std::string& resourceType,
+ SubscribeCallback& presenceHandler)
{
OCCallbackData cbdata = {0};
auto cLock = m_csdkLock.lock();
std::ostringstream os;
-
os << host << "/oc/presence";
+ if(!resourceType.empty())
+ {
+ os << "?rt=" << resourceType;
+ }
+
if(!cLock)
return OC_STACK_ERROR;
presenceHandler);
}
+ OCStackResult subscribePresence(OCPresenceHandle& presenceHandle,
+ const std::string& host,
+ const std::string& resourceType,
+ SubscribeCallback presenceHandler)
+ {
+ return OCPlatform_impl::Instance().subscribePresence(presenceHandle, host,
+ resourceType, presenceHandler);
+ }
+
OCStackResult unsubscribePresence(OCPresenceHandle presenceHandle)
{
return OCPlatform_impl::Instance().unsubscribePresence(presenceHandle);
const std::string& host,
SubscribeCallback presenceHandler)
{
+ return subscribePresence(presenceHandle, host, "", presenceHandler);
+ }
+
+ OCStackResult OCPlatform_impl::subscribePresence(OCPresenceHandle& presenceHandle,
+ const std::string& host,
+ const std::string& resourceType,
+ SubscribeCallback presenceHandler)
+ {
return checked_guard(m_client, &IClientWrapper::SubscribePresence,
- &presenceHandle, host, presenceHandler);
+ &presenceHandle, host, resourceType, presenceHandler);
}
OCStackResult OCPlatform_impl::unsubscribePresence(OCPresenceHandle presenceHandle)