Cleaned up the unused-parameter warning
authorGeorge Nash <george.nash@intel.com>
Mon, 11 Apr 2016 17:09:37 +0000 (10:09 -0700)
committerJon A. Cruz <jon@joncruz.org>
Thu, 14 Apr 2016 06:53:36 +0000 (06:53 +0000)
unused parameters are typically the result of 3 things
- they are from a call back and are not needed for that instance of
  the call back
- introduced to maintain backward compatability for older APIs
- variables only used in debug mode for debuging reasons

Many projects that try to build without warnings cast the unused
paramenter to a void type to prevent the warning.  The cast can
be added to the project using a #define.

The OC_UNUSED macro has been added to the octypes header file
to be used when in one of the three given scenarios.

In addition the macro has been used to prevent the unused-parameter
warning for several files.

Change-Id: Ib10967df4a135f0863aebbca41479d8e62d1a27b
Signed-off-by: George Nash <george.nash@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/7757
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jon A. Cruz <jon@joncruz.org>
resource/csdk/stack/include/octypes.h
service/easy-setup/mediator/csdk/unittests/MediatorCSDKTest.cpp
service/easy-setup/mediator/richsdk/src/RemoteEnrolleeResource.cpp
service/easy-setup/sampleapp/mediator/linux/richsdk_sample/mediator_cpp.cpp
service/resource-encapsulation/src/resourceBroker/src/DevicePresence.cpp

index e1ee26c..a4b0b48 100644 (file)
@@ -333,6 +333,18 @@ extern "C" {
 #define OC_RSRVD_RESOURCE_TYPE_RDPUBLISH "oic.wk.rdPub"
 
 /**
+ * Mark a parameter as unused. Used to prevent unused variable compiler warnings.
+ * Used in three cases:
+ * 1. in callbacks when one of the parameters are unused
+ * 2. when due to code changes a functions parameter is no longer
+ *    used but must be left in place for backward compatibility
+ *    reasons.
+ * 3. a variable is only used in the debug build variant and would
+ *    give a build warning in release mode.
+ */
+#define OC_UNUSED(x) (void)(x)
+
+/**
  * These enums (OCTransportAdapter and OCTransportFlags) must
  * be kept synchronized with OCConnectivityType (below) as well as
  * CATransportAdapter and CATransportFlags (in CACommon.h).
index 65606d8..057a392 100644 (file)
@@ -53,7 +53,9 @@ class MediatorCSDKTest: public TestWithMock
 };
 
 //callbacks
-void OCProvisioningStatusCallback(EasySetupInfo  *easySetupInfo) {}
+void OCProvisioningStatusCallback(EasySetupInfo  *easySetupInfo) {
+    OC_UNUSED(easySetupInfo);
+}
 
 /* Test cases for prov_adapter*/
 
index b401b27..e3a91d9 100755 (executable)
@@ -51,6 +51,7 @@ namespace OIC
                 const HeaderOptions& /*headerOptions*/, const OCRepresentation& rep,
                 const int eCode)
         {
+            OC_UNUSED(rep);
             OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "checkProvInformationCb : %s, eCode = %d",
                     rep.getUri().c_str(),
                     eCode);
index 8e3c6c6..5011403 100755 (executable)
@@ -74,6 +74,7 @@ int processUserInput(int min, int max)
 
 void easySetupStatusCallback (std::shared_ptr< EasySetupStatus > easySetupStatus)
 {
+    OC_UNUSED(easySetupStatus);
     OIC_LOG_V(DEBUG, ES_SAMPLE_APP_TAG, "easySetupStatusCallback status is Status = %d",
             easySetupStatus->getEasySetupState());
 
index 8d7391d..7ebdf3f 100644 (file)
@@ -125,6 +125,9 @@ namespace OIC
         void DevicePresence::subscribeCB(OCStackResult ret,
                 const unsigned int seq, const std::string & hostAddress)
         {
+            OC_UNUSED(seq);
+            OC_UNUSED(hostAddress);
+
             OIC_LOG_V(DEBUG, BROKER_TAG, "subscribeCB()");
             OIC_LOG_V(DEBUG, BROKER_TAG, "Received presence CB from: %s",hostAddress.c_str());
             OIC_LOG_V(DEBUG, BROKER_TAG, "In subscribeCB: %d",ret);