OSGi 이야기

OGEMA - DeviceSimulationV2.impl

НooпeУ 2011. 12. 29. 15:16
ogmea.sample.device.Sim.DeviceSimulation implements RunningModule,,ResourceListener

interface RunningModle extends Module
- SyncMaster에 의해 호출되는 moudule interface
- start(ExecutionTime curTime), step(ExecutionTime curTime), stop(ExecutionTime curTime)을 메소드 노출

-start(ExecutionTime curTime)
모듈이 시작될 때, 마스터에 의해 이 함수는 호출된다.

-step
모듈의 한 스텝씩 마스터에 의해 이 함수는 호출된다.

-stop
모듈이 멈출때, master에 의해 이 함수는 호출된다.
 
Module{String getName();}

/******************************************************************/
ResourceListener
어떤 자원의 사용가능성을 리스닝하려고 할 때

ConnectMode resourceAvailable(int id, int demandId);
-  application 정보와 요구되는 자원의 사용가능성의 어플리케이션을 설명한다. 
- id : 사용가능한 resource id
- demandId : id를 가지고 demandId를 가지는 리소스를 이용할 수 있는가?
- ConnectionMode : 위에 대한 답을 enum 타입으로 리턴

enum ConnectMode{NO_CONNECTION,NO_WRITE_DEMAND, HAS_WRITE_DEMAND_APP,RESOURCE_DELETED}

 void resourceUpdatedBoolean(int demandId, int id, boolean value); 
- id가 변했을 떄 요청되는 demandID를 가지고 있는 리소스의 값의 변경여부
- value : new value of resource changed

 void resourceUpdatedInt(int demandId, int id, int value);
- id가 변했을 때 요청되는 dmandId를 가지고 있는 리소스의 값을 value로 지정한다.

void resourceUpdatedFloat(int demandId, int id, float value);
void resourceUpdatedString(int demandId, int id, String value);
void resourceUpdatedLong(int demandId, int id, long value);
ConnectMode resourceRegisterStatusChanged(int demandId, int id,
boolean hasBeenUnlocked,
String otherApplicationName, ConnectMode newOwnConnectMode);

List<Integer> getWritingDemands(int demandId, int resourceId);
 String getName();


/***********************************************************/

이제부터 진짜다... 이거보고 감동먹었슴
 시스템 실행중에 즉, 런타임 중에 어플을 올린다는 것은 힘든 작업이다. 리플렉션에 대해 꿰고 있어야 할 수 있다고 생각한다.

/**
 * Information about one resource which is managed by the device simulation.</p>

디바이스 시뮬레이션에 의해 관리되는 하나의 리소스의 정보를 추상화한 클래스 
 
 * @author Johanna Kuhlmann
 */
private class SimulatedDeviceResource {
private Field field; /* field having the resource */
private String resourcePath; /* path of the resource */
private boolean supervised; /* true if resource is supervised, i.e. a ResourceDemand is registered */
private ConnectMode access; /* read or write access */
private int id; /* id of the resource */
private SimulatedDevice simulatedDevice; /* parent, i.e. the complete device */
private Object lastValue; /* last value for checks if the value of a write resource was modified.
* The value only is set for output resources. For input resources its always null */
}

/***********************************************************/
 public class SimulatedDevice {

//하는 일이 뭘까?
//simulated devices의 새로운 storage
public SimulatedDevice(KnownDevice device) {}