Poco::OSP

class BundleLoader

File Information

Library: OSP
Package: Bundle
Header: Poco/OSP/BundleLoader.h

Description

The BundleLoader is used internally by the framework to manage Bundle and BundleContext objects, and to load shared libraries containing BundleActivator classes.

The BundleLoader uses the logger osp.core.BundleLoader to write diagnostic messages.

Member Summary

Member Functions: contextForBundle, createBundle, events, findBundle, installLibraries, installLibrary, isProvidingModule, isResolving, libraryNameFor, libraryPathFor, listBundles, listLibraries, loadActivator, loadBundle, makeValidFileName, nextBundleId, osArchitecture, osName, pathForLibrary, resolveAllBundles, resolveBundle, resolveDependencies, resolveDependency, resolveModules, resolveProviders, sortBundles, startAllBundles, startBundle, startDependencies, stopAllBundles, stopBundle, uninstallBundle, uninstallLibraries, unloadActivator, unloadAllBundles, unloadBundle

Nested Classes

struct BundleError

 

struct BundleInfo

 

Types Aliases

ActivatorClassLoader

using ActivatorClassLoader = Poco::ClassLoader < BundleActivator >;

ActivatorClassLoaderPtr

using ActivatorClassLoaderPtr = Poco::SharedPtr < ActivatorClassLoader >;

BundleMap

using BundleMap = std::map < std::string, BundleInfo >;

BundleSet

using BundleSet = std::set < Bundle * >;

Constructors

BundleLoader

BundleLoader(
    CodeCache & codeCache,
    BundleFactory::Ptr pBundleFactory,
    BundleContextFactory::Ptr pBundleContextFactory,
    bool autoUpdateCodeCache = true
);

Creates the BundleLoader.

BundleLoader

BundleLoader(
    CodeCache & codeCache,
    BundleFactory::Ptr pBundleFactory,
    BundleContextFactory::Ptr pBundleContextFactory,
    const std::string & osName,
    const std::string & osArch,
    bool autoUpdateCodeCache = true
);

Creates the BundleLoader.

Destructor

~BundleLoader

~BundleLoader();

Destroys the BundleLoader.

Member Functions

contextForBundle

BundleContext::Ptr contextForBundle(
    Bundle::ConstPtr pBundle
) const;

Returns the BundleContext for the given bundle.

createBundle

Bundle::Ptr createBundle(
    const std::string & path
);

Loads a bundle from the given path.

A new Bundle object is created for the bundle, and the Bundle's state is BUNDLE_INSTALLED. The bundle is not added to the bundle map.

events inline

BundleEvents & events();

Returns a reference to the BundleEvents object.

findBundle

Bundle::ConstPtr findBundle(
    const std::string & symbolicName
) const;

Returns the Bundle object for the bundle with the given symbolic name, or NULL if the bundle does not exist.

findBundle

Bundle::ConstPtr findBundle(
    int id
) const;

Returns the Bundle object for the bundle with the given ID, or NULL if the bundle does not exist.

listBundles

void listBundles(
    std::vector < Bundle::Ptr > & bundles
) const;

Fills the given vector with all bundles known to the loader.

listBundles

void listBundles(
    std::vector < Bundle::Ptr > & bundles,
    BundleFilter::Ptr pFilter
) const;

Fills the given vector with all bundles known to the loader, filtered by the given BundleFilter.

loadBundle

Bundle::Ptr loadBundle(
    const std::string & path
);

Loads a bundle from the given path. A new Bundle object is created for the bundle, and the Bundle's state is BUNDLE_INSTALLED.

The bundle is then added to the bundle map. If another version of the same bundle is already loaded, a BundleVersionConflictException is thrown.

Returns the new Bundle object.

loadBundle

void loadBundle(
    Bundle::Ptr pBundle
);

Loads the given Bundle, which must have been created with createBundle().

The bundle is then added to the bundle map. If another version of the same bundle is already loaded, a BundleVersionConflictException is thrown.

nextBundleId

int nextBundleId();

Returns a new unique bundle ID.

osArchitecture inline

const std::string & osArchitecture() const;

Returns the name of the hardware architecture.

osName inline

const std::string & osName() const;

Returns the name of the operating system.

pathForLibrary

std::string pathForLibrary(
    const std::string & libraryName
);

Returns the full path for the library with the given libraryName. If libraryName is the empty string, return the path to the code cache directory.

resolveAllBundles

void resolveAllBundles();

Resolves all bundles.

If a bundle cannot be resolved, an error is logged and the loader will continue to resolve other bundles.

startAllBundles

void startAllBundles();

Starts all bundles, ordered by their run level. If a bundle has the lazyStart property set, that bundle won't be started unless another bundle requires it.

Bundles with lower run levels will be started before bundles with higher run levels.

If a bundle cannot be started, an error will be logged, and the loader will continue to load other bundles.

stopAllBundles

void stopAllBundles();

Stops all bundles.

Bundles are stopped in order of their depedencies.

unloadAllBundles

void unloadAllBundles();

Stops and unloads all bundles.

unloadBundle

void unloadBundle(
    Bundle::Ptr pBundle
);

Unloads the given bundle.

The bundle is removed from the bundle map and its activator library, if loaded, is unloaded.

installLibraries protected

void installLibraries(
    Bundle * pBundle
);

Copies all shared libraries in the bundle (for the current platform) to the code cache.

installLibrary protected

void installLibrary(
    Bundle * pBundle,
    const Poco::Path & p,
    const Poco::Timestamp * pTS = 0
);

Copies the library to the code cache. If timestamp is provided, the file creation date is modified to the given time.

isProvidingModule protected static

static bool isProvidingModule(
    Bundle::Ptr pBundle,
    const BundleManifest::Dependency & module
);

Checks whether the given bundle provides the given module.

isResolving protected

bool isResolving(
    Bundle * pBundle
) const;

Returns true if and only if the given bundle is currently being resolved.

libraryNameFor protected

const std::string & libraryNameFor(
    Bundle * pBundle
);

Returns the library name for the library containing the activator for the given bundle.

libraryPathFor protected

std::string libraryPathFor(
    Bundle * pBundle
);

Returns the library path for the library containing the activator for the given bundle.

listLibraries protected

void listLibraries(
    Bundle * pBundle,
    std::vector < std::string > & list
);

Lists all shared libraries contained in the bundle for the current platform.

loadActivator protected

BundleActivator * loadActivator(
    BundleInfo & bundleInfo
);

Loads the activator for the given bundle, unless it has already been loaded.

makeValidFileName protected static

static void makeValidFileName(
    std::string & name
);

Replaces all non alphanumeric characters in name with an underscore.

resolveBundle protected

void resolveBundle(
    Bundle * pBundle
);

Resolves the given bundle.

resolveDependencies protected

void resolveDependencies(
    Bundle * pBundle,
    const BundleManifest::Dependencies & deps
);

Resolves all direct dependencies of the given bundle.

resolveDependency protected

void resolveDependency(
    Bundle * pBundle,
    const BundleManifest::Dependency & dependency
);

Resolves a single dependency of a bundle.

resolveModules protected

Bundle::ModuleProviders resolveModules(
    Bundle * pBundle
) const;

Determines the bundles providing the required modules.

resolveProviders protected

void resolveProviders(
    Bundle * pBundle,
    const Bundle::ModuleProviders & providers
);

Resolves the module providers for the given bundle.

sortBundles protected

void sortBundles(
    std::vector < Bundle::Ptr > & bundles
) const;

Sorts all bundles topologically, based on their dependencies.

The bundles are sorted in such a way so that bundles can be safely stopped in the resulting order.

startBundle protected

void startBundle(
    Bundle * pBundle
);

Starts the given bundle.

startDependencies protected

void startDependencies(
    Bundle * pBundle
);

Starts all bundles that the given bundle requires to run.

stopBundle protected

void stopBundle(
    Bundle * pBundle
);

Stops the given bundle.

uninstallBundle protected

void uninstallBundle(
    Bundle * pBundle
);

Uninstalls the given bundle.

uninstallLibraries protected

void uninstallLibraries(
    Bundle * pBundle
);

Removes all shared libraries belonging to the given bundle from the code cache.

unloadActivator protected

void unloadActivator(
    BundleInfo & bundleInfo
);

Unloads the activator for the given bundle.

Variables

bundleError

Poco::BasicEvent < const BundleError > bundleError;

Fired when an error occurs while resolving or starting a bundle.