Commit 5d9627f0 authored by Sebastien Petitdemange's avatar Sebastien Petitdemange
Browse files

switch: base class for switch object.

parent 87ea481b
# -*- coding: utf-8 -*-
# This file is part of the bliss project
# Copyright (c) 2017 Beamline Control Unit, ESRF
# Distributed under the GNU LGPLv3. See LICENSE for more info.
import functools
from gevent import lock
from bliss.config.conductor.client import Lock
from bliss.config.channels import Cache
class Switch(object):
Generic interface for switch object.
def lazy_init(func):
def func_wrapper(self,*args,**kwargs):
with Lock(self):
return func(self,*args,**kwargs)
return func_wrapper
def __init__(self,name,config):
self.__name = name
self.__config = config
self.__initialized_hw = Cache(self,"initialized",
default_value = False)
self._init_flag = False
self.__lock = lock.Semaphore()
def name(self):
return self.__name
def config(self):
return self.__config
def init(self):
initialize the switch object
if not self._init_flag:
self._init_flag = True
with Lock(self):
with self.__lock:
if not self.__initialized_hw.value:
self.__initialized_hw.value = True
self._init_flag = False
def _init(self):
This method should contains all software initialization
def _initialize_hardware(self):
This method should contains all commands needed to
initialize the hardware.
It will be called only once (by the first client).
def set(self,state):
return self._set(state.upper())
def _set(self,state):
raise NotImplementedError
def get(self):
return self._get().upper()
def _get(self):
raise NotImplementedError
def states_list(self):
return [x.upper() for x in self._states_list()]
def _states_list(self):
raise NotImplementedError
Supports Markdown
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