Ejemplo n.º 1
0
        //////////////////////////////////////////////////////////////////////////
        public void Init()
        {
            /*
            After calling this method, this Framework must:
            Be in the Bundle.STARTING state.
            Have a valid Bundle Context.
            Be at start level 0.
            Have event handling enabled.
            Have reified Bundle objects for all installed bundles.
            Have registered any framework services. For example, PackageAdmin, ConditionalPermissionAdmin, StartLevel.
            This Framework will not actually be started until start is called.

            This method does nothing if called when this Framework is in the Bundle.STARTING, Bundle.ACTIVE or Bundle.STOPPING states.
            */

            lock(m_lock)
            {
                if(getState() == BundleState.STARTING ||
                    getState() == BundleState.ACTIVE ||
                    getState() == BundleState.STOPPING)
                    return;

                m_shutdownResult = new FrameworkEvent(FrameworkEvent.Type.STOPPED, this, null);
                m_bundleRepository = new CBundleRepository(this);
                m_serviceRegistry = new CServiceRegistry(this);
                m_eventServer = new CEventServer();

                m_bundleListeners = new ListenerQueue<IBundleListener>();
                m_syncBundleListeners = new ListenerQueue<ISynchronousBundleListener>();
                m_frameworkListeners = new ListenerQueue<IFrameworkListener>();
                m_serviceListeners = new ListenerQueue<IServiceListener>();
                m_allServiceListeners = new ListenerQueue<IAllServiceListener>();

                if(getState() == BundleState.INSTALLED)
                    setState(BundleState.RESOLVED);
                setState(BundleState.STARTING);

                m_context = new CBundleContext(this, this);
                m_activator = new CSystemBundleActivator();
                m_activator.Start(m_context);
            }
        }
Ejemplo n.º 2
0
        //////////////////////////////////////////////////////////////////////////
        public CServiceRegistration RegisterService(string[] clazz, object service/*, Dictionary properties*/, CBundleContext bundleCtx)
        {
            CServiceRegistration reg = new CServiceRegistration(clazz, service, bundleCtx);

            lock (m_lock)
            {
                foreach (string clz in clazz)
                {
                    List<CServiceRegistration> sbucket;
                    if (!m_services.TryGetValue(clz, out sbucket))
                    {
                        sbucket = new List<CServiceRegistration>();
                        m_services.Add(clz, sbucket);
                    }
                    sbucket.Add(reg);
                }
            }

            return reg;
        }
