Back to project page Android-NetPowerctrl-Shared.
The source code is released under:
Copyright (c) 2014, David Gr?ff All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: *...
If you think the Android project Android-NetPowerctrl-Shared listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package oly.netpowerctrl.plugin; /* w ww . jav a 2 s.com*/ import android.os.RemoteException; import android.support.annotation.NonNull; import oly.netpowerctrl.device_base.device.Device; import oly.netpowerctrl.device_base.device.DeviceConnection; import oly.netpowerctrl.device_base.device.DevicePort; import oly.netpowerctrl.plugins.INetPwrCtrlPlugin; import oly.netpowerctrl.plugins.INetPwrCtrlPluginResult; /** * IPC Binding to the host software */ public class App2PluginCommunication extends INetPwrCtrlPlugin.Stub { public INetPwrCtrlPluginResult AppInterface = null; ComCallbacks onComCallbacks; public App2PluginCommunication(ComCallbacks onComCallbacks) { this.onComCallbacks = onComCallbacks; } public void updateDeviceConnection(@NonNull Device device, int connection_id) { if (AppInterface == null) { onComCallbacks.lostConnectionToAppHost(); return; } try { AppInterface.deviceConnectionChanged(device.getUniqueDeviceID(), connection_id, device.getConnectionByID(connection_id).toString()); } catch (NullPointerException e) { // Ignore this error } catch (RemoteException e) { onComCallbacks.lostConnectionToAppHost(); } } public void updateDevicePort(@NonNull DevicePort devicePort) { if (AppInterface == null) { onComCallbacks.lostConnectionToAppHost(); return; } try { assert devicePort.device != null; AppInterface.devicePortChanged(devicePort.device.getUniqueDeviceID(), devicePort.toString()); } catch (NullPointerException e) { // Ignore this error } catch (RemoteException e) { onComCallbacks.lostConnectionToAppHost(); } } public void deviceChanged(Device device) { if (AppInterface == null) { onComCallbacks.lostConnectionToAppHost(); return; } try { AppInterface.deviceChanged(device.toString()); } catch (NullPointerException e) { // Ignore this error } catch (RemoteException e) { onComCallbacks.lostConnectionToAppHost(); } } @Override public void init(INetPwrCtrlPluginResult cb, int api_version) throws RemoteException { if (api_version != 1) { cb.finished(true); onComCallbacks.lostConnectionToAppHost(); return; } AppInterface = cb; } @Override public void shutdown() throws RemoteException { onComCallbacks.lostConnectionToAppHost(); } @Override public void requestData() throws RemoteException { onComCallbacks.requestData(); } @Override public void requestDataByConnection(String device_unique_id, int device_connection_id) throws RemoteException { Device device = onComCallbacks.getDeviceByUniqueID(device_unique_id); if (device == null) return; DeviceConnection deviceConnection = device.getConnectionByID(device_connection_id); if (deviceConnection != null) onComCallbacks.requestData(deviceConnection); } @Override public void execute(String device_unique_id, String devicePort_unique_id, int command) throws RemoteException { Device device = onComCallbacks.getDeviceByUniqueID(device_unique_id); if (device == null) return; DevicePort devicePort = device.getDevicePortByUid(devicePort_unique_id); if (devicePort != null) onComCallbacks.execute(devicePort, command); else onComCallbacks.devicePortNotFound(device); } @Override public void rename(String device_unique_id, String devicePort_unique_id, String new_name) throws RemoteException { Device device = onComCallbacks.getDeviceByUniqueID(device_unique_id); if (device == null) return; DevicePort devicePort = device.getDevicePortByUid(devicePort_unique_id); if (devicePort != null) onComCallbacks.rename(devicePort, new_name); } public interface ComCallbacks { void lostConnectionToAppHost(); void requestData(); void requestData(DeviceConnection deviceConnection); void execute(DevicePort devicePort, int command); void rename(DevicePort devicePort, String new_name); Device getDeviceByUniqueID(String device_unique_id); void devicePortNotFound(Device device); } }