Commit 05eb875e authored by yoogx's avatar yoogx

* Example of RPC using ports

        For openaadl/ocarina#169
parent 45856775
......@@ -221,6 +221,7 @@ AC_OUTPUT([
examples/aadlv2/file-store/Makefile
examples/aadlv2/latency/Makefile
examples/aadlv2/rma/Makefile
examples/aadlv2/rpc/Makefile
examples/aadlv2/some-types/Makefile
examples/aadlv2/some-types-stdint/Makefile
examples/aadlv2/sunseeker/Makefile
......
SUBDIRS = d3.1.3-1 ping rma sunseeker producer-consumer some-types \
some-types-stdint flight-mgmt import monitor lua cpp \
packet-store file-store latency code_coverage torture_gqueue
packet-store file-store latency code_coverage torture_gqueue \
rpc
SAMPLE_DIR = ${shell $(CYGPATH_U) '$(OCARINA_PREFIX)/examples/ocarina/polyorb-hi-c/aadlv2'}
......
C_FILES = $(srcdir)/rpc.c
AADL_FILES = $(srcdir)/rpc.aadl
SCENARIO_FILES = $(srcdir)/scenario.aadl
include $(srcdir)/../../Makefile.common
EXTRA_DIST = $(AADL_FILES) $(SCENARIO_FILES) $(C_FILES)
CLEANDIRS = rpc_impl
package RPC
-- This example illustrates how to emulate RPC synchronous (or
-- rendez-vous) interactions using a tuple of parameter/return value
-- ports, and the AADL runtime services.
public
with Data_Model;
with Deployment;
---------------
-- Processes --
---------------
-- RPC_Process host two threads interacting in a synchronou way: a
-- client and a server
process RPC_Process
end RPC_Process;
process implementation RPC_Process.Impl
subcomponents
Client_T : thread Client_Thread.Impl;
Server_T : thread Server_Thread.Impl;
connections
C1 : port Client_T.Out_Parameter -> Server_T.In_Parameter;
C2 : port Server_T.Return_Value -> Client_T.Return_Value;
end RPC_Process.Impl;
-------------
-- Threads --
-------------
thread Client_Thread
features
Out_Parameter : out event data port Alpha_Type;
Return_Value : in event data port Alpha_Type;
end Client_Thread;
thread implementation Client_Thread.Impl
-- In the case of the client-side of the RPC: the corresponding
-- AADL subprogram is *NOT* connected to AADL thread ports. The
-- Client_Side_Function interacts directly with the port
-- variables to emulate a RPC synchronous call:
--
-- 1/ we send the parameter through the "out_parameter" port
-- 2/ we block and wait for return parameters through the return_value
properties
Dispatch_Protocol => Periodic;
Period => 1 sec;
Priority => 110;
Compute_Entrypoint => classifier (Client_Side_Function);
end Client_Thread.Impl;
thread Server_Thread
features
In_Parameter : in event data port Alpha_Type;
Return_Value : out event data port Alpha_Type;
end Server_Thread;
thread implementation Server_Thread.Impl
-- In the case of the server-side RPC: the server function is
-- connected to the input parameter and return value ports, we
-- take advantage of port-to-parameter conenctions to hook the
-- server code directly. It is sporadic to reflect it server
-- nature: ut reacts to incoming events representing the arrival
-- of in parameters and will answer back through the return_value
-- port.
calls
Mycalls: {
S_Spg : subprogram Server_Side_Function;
};
connections
parameter S_Spg.Return_Value -> Return_Value;
parameter In_Parameter -> S_Spg.In_Parameter;
properties
Dispatch_Protocol => Sporadic;
Period => 10 ms;
end Server_Thread.Impl;
----------
-- Data --
----------
data Alpha_Type
properties
Data_Model::Data_Representation => integer;
end Alpha_Type;
-----------------
-- Subprograms --
-----------------
subprogram Server_Side_Function
features
In_Parameter : in parameter Alpha_Type;
Return_Value : out parameter Alpha_Type;
properties
Source_Language => (C);
Source_Name => "rpc_server";
Source_Text => ("rpc.c");
end Server_Side_Function;
subprogram Client_Side_Function
features
Out_Parameter : out parameter Alpha_Type;
Return_Value : in parameter Alpha_Type;
properties
Source_Language => (C);
Source_Name => "rpc_client";
Source_Text => ("rpc.c");
end Client_Side_Function;
---------------
-- Processor --
---------------
processor the_processor
properties
Deployment::Execution_Platform => Native;
end the_processor;
processor implementation the_processor.i
end the_processor.i;
------------
-- System --
------------
system RPC
end RPC;
system implementation RPC.Impl
subcomponents
RPC : process RPC_Process.Impl;
CPU : processor the_processor.i;
properties
Actual_Processor_Binding => (reference (CPU)) applies to RPC;
end RPC.Impl;
end RPC;
#include <aadl.h>
#include <stdio.h>
/* Files generated from AADL model */
#include <request.h>
#include <deployment.h>
#include "types.h"
#include <po_hi_transport.h>
#include <po_hi_gqueue.h>
/******************************************************************************/
/* In the case of the client-side of the RPC: the corresponding AADL
* subprogram is *NOT* connected to AADL thread ports. We interact
* directly with the port variables to emulate a RPC synchronous call:
* 1/ we send the parameter through the "out_parameter" port
* 2/ we block and wait for return parameters through the return_value
*/
void rpc_client (__po_hi_task_id self) {
static int i = 0;
__po_hi_request_t req;
__po_hi_local_port_t return_value_port;
printf ("[START of RPC]\n");
req.port = REQUEST_PORT (client_t, out_parameter);
req.PORT_VARIABLE (client_t,out_parameter) = i;
__po_hi_gqueue_store_out
(self,
LOCAL_PORT (client_t,out_parameter),
&req);
__po_hi_send_output (self,REQUEST_PORT(client_t, out_parameter));
printf ("Client thread: sending parameter %d\n", i);
__po_hi_gqueue_wait_for_incoming_event(self, &return_value_port);
__po_hi_gqueue_get_value(self,return_value_port,&req);
__po_hi_gqueue_next_value(self,return_value_port);
printf ("Client received: %d\n",
req.PORT_VARIABLE(client_t,return_value));
i++;
printf ("[END of RPC]\n\n");
}
/******************************************************************************/
/* In the case of the server-side RPC: the server function is
* connected to the input parameter and return value ports, we take
* advantage of port-to-parameter conenctions to hook the server code
* directly
*/
void rpc_server
(rpc__alpha_type in_parameter,
rpc__alpha_type* return_value)
{
printf ("Server thread: received %d\n", in_parameter);
*return_value = in_parameter + 1;
printf ("Server thread: sending return value %d\n", *return_value);
}
package Scenario
public
with Ocarina_Config;
with Ocarina_Library;
system producer_consumer extends Ocarina_Library::Default_PolyORB_HI_C_Config
properties
Ocarina_Config::Timeout_Property => 10500ms;
Ocarina_Config::AADL_Files +=>
("rpc.aadl");
Ocarina_Config::Root_System_Name => "rpc.impl";
end producer_consumer;
system implementation producer_consumer.Impl
end producer_consumer.Impl;
end scenario;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment