Commit 31d5a314 authored by Maxime Perrotin's avatar Maxime Perrotin

Add adb stub for RIs

parent 6c72e5f1
......@@ -348,7 +348,8 @@ LD_LIBRARY_PATH=./lib:. opengeode-simulator
# When a signal is sent from the model a call to a function is emitted
# This function has to be provided - either by TASTE (kazoo), or by
# the user. Opengeode will generate a stub package for this.
ri_stub_template = []
ri_stub_ads = []
ri_stub_adb = []
# Add user-defined NEWTYPEs
if process.user_defined_types:
......@@ -581,15 +582,20 @@ use Interfaces,
{generic_spec}'''.strip() + f'''
package {process_name} with Elaborate_Body is''']
ri_stub_template = [f'''\
ri_stub_ads = [f'''\
-- This file is a stub for the implementation of the required interfaces
-- It is normally overwritten by TASTE with the actual connection to the
-- middleware. If you use Opengeode independently from TASTE you may
-- add a .adb with your own implementation of these functions.
-- middleware. If you use Opengeode independently from TASTE you must
-- edit the .adb (body) with your own implementation of these functions.
-- The body stub will be generated only once.
package {process_name}_RI is''']
ri_stub_adb = [f'''-- Stub generated by OpenGEODE.
-- You can edit this file, it will not be overwritten
package body {process_name}_RI is''']
dll_api = []
......@@ -890,7 +896,8 @@ package {process_name}_RI is''']
elif not generic:
ads_template.append(f'procedure RI{SEPARATOR}{sig}{param_spec} '
f'renames {process_name}_RI.{sig};')
ri_stub_template.append(f'procedure {sig}{param_spec} is null;')
ri_stub_ads.append(f'procedure {sig}{param_spec};')
ri_stub_adb.append(f'procedure {sig}{param_spec} is null;')
# TASTE generates the pragma import in <function>
# therefore do not generate it in the .ads
# ads_template.append(f'pragma Import (C, RI{SEPARATOR}{sig}, "{process_name.lower()}_RI_{sig}");')
......@@ -937,10 +944,8 @@ package {process_name}_RI is''']
elif not generic:
ads_template.append(f'{ri_header} renames {process_name}_RI.{sig};')
ri_stub_template.append(f'procedure {sig}{params_spec} is null;')
#ri_stub_template.append(f'{ri_header} is null;')
#procname = process_name.lower()
#ads_template.append(f'pragma Import(C, RI{SEPARATOR}{sig}, "{procname}_RI_{sig}");')
ri_stub_ads.append(f'procedure {sig}{params_spec};')
ri_stub_adb.append(f'procedure {sig}{params_spec} is null;')
# for the .ads file, generate the declaration of timers set/reset functions
for timer in process.timers:
......@@ -982,12 +987,14 @@ package {process_name}_RI is''']
f'procedure SET_{timer} (Val : in out asn1SccT_UInt32) '
f'renames {process_name}_RI.Set_{timer};')
ri_stub_template.append(f'procedure SET_{timer} (Val : in out asn1SccT_UInt32) is null;')
ri_stub_ads.append(f'procedure SET_{timer} (Val : in out asn1SccT_UInt32);')
ri_stub_adb.append(f'procedure SET_{timer} (Val : in out asn1SccT_UInt32) is null;')
# f'pragma Import (C, SET_{timer}, "{procname}_RI_SET_{timer}");')
ads_template.append(f'procedure RESET_{timer} '
f'renames {process_name}_RI.Reset_{timer};')
ri_stub_template.append(f'procedure RESET_{timer} is null;')
ri_stub_ads.append(f'procedure RESET_{timer};')
ri_stub_adb.append(f'procedure RESET_{timer} is null;')
# f'pragma Import (C, RESET_{timer}, "{procname}_RI_RESET_{timer}");')
......@@ -1106,25 +1113,22 @@ package {process_name}_RI is''']
taste_template.append('if {}.Init_Done then'.format(LPREFIX))
taste_template.append("Check_Queue (msgPending);")
taste_template.append('end if;')
u'procedure Check_Queue (Res : out Asn1Boolean);')
ads_template.append('procedure Check_Queue (Res : out Asn1Boolean);')
if not generic:
u'pragma Import(C, Check_Queue, "{proc}_check_queue");'
ads_template.append(f'pragma Import(C, Check_Queue, "{process_name}_check_queue");')
elif has_cs and simu:
taste_template.append('if {}.Init_Done then'.format(LPREFIX))
taste_template.append("Check_Queue (msgPending);")
taste_template.append('end if;')
# simulation: create a callback registration function
ads_template.append(u'type Check_Queue_T is access procedure'
u'(Res : out Asn1Boolean);')
ads_template.append(u'pragma Convention(Convention => C,'
u' Entity => Check_Queue_T);')
ads_template.append(u'Check_Queue : Check_Queue_T;')
ads_template.append(u'procedure Register_Check_Queue'
u'(Callback : Check_Queue_T);')
ads_template.append(u'pragma Export (C, Register_Check_Queue,'
ads_template.append('type Check_Queue_T is access procedure'
'(Res : out Asn1Boolean);')
ads_template.append('pragma Convention(Convention => C,'
' Entity => Check_Queue_T);')
ads_template.append('Check_Queue : Check_Queue_T;')
ads_template.append('procedure Register_Check_Queue'
'(Callback : Check_Queue_T);')
ads_template.append('pragma Export (C, Register_Check_Queue,'
' "register_check_queue");')
......@@ -1249,7 +1253,8 @@ package {process_name}_RI is''']
ads_template.append(f'end {process_name};')
ri_stub_template.append(f'end {process_name}_RI;')
ri_stub_ads.append(f'end {process_name}_RI;')
ri_stub_adb.append(f'end {process_name}_RI;')
with open(process_name.lower() + os.extsep + 'adb', 'wb') as ada_file:
code = '\n'.join(format_ada_code(taste_template)).encode('latin1')
......@@ -1261,8 +1266,12 @@ package {process_name}_RI is''']
if not taste:
with open(f"{process_name.lower()}", "wb") as ri_stub:
ri_stub.write (
ri_stub.write ("\n".join(format_ada_code(ri_stub_ads)).encode('latin1'))
stub_adb = f'{process_name.lower()}_ri.adb'
# don't overwrite adb as it may contain user code
if not os.path.exists(stub_adb):
with open(stub_adb, "wb") as ri_stub:
ri_stub.write ("\n".join(format_ada_code(ri_stub_adb)).encode('latin1'))
with open("{}_ada.gpr".format(process_name.lower()), "wb") as gprada:
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