Accelerator Independent Data Access / PVAccess 2.0
AIDA-PVA is the latest version of the AIDA framework. Built on top of EPICS 7 it enables client applications to programmatically access and manage any device or database on the SLAC Network using simple channel names.
Loading...
Searching...
No Matches
AIDASLCMOSC_SERVER.c
Go to the documentation of this file.
1/** @file
2 * @brief Master Oscillator Native Provider implementation.
3 * **MEMBER**=SLCLIBS:AIDA_PVALIB
4 * **ATTRIBUTES**=JNI,LIBR_NOGLOBAL
5 */
6#include "aida_pva.h"
7#include "AIDASLCMOSC_SERVER.h"
8
9static int getMoscArguments(JNIEnv* env, Arguments arguments, Value value, char** units, char** ring, float* floatValue);
10
11// API Stubs
12VERSION("1.0.0")
29
30/**
31 * Initialise the service
32 * @param env to be used to throw exceptions using aidaThrow() and aidaThrowNonOsException()
33 * @throws ServerInitialisationException if the service fails to initialise
34 */
35void aidaServiceInit(JNIEnv* env)
36{
37 vmsstat_t status;
38
39 if (!$VMS_STATUS_SUCCESS(status = init("AIDA_SLCMOSC", false))) {
40 aidaThrow(env, status, SERVER_INITIALISATION_EXCEPTION, "initialising Master Oscillator Service");
41 } else {
42 printf("AIDA-PVA Master Oscillator Provider\n");
43 }
44}
45
46/**
47 * Get a double
48 *
49 * @param env to be used to throw exceptions using aidaThrow() and aidaThrowNonOsException()
50 * @param uri the uri
51 * @param arguments the arguments
52 * @return the double
53 */
54double aidaRequestDouble(JNIEnv* env, const char* uri, Arguments arguments)
55{
56 // Check if operations are enabled?
57 if (!DPSLCMOSC_ACCESSENABLED()) {
59 "Aida access to Master Oscillator is not currently enabled");
60 return 0.0;
61 }
62
63 // Read value
64 double meas_abs_freq;
65 vmsstat_t status;
66 status = DPSLCMOSC_MEASMASTEROSC(&meas_abs_freq);
67 if (!SUCCESS(status)) {
68 aidaThrow(env, status, UNABLE_TO_GET_DATA_EXCEPTION, "Unable to get oscillator frequency");
69 return 0.0;
70 }
71 CONVERT_FROM_VMS_DOUBLE(&meas_abs_freq, 1)
72
73 return meas_abs_freq;
74}
75
76/**
77 * Get a table of data
78 *
79 * @param env to be used to throw exceptions using aidaThrow() and aidaThrowNonOsException()
80 * @param uri the uri
81 * @param arguments the arguments
82 * @return the table
83 */
84Table aidaRequestTable(JNIEnv* env, const char* uri, Arguments arguments)
85{
86 // Create table to return value
87 Table table = tableCreate(env, 1, 1);
89
90 // Get the value
91 double meas_abs_freq = aidaRequestDouble(env, uri, arguments);
93
94 // Add value to table
95 tableAddSingleRowDoubleColumn(env, &table, meas_abs_freq, true);
96
97 // Return table
98 return table;
99}
100
101/**
102 * Set a value and return a table as a response
103 *
104 * @param env to be used to throw exceptions using aidaThrow() and aidaThrowNonOsException()
105 * @param uri the uri
106 * @param arguments the arguments
107 * @param value to set
108 * @return a table
109 */
110Table aidaSetValueWithResponse(JNIEnv* env, const char* uri, Arguments arguments, Value value)
111{
112 // Keep track of stuff to free
114
115 // Check if operations are enabled?
116 if (!DPSLCMOSC_ACCESSENABLED()) {
118 "Aida access to Master Oscillator is not currently enabled");
120 }
121
122 // Get arguments
123 float floatValue;
124 char* units;
125 char* ring;
126 int getArgStatus = getMoscArguments(env, arguments, value, &units, &ring, &floatValue);
127 TRACK_MEMORY(units)
128 TRACK_MEMORY(ring)
129 if (getArgStatus) {
132 }
133
134 // Set value
135 vmsstat_t status;
136 double resulting_abs_freq; // Value read back
137 CONVERT_TO_VMS_FLOAT(&floatValue, 1)
138 status = DPSLCMOSC_SETMASTEROSC(&floatValue, units, ring, &resulting_abs_freq);
140 if (!SUCCESS(status))
141 {
142 aidaThrow(env, status, UNABLE_TO_SET_DATA_EXCEPTION, "Unable to set Master Oscillator frequency");
144 }
145
146 // Now create table to return
147 Table table = tableCreate(env, 1, 1);
149 tableAddSingleRowDoubleColumn(env, &table, resulting_abs_freq, false);
150
151 return table;
152}
153
154/**
155 * Get all Master Oscillator arguments
156 *
157 * @param env
158 * @param arguments
159 * @param value
160 * @param units
161 * @param ring
162 * @param floatValue
163 * @return true if successful
164 */
165static int getMoscArguments(JNIEnv* env, Arguments arguments, Value value, char** units, char** ring, float* floatValue)
166{
167 *units = "FREQUENCY";
168 *ring = NULL;
169 if (avscanf(env, &arguments, &value, "%f %os %os",
170 "value", floatValue,
171 "units", units,
172 "ring", ring
173 )) {
174 return EXIT_FAILURE;
175 }
176
177 // If the units is set to ENERGY then we *do* require the ring parameter
178 if (strcasecmp(*units, "ENERGY") == 0 && *ring == NULL ) {
180 "Master Oscillator Set Variable requires a RING parameter if the UNITS are ENERGY");
181 return EXIT_FAILURE;
182 }
183
184 return EXIT_SUCCESS;
185}
186
REQUEST_STUB_BOOLEAN REQUEST_STUB_BYTE REQUEST_STUB_SHORT REQUEST_STUB_INTEGER REQUEST_STUB_LONG REQUEST_STUB_FLOAT REQUEST_STUB_STRING REQUEST_STUB_BOOLEAN_ARRAY REQUEST_STUB_BYTE_ARRAY REQUEST_STUB_SHORT_ARRAY REQUEST_STUB_INTEGER_ARRAY REQUEST_STUB_LONG_ARRAY REQUEST_STUB_FLOAT_ARRAY REQUEST_STUB_DOUBLE_ARRAY REQUEST_STUB_STRING_ARRAY SET_STUB_VOID void aidaServiceInit(JNIEnv *env)
Initialise the service.
Table aidaSetValueWithResponse(JNIEnv *env, const char *uri, Arguments arguments, Value value)
Set a value and return a table as a response.
Table aidaRequestTable(JNIEnv *env, const char *uri, Arguments arguments)
Get a table of data.
double aidaRequestDouble(JNIEnv *env, const char *uri, Arguments arguments)
Get a double.
The Header File for the AIDA-PVA Module functions.
#define REQUEST_STUB_BYTE
aidaRequestByte API Stub
Definition: aida_pva_api.h:259
#define VERSION(_version)
Use this macro to define the version of the provider.
Definition: aida_pva_api.h:40
#define REQUEST_STUB_INTEGER
aidaRequestInteger API Stub
Definition: aida_pva_api.h:269
#define REQUEST_STUB_LONG_ARRAY
aidaRequestLongArray API Stub
Definition: aida_pva_api.h:326
#define REQUEST_STUB_SHORT
aidaRequestShort API Stub
Definition: aida_pva_api.h:264
#define REQUEST_STUB_INTEGER_ARRAY
aidaRequestIntegerArray API Stub
Definition: aida_pva_api.h:321
#define SET_STUB_VOID
aidaSetValue API stub
Definition: aida_pva_api.h:361
#define REQUEST_STUB_LONG
aidaRequestLong API Stub
Definition: aida_pva_api.h:274
#define REQUEST_STUB_STRING
aidaRequestString API Stub
Definition: aida_pva_api.h:289
#define REQUEST_STUB_SHORT_ARRAY
aidaRequestShortArray API Stub
Definition: aida_pva_api.h:316
#define REQUEST_STUB_BYTE_ARRAY
aidaRequestByteArray API Stub
Definition: aida_pva_api.h:311
#define RETURN_NULL_TABLE
Return an empty table response.
Definition: aida_pva_api.h:380
#define REQUEST_STUB_BOOLEAN
aidaRequestBoolean API Stub
Definition: aida_pva_api.h:253
#define REQUEST_STUB_FLOAT_ARRAY
aidaRequestFloatArray API Stub
Definition: aida_pva_api.h:331
#define REQUEST_STUB_DOUBLE_ARRAY
aidaRequestDoubleArray API Stub
Definition: aida_pva_api.h:336
#define REQUEST_STUB_BOOLEAN_ARRAY
aidaRequestBooleanArray API Stub
Definition: aida_pva_api.h:306
#define REQUEST_STUB_FLOAT
aidaRequestFloat API Stub
Definition: aida_pva_api.h:279
#define REQUEST_STUB_STRING_ARRAY
aidaRequestStringArray API stub
Definition: aida_pva_api.h:342
#define CONVERT_TO_VMS_FLOAT(_float, _count)
Convert in-place, floating point numbers from ieee to VMS format.
#define CONVERT_FROM_VMS_DOUBLE(_double, _count)
Convert in-place, doubles from VMS to ieee format.
#define SERVER_INITIALISATION_EXCEPTION
Use this string to signal Server Initialisation Exceptions in aidaThrow()
#define UNABLE_TO_SET_DATA_EXCEPTION
Use this string to signal Exceptions when trying to Set Data in aidaThrow()
#define MISSING_REQUIRED_ARGUMENT_EXCEPTION
Use this string to signal Missing Required Argument Exceptions in aidaThrow()
#define ON_EXCEPTION_RETURN_(_r)
Check to see if an exception has been raised, and return the given return value.
#define UNABLE_TO_GET_DATA_EXCEPTION
Use this string to signal Exceptions when trying to Get Data in aidaThrow()
#define TRACK_ALLOCATED_MEMORY
Create tracking variables so that memory can be freed with FREE_MEMORY macro.
#define FREE_MEMORY
Free any allocated memory.
#define TRACK_MEMORY(_ptr)
Register this newly allocated memory so that it will be freed by FREE_MEMORY.
void aidaThrow(JNIEnv *env, vmsstat_t status, char *exception, const char *message)
To log any exceptions and throw back to java.
vmsstat_t init(const char *processName, bool initMessageServices)
Call standalone_init()
void aidaThrowNonOsException(JNIEnv *env, char *exception, const char *message)
To log any non-OS exceptions and throw back to java.
Table tableCreate(JNIEnv *env, int rows, int columns)
Make a Table for return to client.
void tableAddSingleRowDoubleColumn(JNIEnv *env, Table *table, double data, bool ieeeDouble)
Add a double column to a Table with only one row.
int avscanf(JNIEnv *env, Arguments *arguments, Value *value, const char *formatString,...)
ascanf(), avscanf()
An Arguments structure stores all of the arguments passed from the request to the Native Channel Prov...
Table structure.
This special type represents a Value.