if(threadRun==true)
{
- messageCallback(env,obj,"already execute OICCoordinatorStart");
+ messageCallback(env,obj,"OICCoordinatorStart already executed");
result = (jint)HOSTING_THREAD_ERROR;
return result;
}
}
else
{
- messageCallback(env,obj,"The thread may be not running.");
+ messageCallback(env,obj,"OICCoordinatorStop already terminated");
result = (jint)HOSTING_THREAD_ERROR;
return result;
}
private final int RESOURCEHOSTING_DO_NOT_THREADRUNNING = -2;
private String TAG = "ResourceHosting";
- private OcResourceHandle mResourceHandle;
- private String mIpAddress;
private TextView mLogTextView;
private String mLog = "";
/**
protected void onStart()
{
super.onStart();
- initOICStack();
}
/**
protected void onStop()
{
super.onStop();
- int result;
- result = ResourceHostingTerminate();
- Log.d(TAG, "ResourceHostingTerminate : "+ result);
}
protected void onResume()
protected void onRestart()
{
super.onRestart();
- initOICStack();
}
/**
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);
}
/**
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;
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
public void onCreate(Bundle savedInstanceState)
{
+ sampleProviderObj = this;
super.onCreate(savedInstanceState);
setContentView(R.layout.sampleprovider_layout);
registerReceiver(mMessageReceiver, new IntentFilter(
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()
}
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
import android.content.Context;
import android.content.Intent;
+import android.os.Message;
import android.util.Log;
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()
{
try
{
- logMessage(TAG + "Request");
+ logMessage(TAG + requestType + "Request");
OcResourceResponse ocResourceResponse = new OcResourceResponse();
ocResourceResponse.setRequestHandle(request
.getRequestHandle());
{
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)
{
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;
}
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)
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");
}
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");
}