Ejemplo n.º 3
0
        //////////////////////////////////////////////////////////////////////////

        protected virtual void PreStart()
        {
            m_state = BundleState.STARTING;
            m_systemBundle.RaiseBundleEvent(new BundleEvent(BundleEvent.Type.STARTING, this));

            m_activator = null;

            try
            {
                m_assembly = m_systemBundle.getBundleRepository().LoadBundleAssembly(this);

                Type[] exports = m_assembly.GetExportedTypes();
                foreach (Type t in exports)
                {
                    TypeAttributes attrs = t.Attributes;
                    if ((attrs & TypeAttributes.Interface) == TypeAttributes.Interface ||
                        (attrs & TypeAttributes.Abstract) == TypeAttributes.Abstract)
                    {
                        continue;
                    }

                    if (t.GetInterface(typeof(IBundleActivator).FullName) != null)
                    {
                        m_activator = m_assembly.CreateInstance(t.FullName) as IBundleActivator;
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                m_state = BundleState.RESOLVED;
                throw new BundleException("Failed to load bundle assembly", BundleException.ErrorCode.STATECHANGE_ERROR, ex);
            }

            m_context = new CBundleContext(this, m_systemBundle);
        }
Ejemplo n.º 4
0
        //////////////////////////////////////////////////////////////////////////
        public void Init()
        {
            /*
            After calling this method, this Framework must:
            Be in the Bundle.STARTING state.
            Have a valid Bundle Context.
            Be at start level 0.
            Have event handling enabled.
            Have reified Bundle objects for all installed bundles.
            Have registered any framework services. For example, PackageAdmin, ConditionalPermissionAdmin, StartLevel.
            This Framework will not actually be started until start is called.

            This method does nothing if called when this Framework is in the Bundle.STARTING, Bundle.ACTIVE or Bundle.STOPPING states.
            */

            lock(m_lock)
            {
                if(m_state == BundleState.STARTING ||
                    m_state == BundleState.ACTIVE ||
                    m_state == BundleState.STOPPING)
                    return;

                m_bundleRepository = new CBundleRepository(this);
                m_serviceRegistry = new CServiceRegistry(this);
                m_eventServer = new CEventServer();

                m_bundleListeners = new ListenerQueue<IBundleListener>();
                m_syncBundleListeners = new ListenerQueue<ISynchronousBundleListener>();
                m_frameworkListeners = new ListenerQueue<IFrameworkListener>();
                m_serviceListeners = new ListenerQueue<IServiceListener>();
                m_allServiceListeners = new ListenerQueue<IAllServiceListener>();

                m_state = BundleState.STARTING;
                m_context = new CBundleContext(this, this);
                m_activator = new CSystemBundleActivator();
                m_activator.Start(m_context);
            }
        }
        //////////////////////////////////////////////////////////////////////////

        public CServiceRegistration(string[] clazz, object service, CBundleContext bundleCtx)
        {
            m_clazz     = clazz;
            m_instance  = service;
            m_bundleCtx = bundleCtx;
        }
		//////////////////////////////////////////////////////////////////////////

		public CServiceRegistration(string[] clazz, object service, CBundleContext bundleCtx)
		{
			m_clazz = clazz;
			m_instance = service;
			m_bundleCtx = bundleCtx;
		}
Ejemplo n.º 7
0
        //////////////////////////////////////////////////////////////////////////
        protected virtual void PreStop()
        {
            /*
            This bundle's state is set to STOPPING.
            A bundle event of type BundleEvent.STOPPING is fired.
            Any services registered by this bundle must be unregistered.
            Any services used by this bundle must be released.
            Any listeners registered by this bundle must be removed.
            */
            m_state = BundleState.STOPPING;
            m_systemBundle.RaiseBundleEvent(new BundleEvent(BundleEvent.Type.STOPPING, this));

            m_context.Dispose();
            m_context = null;
            // TODO: unregister all links
        }
Ejemplo n.º 8
0
        //////////////////////////////////////////////////////////////////////////
        protected virtual void PreStart()
        {
            m_state = BundleState.STARTING;
            m_systemBundle.RaiseBundleEvent(new BundleEvent(BundleEvent.Type.STARTING, this));

            m_activator = null;

            try
            {
                m_assembly = m_systemBundle.getBundleRepository().LoadBundleAssembly(this);

                Type[] exports = m_assembly.GetExportedTypes();
                foreach (Type t in exports)
                {
                    TypeAttributes attrs = t.Attributes;
                    if ((attrs & TypeAttributes.Interface) == TypeAttributes.Interface ||
                        (attrs & TypeAttributes.Abstract) == TypeAttributes.Abstract)
                        continue;

                    if (t.GetInterface(typeof(IBundleActivator).FullName) != null)
                    {
                        m_activator = m_assembly.CreateInstance(t.FullName) as IBundleActivator;
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                m_state = BundleState.RESOLVED;
                throw new BundleException("Failed to load bundle assembly", BundleException.ErrorCode.STATECHANGE_ERROR, ex);
            }

            m_context = new CBundleContext(this, m_systemBundle);
        }
        //////////////////////////////////////////////////////////////////////////

        public CServiceRegistration RegisterService(string[] clazz, object service /*, Dictionary properties*/, CBundleContext bundleCtx)
        {
            CServiceRegistration reg = new CServiceRegistration(clazz, service, bundleCtx);

            lock (m_lock)
            {
                foreach (string clz in clazz)
                {
                    List <CServiceRegistration> sbucket;
                    if (!m_services.TryGetValue(clz, out sbucket))
                    {
                        sbucket = new List <CServiceRegistration>();
                        m_services.Add(clz, sbucket);
                    }
                    sbucket.Add(reg);
                }
            }

            return(reg);
        }