Skip to content

Commit

Permalink
added options for ioc main
Browse files Browse the repository at this point in the history
  • Loading branch information
ZohebShaikh committed Oct 2, 2024
1 parent de99053 commit 8ac8589
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/python/epicscorelibs/ioc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import os
import atexit

from setuptools_dso import find_dso

from . import path


Expand All @@ -19,9 +21,8 @@
Com = ctypes.CDLL(path.get_lib("Com"), mode=ctypes.RTLD_GLOBAL)
dbCore = ctypes.CDLL(path.get_lib("dbCore"), mode=ctypes.RTLD_GLOBAL)
dbRecStd = ctypes.CDLL(path.get_lib("dbRecStd"), mode=ctypes.RTLD_GLOBAL)
pvAccessIOC = ctypes.CDLL(path.get_lib("pvAccessIOC"), mode=ctypes.RTLD_GLOBAL)
qsrv = ctypes.CDLL(path.get_lib("qsrv"), mode=ctypes.RTLD_GLOBAL)

DEFAULT_DBD_PATH =os.path.join(path.base_path, "dbd")
# The functions we need from those libraries

epicsExitCallAtExits = Com.epicsExitCallAtExits
Expand Down Expand Up @@ -63,7 +64,7 @@ def ioc(cmd):
'''
return iocshCmd(cmd.encode())

def start_ioc(database=None, macros='', dbs=None):
def start_ioc(extra_dbd_load, extra_dso_load, database=None, macros='', dbs=None):
if dbs is None:
dbs = []
if database is not None:
Expand All @@ -73,12 +74,16 @@ def out(msg, *args):
sys.stderr.write(msg%args)
sys.stderr.flush()

for dso in extra_dso_load:
ctypes.CDLL(find_dso(dso), ctypes.RTLD_GLOBAL)

iocshRegisterCommon()

out('IOC Starting w/ %s \n', dbs)
dbdpath = os.path.join(path.base_path, "dbd")
for dbd in [b'base.dbd', b'PVAServerRegister.dbd', b'qsrv.dbd']:
if dbLoadDatabase(dbd, dbdpath.encode(), None):

base_dbd_load = (('base.dbd',DEFAULT_DBD_PATH),)
for dbd,dbdpath in base_dbd_load + tuple(extra_dbd_load):
if dbLoadDatabase(dbd.encode(), dbdpath.encode(), None):
raise RuntimeError('Error loading '+dbdpath)

out('IOC dbd loaded\n')
Expand All @@ -94,8 +99,9 @@ def out(msg, *args):
raise RuntimeError('Error starting IOC')
out('IOC Running\n')


def main():
pva_dbd_load = (("PVAServerRegister.dbd",DEFAULT_DBD_PATH), ("qsrv.dbd",DEFAULT_DBD_PATH))
pva_dso_load = ("epicscorelibs.lib.pvAccessIOC", "epicscorelibs.lib.qsrv",)
def main(extra_dbd_load=pva_dbd_load,extra_dso_load=pva_dso_load):
class DbAction(argparse.Action):
def __call__(self, parser, ns, values, opt):
ns.database.append((values, ns.macros))
Expand All @@ -106,7 +112,7 @@ def __call__(self, parser, ns, values, opt):
parser.add_argument('-d', '--database', default=[], action=DbAction,
help="Path to database file to load")
args = parser.parse_args()
start_ioc(dbs=args.database)
start_ioc(dbs=args.database,extra_dbd_load=extra_dbd_load,extra_dso_load=extra_dso_load)
code.interact(local={
'exit':sys.exit,
'ioc':ioc,
Expand Down

0 comments on commit 8ac8589

Please sign in to comment.