Fix for the Jira issue IOT- 531 and review comment fixes
authorarya.kumar <arya.kumar@samsung.com>
Fri, 5 Jun 2015 11:19:27 +0000 (16:49 +0530)
committerUze Choi <uzchoi@samsung.com>
Mon, 8 Jun 2015 01:34:25 +0000 (01:34 +0000)
Change-Id: I598491a857e95af37b03f44eac200d775728e6c9
Signed-off-by: arya.kumar <arya.kumar@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1141
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Hun-je Yeon <hunje.yeon@samsung.com>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/notification-manager/NotificationManager/src/resourceCoordinator_JNI.cpp
service/notification-manager/SampleApp/android/ResourceHostingSampleApp/src/com/example/resourcehostingsampleapp/ResourceHosting.java
service/notification-manager/SampleApp/android/SampleProviderApp/src/com/example/sample/provider/SampleProvider.java
service/notification-manager/SampleApp/android/SampleProviderApp/src/com/example/sample/provider/TemperatureResource.java
service/notification-manager/SampleApp/linux/notificationManager/main.c
service/notification-manager/SampleApp/tizen/NMSampleApp/src/main.cpp

index 7f30a1c..4382ea8 100644 (file)
@@ -64,7 +64,7 @@ JNIEXPORT jint JNICALL Java_com_example_resourcehostingsampleapp_ResourceHosting
     if(threadRun==true)
     {
 
-        messageCallback(env,obj,"already execute OICCoordinatorStart");
+        messageCallback(env,obj,"OICCoordinatorStart already executed");
         result = (jint)HOSTING_THREAD_ERROR;
         return result;
     }
@@ -95,7 +95,7 @@ JNIEXPORT jint JNICALL Java_com_example_resourcehostingsampleapp_ResourceHosting
     }
     else
     {
-            messageCallback(env,obj,"The thread may be not running.");
+            messageCallback(env,obj,"OICCoordinatorStop already terminated");
             result = (jint)HOSTING_THREAD_ERROR;
             return result;
     }
index 53576c2..796f771 100644 (file)
@@ -54,8 +54,6 @@ public class ResourceHosting extends Activity implements OnClickListener
         private final int RESOURCEHOSTING_DO_NOT_THREADRUNNING = -2;
 
         private String TAG = "ResourceHosting";
