예제 #1
0
def get_bundle_context():
    _bundle = FrameworkUtil.getBundle(jsr223_class)
    return _bundle.getBundleContext() if _bundle else None
예제 #2
0
from java.util import Hashtable
from org.osgi.framework import FrameworkUtil
from org.osgi.service.event import EventHandler, EventConstants, EventAdmin
from org.osgi.util.tracker import ServiceTracker

from org.osgi.service.cm import ManagedService
from org.osgi.framework import Constants

# Note: These imports will trigger OSGI dependency resolution
# and have side-effects that cause NPEs in the JSR223 binding.
from org.openhab.core.events import AbstractEventSubscriber
from org.openhab.core.jsr223.internal.engine import Jsr223Engine
from org.openhab.model.item.binding import BindingConfigReader
# ---------------

bundle_context = FrameworkUtil.getBundle(Jsr223Engine).getBundleContext()

def hashtable(*key_values):
    """
    :param key_values: 2-tuples of (key, value)
    :return: initialized Hashtable
    """
    ht = Hashtable()
    for k, v in key_values:
        ht.put(k, v)
    return ht

class Binding(AbstractEventSubscriber, BindingConfigReader, ManagedService):
    """
        Base class for Jython Binding implementations.
    """
예제 #3
0
from java.util import Hashtable
from org.osgi.framework import FrameworkUtil
from org.osgi.service.event import EventHandler, EventConstants, EventAdmin
from org.osgi.util.tracker import ServiceTracker

from org.osgi.service.cm import ManagedService
from org.osgi.framework import Constants

# Note: These imports will trigger OSGI dependency resolution
# and have side-effects that cause NPEs in the JSR223 binding.
from org.openhab.core.events import AbstractEventSubscriber
from org.openhab.core.jsr223.internal.engine import Jsr223Engine
from org.openhab.model.item.binding import BindingConfigReader
# ---------------

bundle_context = FrameworkUtil.getBundle(Jsr223Engine).getBundleContext()


def hashtable(*key_values):
    """
    :param key_values: 2-tuples of (key, value)
    :return: initialized Hashtable
    """
    ht = Hashtable()
    for k, v in key_values:
        ht.put(k, v)
    return ht


class Binding(AbstractEventSubscriber, BindingConfigReader, ManagedService):
    """
예제 #4
0
파일: __init__.py 프로젝트: jpg0/oh-config
"""
Provides utility functions for retrieving, registering and removing OSGi
services.
"""
__all__ = [
    'get_service',
    'find_services',
    'register_service',
    'unregister_service'
]

from core.jsr223.scope import scriptExtension
from org.osgi.framework import FrameworkUtil

_bundle = FrameworkUtil.getBundle(type(scriptExtension))
bundle_context = _bundle.getBundleContext() if _bundle else None

registered_services = {}

def get_service(class_or_name):
    """
    This function gets the specified OSGi service.

    Args:
        class_or_name (class or str): the class or class name of the service to
            get

    Returns:
        OSGi service or None: the requested OSGi service or None
    """
    if bundle_context: