Skip to content

Commit

Permalink
DAQ-3058 Extract common code into base class for EPICSv4 test devices
Browse files Browse the repository at this point in the history
Change-Id: I64fea4da11b6cfba44d7bd6a7c062630b92b5a31
  • Loading branch information
joeshannon committed Aug 18, 2020
1 parent daa4c86 commit 325cf95
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,20 @@
import java.util.Map;
import java.util.concurrent.CountDownLatch;

import org.epics.pvaccess.server.ServerContext;
import org.epics.pvaccess.server.impl.remote.ServerContextImpl;
import org.epics.pvdata.pv.PVStructure;

import org.epics.pvdatabase.PVDatabase;
import org.epics.pvdatabase.PVDatabaseFactory;

/**
* This class creates an Epics V4 service, that listens for connections and handles RPC, GET, PUT etc. The modelled
* device is meant to represent a typical Malcolm Device, and has attributes and methods set up accordingly. Any RPC
* call made to the device just pause for 2 seconds and then return an empty Map
*
* @author Matt Taylor
*
*/
public abstract class AbstractEPICSv4Device implements IEPICSv4Device {

protected String recordName = "mydevice";
Expand All @@ -31,4 +43,19 @@ public Map<String, PVStructure> getReceivedRPCCalls() {
return pvRecord.getReceivedRPCCalls();
}

@Override
public void start() throws Exception {
PVDatabase master = PVDatabaseFactory.getMaster();
pvRecord = DummyMalcolmRecord.create(recordName);
pvRecord.setTraceLevel(traceLevel);
master.addRecord(pvRecord);
ServerContext context = ServerContextImpl.startPVAServer(getPvaProviderName(), 0, true,
System.out);
latch.await();
master.removeRecord(pvRecord);
context.destroy();
}

protected abstract String getPvaProviderName();

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@
*******************************************************************************/
package org.eclipse.scanning.example.malcolm;

import org.epics.pvaccess.PVAException;
import org.epics.pvaccess.server.impl.remote.ServerContextImpl;
import org.epics.pvdatabase.PVDatabase;
import org.epics.pvdatabase.PVDatabaseFactory;

/**
* This class creates an Epics V4 service, that listens for connections and handles RPC, GET, PUT etc. The modelled
* device is meant to represent a typical Malcolm Device, and has attributes and methods set up accordingly. Any RPC
* call made to the device just pause for 2 seconds and then return an empty Map
* This Epics Device fails to start with the error {@code WARNING: Channel provider
* with name 'evil' not available.}
* <p>
* This is because the Pva provider name is invalid.
*
* @author Matt Taylor
*
Expand All @@ -31,15 +27,7 @@ public EPICSv4EvilDevice(String deviceName) {
}

@Override
public void start() throws InterruptedException, PVAException {
PVDatabase master = PVDatabaseFactory.getMaster();

pvRecord = DummyMalcolmRecord.create(recordName);
pvRecord.setTraceLevel(traceLevel);
master.addRecord(pvRecord);
ServerContextImpl context = ServerContextImpl.startPVAServer("evil", 0, true, System.out);
latch.await();
master.removeRecord(pvRecord);
context.destroy();
protected String getPvaProviderName() {
return "evil";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,10 @@
package org.eclipse.scanning.example.malcolm;

import org.epics.pvaccess.client.ChannelProvider;
import org.epics.pvaccess.server.impl.remote.ServerContextImpl;
import org.epics.pvdatabase.PVDatabase;
import org.epics.pvdatabase.PVDatabaseFactory;
import org.epics.pvdatabase.pva.ChannelProviderLocalFactory;

/**
* This class creates an Epics V4 service, that listens for connections and handles RPC, GET, PUT etc. The modelled
* device is meant to represent a typical Malcolm Device, and has attributes and methods set up accordingly. Any RPC
* call made to the device just pause for 2 seconds and then return an empty Map
* A functioning example Epics V4 device.
*
* @author Matt Taylor
*
Expand All @@ -32,16 +27,8 @@ public EPICSv4ExampleDevice(String deviceName) {
}

@Override
public void start() throws Exception {
PVDatabase master = PVDatabaseFactory.getMaster();
protected String getPvaProviderName() {
ChannelProvider channelProvider = ChannelProviderLocalFactory.getChannelProviderLocal();
pvRecord = DummyMalcolmRecord.create(recordName);
pvRecord.setTraceLevel(traceLevel);
master.addRecord(pvRecord);
ServerContextImpl context = ServerContextImpl.startPVAServer(channelProvider.getProviderName(), 0, true,
System.out);
latch.await();
master.removeRecord(pvRecord);
context.destroy();
return channelProvider.getProviderName();
}
}

0 comments on commit 325cf95

Please sign in to comment.