|
@@ -131,7 +131,7 @@ public class BridgeService extends IntentService {
|
|
|
if (IBridgeService.class.getName().equals(intent.getAction())) {
|
|
|
return rBinder; // return Remote Binder
|
|
|
} else if (ILightControlService.class.getName().equals(intent.getAction())) {
|
|
|
- return lightBinder; // return Remote Binder
|
|
|
+ return null ;//lightBinder; // return Remote Binder
|
|
|
}
|
|
|
return lBinder; // return Local Binder
|
|
|
}
|
|
@@ -304,7 +304,7 @@ public class BridgeService extends IntentService {
|
|
|
private LightControlServiceConnection lightConn = new LightControlServiceConnection();
|
|
|
public void bindLightControlService() {
|
|
|
|
|
|
- Log.d(TAG, "SecheduledTaskInit : bindLightControlService() called.");
|
|
|
+ Log.d(TAG, "ScheduledTaskInit : bindLightControlService() called.");
|
|
|
|
|
|
// Light Control Service Remote Bind
|
|
|
Intent lIntent = new Intent();
|
|
@@ -341,26 +341,23 @@ public class BridgeService extends IntentService {
|
|
|
public void onServiceConnected(ComponentName name, IBinder service) {
|
|
|
|
|
|
Log.d(TAG, "onServiceConnected ComponentName=" + name + ", IBinder=" + service.toString());
|
|
|
- if (service instanceof ILightControlService.Stub) {
|
|
|
+ try {
|
|
|
+ lightControlBinder = ILightControlService.Stub.asInterface(service);
|
|
|
+ lightControlBinder.registerLightControlServiceCallback(lightCallback);
|
|
|
|
|
|
- try {
|
|
|
- lightControlBinder = ILightControlService.Stub.asInterface(service);
|
|
|
- lightControlBinder.registerLightControlServiceCallback(lightCallback);
|
|
|
-
|
|
|
- // Discover All Light Control Devices
|
|
|
- discoverAllLightControlDevices();
|
|
|
-
|
|
|
- } catch (RemoteException ex) {
|
|
|
- Log.e(TAG, "Register Callback", ex);
|
|
|
- // In this case the service has crashed before we could even
|
|
|
- // do anything with it; we can count on soon being
|
|
|
- // disconnected (and then reconnected if it can be restarted)
|
|
|
- // so there is no need to do anything here.
|
|
|
- }
|
|
|
+ // Discover All Light Control Devices
|
|
|
+ discoverAllLightControlDevices();
|
|
|
|
|
|
- msg( "Light Control Remote Service Connected");
|
|
|
- printLine();
|
|
|
+ } catch (RemoteException ex) {
|
|
|
+ Log.e(TAG, "Register Callback", ex);
|
|
|
+ // In this case the service has crashed before we could even
|
|
|
+ // do anything with it; we can count on soon being
|
|
|
+ // disconnected (and then reconnected if it can be restarted)
|
|
|
+ // so there is no need to do anything here.
|
|
|
}
|
|
|
+
|
|
|
+ msg( "Light Control Remote Service Connected");
|
|
|
+ printLine();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -417,7 +414,7 @@ public class BridgeService extends IntentService {
|
|
|
/**
|
|
|
* The ILightControlService is defined through IDL
|
|
|
*/
|
|
|
- private final ILightControlServiceImpl lightBinder = new ILightControlServiceImpl() ;
|
|
|
+ /*private final ILightControlServiceImpl lightBinder = new ILightControlServiceImpl() ;
|
|
|
class ILightControlServiceImpl extends ILightControlService.Stub {
|
|
|
|
|
|
final RemoteCallbackList<ILightControlServiceCallback> callbacks
|
|
@@ -531,7 +528,7 @@ public class BridgeService extends IntentService {
|
|
|
}
|
|
|
callbacks.finishBroadcast();
|
|
|
}
|
|
|
- };
|
|
|
+ };*/
|
|
|
|
|
|
public String doGetLightControlResource(long device_index, String device_id, String resource_uri) {
|
|
|
try {
|
|
@@ -539,7 +536,8 @@ public class BridgeService extends IntentService {
|
|
|
String device_sn = OCUuidUtil.uuidToString(piid); // same with vod_id(Virtual Device Id) of VirtualOCFDevice
|
|
|
|
|
|
// doGetProperties with Light Control Service
|
|
|
- String properties = lightBinder.doGetResourceProperties(device_sn, resource_uri);
|
|
|
+ if(lightControlBinder==null) return null ;
|
|
|
+ String properties = lightControlBinder.doGetResourceProperties(device_sn, resource_uri);
|
|
|
return properties ;
|
|
|
} catch (RemoteException e) {
|
|
|
Log.e(TAG, "Light Control Service Remote Error : ", e);
|
|
@@ -549,8 +547,10 @@ public class BridgeService extends IntentService {
|
|
|
|
|
|
public void discoverAllLightControlDevices() {
|
|
|
|
|
|
- Log.d(TAG, "SecheduledTaskInit : doRetrieveLightControlAllDevices() called.");
|
|
|
try {
|
|
|
+ if(lightControlBinder==null) return ;
|
|
|
+
|
|
|
+ Log.d(TAG, "ScheduledTaskInit : doRetrieveLightControlAllDevices() called.");
|
|
|
String devices = lightControlBinder.retrieveAllDevices();
|
|
|
Log.d(TAG, "Light Control retrieveAllDevices() : "+ devices);
|
|
|
if(devices != null) {
|
|
@@ -646,7 +646,7 @@ public class BridgeService extends IntentService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- } catch (RemoteException | JSONException ex) {
|
|
|
+ } catch (Exception ex) {
|
|
|
Log.e(TAG, "Register Callback", ex);
|
|
|
// In this case the service has crashed before we could even
|
|
|
// do anything with it; we can count on soon being
|
|
@@ -657,8 +657,9 @@ public class BridgeService extends IntentService {
|
|
|
|
|
|
public void doGetLightControlResources() {
|
|
|
|
|
|
- Log.d(TAG, "SecheduledTaskInit : doGetLightControlResources() called.");
|
|
|
- if(bridgeServer != null && lightBinder != null) {
|
|
|
+ if(bridgeServer != null && lightControlBinder != null) {
|
|
|
+ Log.d(TAG, "ScheduledTaskInit : doGetLightControlResources() called.");
|
|
|
+
|
|
|
ArrayList<VirtualOCFDevice> vods = bridgeServer.getVirtualOCFDeviceList();
|
|
|
for (VirtualOCFDevice vod : vods) {
|
|
|
if (vod.getEcoName().equals(LightControlServiceConnection.ECO_NAME) && vod.isDiscovered()
|
|
@@ -668,7 +669,7 @@ public class BridgeService extends IntentService {
|
|
|
try {
|
|
|
// doGetProperties with Light Control Service
|
|
|
String prev_props = bridgeServer.getVirtualOCFDeviceProperties(device_sn, resource.getResourceUri());
|
|
|
- String properies = lightBinder.doGetResourceProperties(device_sn, resource.getResourceUri());
|
|
|
+ String properies = lightControlBinder.doGetResourceProperties(device_sn, resource.getResourceUri());
|
|
|
bridgeServer.addOrUpdateVirtualOCFDeviceProperties(device_sn, resource.getResourceUri(), properies);
|
|
|
|
|
|
/*Log.d(TAG,"(1) prev_props : " +prev_props + ", cur_props : " +properies );
|
|
@@ -696,8 +697,10 @@ public class BridgeService extends IntentService {
|
|
|
OCUuid piid = OCCoreRes.getDeviceInfo(device_index).getPiid();
|
|
|
String device_sn = OCUuidUtil.uuidToString(piid); // same with vod_id(Virtual Device Id) of VirtualOCFDevice
|
|
|
|
|
|
- Log.d(TAG, "doPostLightControlResource() called.");
|
|
|
- lightBinder.doPostResourceProperties(device_sn, resource_uri, prop_data);
|
|
|
+ if(lightControlBinder!=null) {
|
|
|
+ Log.d(TAG, "doPostLightControlResource() called.");
|
|
|
+ lightControlBinder.doPostResourceProperties(device_sn, resource_uri, prop_data);
|
|
|
+ }
|
|
|
|
|
|
} catch (RemoteException e) {
|
|
|
Log.e(TAG, "Light Control Service Remote Error : ", e);
|
|
@@ -733,7 +736,7 @@ public class BridgeService extends IntentService {
|
|
|
rBinder.broadcastResultToClients(msg.arg1, (String)msg.obj);
|
|
|
} break ;
|
|
|
case MSG_LIGHT_RESULT: {
|
|
|
- lightBinder.broadcastResultToClients(msg.arg1, (String)msg.obj);
|
|
|
+ //lightBinder.broadcastResultToClients(msg.arg1, (String)msg.obj);
|
|
|
} break ;
|
|
|
default:
|
|
|
super.handleMessage(msg);
|
|
@@ -883,21 +886,22 @@ public class BridgeService extends IntentService {
|
|
|
* executorService.schedule(Classname::someTask, delayInSeconds, TimeUnit.SECONDS); // once after a delay
|
|
|
* executorService.scheduleAtFixedRate(Classname::someTask, 0, delayInSeconds, TimeUnit.SECONDS); // at fixed time interval
|
|
|
*/
|
|
|
- if(executorLightControl != null && executorLightControl.isShutdown() == false ) { executorLightControl.shutdown();}
|
|
|
+ if(executorLightControl != null && executorLightControl.isShutdown() == false ) {
|
|
|
+ executorLightControl.shutdown();
|
|
|
+ }
|
|
|
executorLightControl = Executors.newSingleThreadScheduledExecutor();
|
|
|
executorLightControl.scheduleAtFixedRate(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
// Getting Properites of Light Control Service for resource monitoring
|
|
|
- Log.d(TAG, "LightControl ScheduledTask per 180sec was called.");
|
|
|
+ Log.d(TAG, "LightControl ScheduledTask per 30sec was called.");
|
|
|
if(lightControlBinder==null) {
|
|
|
bindLightControlService();
|
|
|
}
|
|
|
discoverAllLightControlDevices();
|
|
|
doGetLightControlResources();
|
|
|
}
|
|
|
- }, 30, 180, TimeUnit.SECONDS); // 180sec interval after 30sec delay
|
|
|
-
|
|
|
+ }, 30, 30, TimeUnit.SECONDS); // 180sec interval after 30sec delay
|
|
|
}
|
|
|
|
|
|
public void stopScheduledTaskForLightControl() {
|