예제 #1
0
        // Methods inherited from interface org.osgi.framework.BundleActivator

        /// <summary>
        ///
        /// </summary>
        public virtual void  start(BundleContext bc)
        {
            preStart();

            /*Assigning value to variable bc in order to be useful in serviceChanged() method.*/
            this.bc = bc;
            try
            {
                /*!--------------PART FOR REGISTERING SERVICES--------------*/
                /*Registering service with name "de.inhaus.inHausLamp.Lamp".*/
                /*INITIALIZE SERVICE OBJECT lamp FOR PROPER REGISTRATION OF THE UNDERLYING SERVICE!*/
                regLamp = bc.registerService("de.inhaus.inHausLamp.Lamp", lamp, props);
                bc.registerService("org.osgi.service.device.Device", osgi_dev, props);
                /*!--------------END OF PART FOR REGISTERING SERVICES--------------*/
                /*!--------------PART FOR GETTING SERVICES--------------*/
                /*Getting ServiceReference for service with name "InHausBasedriver.InHausBasedriver" through BundleContext passed to start method.*/
                refInHausBaseDriver = bc.getServiceReference(SERVICE_INHAUSBASEDRIVER);
                if (refInHausBaseDriver != null)
                {
                    /*If a service with such name is already registered in the framework.*/
                    /*Getting service object.*/
                    inHausBaseDriver = (InHausBaseDriver)bc.getService(refInHausBaseDriver);
                }
                /*!--------------END OF PART FOR GETTING SERVICES--------------*/

                /*!--------------PART FOR ADDING CLASS AS LISTENER--------------*/

                /*Adding this class as listener for ServiceEvents for services which names
                 * agree with the value of LDAP filter 'FILTER'.*/
                bc.addServiceListener(this, FILTER);
                /*!--------------END OF PART FOR ADDING LISTENERS--------------*/
            }
            catch (System.Exception e)
            {
                /*Logging error via org.osgi.service.log.LogService or com.prosyst.util.ref.Log
                 * and printing the stack trace of the thrown exception.*/
                //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1043"'
                dump("[Lamp]Error in start method: " + e.Message, e);


                //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1043"'
                throw new BundleException("[Lamp]Error in start method: " + e.Message);
            }
            postStart();
        }
예제 #2
0
        /// <summary>Method inherited from interface org.osgi.framework.ServiceListener.
        /// Called when some ServiceEvent is processed - a service is registered,
        /// unregistered or modified.
        /// </summary>
        public virtual void  serviceChanged(ServiceEvent event_Renamed)
        {
            /*DO NOT CHANGE THIS CODE!!!IT'S AUTOMATICALLY GENERATED*/
            switch (event_Renamed.Type)
            {
            case ServiceEvent.REGISTERED:  {
                /*Service has been registered.*/
                /*Constructing an array to hold all names, that the registered service has been registered with.*/
                o("ServiceEvent.REGISTERED");
                System.String[] classNames = (System.String[])event_Renamed.ServiceReference.getProperty("objectClass");
                for (int k = 0; k < classNames.Length; k++)
                {
                    System.String objectClass = classNames[k];
                    /*Searching for service with name "InHausBasedriver.InHausBasedriver".*/
                    if (objectClass.Equals(SERVICE_INHAUSBASEDRIVER))
                    {
                        /*!--------------PART FOR GETTING SERVICES--------------*/
                        /*Getting ServiceReference for service with name "InHausBasedriver.InHausBasedriver" through BundleContext passed to start method.*/
                        refInHausBaseDriver = bc.getServiceReference(SERVICE_INHAUSBASEDRIVER);
                        if (refInHausBaseDriver != null)
                        {
                            /*If a service with such name is already registered in the framework.*/
                            /*Getting service object.*/
                            inHausBaseDriver = (InHausBaseDriver)bc.getService(refInHausBaseDriver);
                            o("inHausBaseDriver = (InHausBaseDriver)bc.getService(refInHausBaseDriver);");
                            lamp.setDriver(inHausBaseDriver);
                        }
                        /*!--------------END OF PART FOR GETTING SERVICES--------------*/

                        break;
                    }
                }
                break;
            }

            case ServiceEvent.UNREGISTERING:  {
                /*Service has been unregistered*/
                o("ServiceEvent.UNREGISTERING");
                /*Constructing an array to hold all names, that the registered service has been registered with.*/
                System.String[] classNames = (System.String[])event_Renamed.ServiceReference.getProperty("objectClass");
                for (int k_1 = 0; k_1 < classNames.Length; k_1++)
                {
                    System.String objectClass = classNames[k_1];
                    /*Searching for service with name "InHausBasedriver.InHausBasedriver".*/
                    if (objectClass.Equals(SERVICE_INHAUSBASEDRIVER))
                    {
                        /*!--------------PART FOR UNGETTING SERVICES--------------*/
                        if (refInHausBaseDriver != null)
                        {
                            /*Ungetting service if the ServiceReference is not null, i.e. the service has been gotten.*/
                            bc.ungetService(refInHausBaseDriver);
                            lamp.Driver = null;
                        }
                        /*!--------------END OF PART FOR UNGETTING SERVICES--------------*/

                        break;
                    }
                }
                break;
            }
            }
            /*END OF AUTOMATICALLY GENERATED CODE*/
        }