-        private OcResourceHandle mResourceHandle;
-        private String  mIpAddress;
         private TextView mLogTextView;
         private String mLog = "";
         /**
@@ -91,7 +89,6 @@ public class ResourceHosting extends Activity implements OnClickListener
         protected void onStart()
         {
             super.onStart();
-            initOICStack();
         }
 
         /**
@@ -103,9 +100,6 @@ public class ResourceHosting extends Activity implements OnClickListener
         protected void onStop()
         {
             super.onStop();
-            int result;
-            result = ResourceHostingTerminate();
-            Log.d(TAG, "ResourceHostingTerminate : "+ result);
         }
 
         protected void onResume()
@@ -122,7 +116,6 @@ public class ResourceHosting extends Activity implements OnClickListener
         protected void onRestart()
         {
             super.onRestart();
-            initOICStack();
         }
 
         /**
@@ -132,56 +125,9 @@ public class ResourceHosting extends Activity implements OnClickListener
         protected void onDestroy()
         {
             super.onDestroy();
-        }
-
-        /**
-         * get IpAddress and execute resourceHostingInit() method.
-         * @see Class   class : com_example_resourcehostingsampleapp_ResourceHosting</br>
-         * @see Method  method : initOICStack</br>
-         */
-        private void initOICStack()
-        {
-            try
-            {
-                mIpAddress = getIpAddress();
-                int result;
-                result = ResourceHostingInit(mIpAddress);
-                Log.d(TAG, "ResourceHostingInit : " + result);
-            }
-            catch (Exception e)
-            {
-                e.printStackTrace();
-            }
-        }
-
-        /**
-         * @see Class   class :  com_example_resourcehostingsampleapp_ResourceHosting</br>
-         * @see Method  method :  getIpAddress</br>
-         */
-        private String getIpAddress()
-        {
-            try
-            {
-                for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
-                     en.hasMoreElements();)
-                {
-                    NetworkInterface intf = (NetworkInterface) en.nextElement();
-                    for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();)
-                    {
-                        InetAddress inetAddress = (InetAddress) enumIpAddr.nextElement();
-                        if (!inetAddress.isLoopbackAddress())
-                        {
-                            if (inetAddress instanceof Inet4Address)
-                                return inetAddress.getHostAddress().toString();
-                        }
-                    }
-                }
-            }
-            catch (SocketException e)
-            {
-                e.printStackTrace();
-            }
-            return null;
+            int result;
+            result = OICCoordinatorStop();
+            Log.d(TAG, "OICCoordinatorStop() : "+ result);
         }
 
         /**
index 26bd9b5..8ed682a 100644 (file)
@@ -32,6 +32,7 @@ import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.os.Bundle;
+import android.os.Handler;
 import android.os.Message;
 import android.support.v4.content.LocalBroadcastManager;
 import android.util.Log;
@@ -54,6 +55,12 @@ public class SampleProvider extends Activity implements OnClickListener,
         private boolean isExecutePresence;
         private ScrollView sv_sclLog;
         private MessageReceiver mMessageReceiver = new MessageReceiver();
+        private Handler mHandler;
+        private static String message;
+        private static SampleProvider  sampleProviderObj;
+        private String temp;
+        private String hum;
+
         /*
          * To initialize UI Function Setting
          * To execute initOICStack for running find resource
@@ -62,6 +69,7 @@ public class SampleProvider extends Activity implements OnClickListener,
         public void onCreate(Bundle savedInstanceState)
         {
 
+            sampleProviderObj = this;
             super.onCreate(savedInstanceState);
             setContentView(R.layout.sampleprovider_layout);
             registerReceiver(mMessageReceiver, new IntentFilter(
@@ -80,6 +88,18 @@ public class SampleProvider extends Activity implements OnClickListener,
             findViewById(R.id.btnLogClear).setOnClickListener(this);
 
             isExecutePresence = false;
+            mHandler = new Handler() {
+                @Override
+                public void handleMessage(Message msg) {
+                    switch (msg.what) {
+                        case 0:
+                            String[] tempHum = message.split(":");
+                            mTempValue.setText(tempHum[0]);
+                            mHumValue.setText(tempHum[1]);
+                    }
+                }
+            };
+            setmHandler(mHandler);
         }
 
         private void initOICStack()
@@ -268,4 +288,20 @@ public class SampleProvider extends Activity implements OnClickListener,
             }
             return super.onKeyDown(keyCode, event);
         }
+
+        public Handler getmHandler() {
+            return mHandler;
+        }
+
+        public void setmHandler(Handler mHandler) {
+            this.mHandler = mHandler;
+        }
+
+        public static SampleProvider getSampleProviderObject() {
+            return sampleProviderObj;
+        }
+
+        public static void setmessage(String msg) {
+            message = msg;
+        }
 }
\ No newline at end of file
index 98f6f47..2cae1e9 100644 (file)
@@ -18,6 +18,7 @@ import org.iotivity.base.ResourceProperty;
 
 import android.content.Context;
 import android.content.Intent;
+import android.os.Message;
 import android.util.Log;
 
 public class TemperatureResource implements IMessageLogger
@@ -125,8 +126,16 @@ public class TemperatureResource implements IMessageLogger
         {
             mtemp = rep.getValueInt(StringConstants.TEMPERATURE);
             mhumidity = rep.getValueInt(StringConstants.HUMIDITY);
-            logMessage(TAG + "temperature : " + mtemp + "humidity : " + mhumidity);
+            logMessage(TAG + "PUT Request" +"temperature : " + mtemp + "humidity : " + mhumidity);
+             notifyObserver();
             // " Power: " + mPower);
+             String message = mtemp+":"+mhumidity; 
+             Message msg = Message.obtain();
+             msg.what = 0;
+             SampleProvider mainActivityObj = SampleProvider.getSampleProviderObject();
+             SampleProvider.setmessage(message);
+             mainActivityObj.getmHandler().sendMessage(msg);
+
         }
 
         protected OcRepresentation get()
@@ -156,7 +165,7 @@ public class TemperatureResource implements IMessageLogger
                 {
                     try
                     {
-                        logMessage(TAG + "Request");
+                        logMessage(TAG + requestType + "Request");
                         OcResourceResponse ocResourceResponse = new OcResourceResponse();
                         ocResourceResponse.setRequestHandle(request
                                                             .getRequestHandle());
index 830db3a..5814107 100644 (file)
@@ -35,18 +35,14 @@ int main()
 {
     printf("OCResourceHosting is starting...\n");
 
-    if (OCInit((char *) NULL, 0, OC_CLIENT_SERVER) != OC_STACK_OK)
-    {
-        printf("OCStack init error\n");
-        return 0;
-    }
-
     if (OICStartCoordinate() != OC_STACK_OK)
     {
-        printf("OIC coordinate start fail\n");
+        printf("OICStartCoordinate fail\n");
         return 0;
     }
 
+    printf("OCResourceHosting Started Successfully \n");
+
     signal(SIGINT, handleSigInt);
     while (!g_quitFlag)
     {
@@ -62,20 +58,14 @@ int main()
 
     if (OICStopCoordinate() != OC_STACK_OK)
     {
-        printf("OIC coordinate stop error\n");
+        printf("OICStopCoordinate error\n");
     }
     else
     {
-        printf("OIC coordinate stop success\n");
+        printf("OICStopCoordinate success\n");
     }
 
     printf("Exiting occlient main loop...\n");
-
-    if (OCStop() != OC_STACK_OK)
-    {
-        printf("OCStack stop error\n");
-    }
-
     return 0;
 
 }
index 8ec9645..227772b 100644 (file)
@@ -46,16 +46,15 @@ static void start_hosting(int seconds)
     logMessage = logMessage + "Interface Name : " + reinterpret_cast<char *>(interfaceName) + "<br>";
     printLog(DLOG_INFO, logMessage);
 
-    if (OCInit((char *) NULL, 0, OC_CLIENT_SERVER) != OC_STACK_OK)
+    if (OICStartCoordinate() != OC_STACK_OK)
     {
-        logMessage = "OCStack init error <br>";
+        logMessage = "OICStartCoordinate FAILED <br>";
         printLog(DLOG_ERROR, logMessage);
         return;
     }
 
-    OICStartCoordinate();
     g_quitFlag = 0;
-    logMessage = "OICStartCoordinate done successfully";
+    logMessage = "OICStartCoordinate done successfully <br>";
     printLog(DLOG_INFO, logMessage);
 
     while (!g_quitFlag)
@@ -70,15 +69,13 @@ static void start_hosting(int seconds)
         sleep(seconds);
     }
 
-    OICStopCoordinate();
-    logMessage = "OICStopCoordinate done successfully <br>";
-    printLog(DLOG_INFO, logMessage);
-
-    if (OCStop() != OC_STACK_OK)
+    if (OICStopCoordinate() != OC_STACK_OK)
     {
-        logMessage = "OCStack stop error <br>";
+        logMessage = "OICStopCoordinate FAILED <br>";
         printLog(DLOG_ERROR, logMessage);
     }
+    logMessage = "OICStopCoordinate done successfully <br>";
+    printLog(DLOG_INFO, logMessage);
     LOGI("start EXIT");
 }
 
@@ -88,7 +85,15 @@ void stop_hosting()
     string logMessage = "Terminating Resource Hosting <br>";
     printLog(DLOG_INFO, logMessage);
 
-    g_quitFlag = 1;
+    if(!g_quitFlag)
+    {
+       g_quitFlag = 1;
+    }
+    else
+    {
+       string logMessage = "Resource Hosting already terminated <br>";
+       printLog(DLOG_INFO, logMessage);
+    }
     LOGI("stop_hosting EXIT");
 }