BundleMetadata const& BundleLoader::createBundleEx( std::string const& path, void ( *MetainfoFunc )( bundle::BundleMetainfo & ) )
	{
		Metainfo *info = new Metainfo();

		try
		{
			BundleInfo bundleInfo;
			bundle::BundleMetainfo metainfo( *info );
			MetainfoFunc( metainfo );
			bundleInfo.metainfo = info;
			bundleInfo.metainfo->setInstallDirectory( path );
			bundleInfo.metainfo->cleanup();
			m_LoadedBundles.insert( make_pair( path, bundleInfo ) );
		}
		catch ( Exception &e )
		{
			delete info;
			throw e;
		}

		BundleMetadata const& meta = info->getBundleData();
		if ( meta.getName() == "undefined" )
		{
			ostringstream msg;
			msg << "bundle " << meta.getInstallDirectory() << " does not define a name";
			throw NotFoundException( msg.str() );
		}

		return meta;
	}
Exemple #2
0
int main() {
    std::string path(TORRENT_FILE);
    MetaInfo metainfo(path);

    assert(metainfo.tracker_url == "http://torrent.ubuntu.com:6969/announce");
    assert(metainfo.piece_length == 524288);

    assert(metainfo.files.size() == 1);
    assert(metainfo.files[0].name == "ubuntu-12.10-desktop-amd64.iso");
    assert(metainfo.files[0].length == 800063488);
}
	BundleMetadata const& BundleLoader::loadLibrary( string const& path )
	{
		if ( isLibraryLoaded( path ) )
		{
			BundleInfoConstIterator it = m_LoadedBundles.find( path );
			return it->second.metainfo->getBundleData();
		}

		typedef void ( *MetainfoFunc )( bundle::BundleMetainfo &info );

		Poco::SharedLibrary *lib;
		try
		{
			lib = new Poco::SharedLibrary( path );
		}
		catch ( Poco::Exception &e )
		{
			ostringstream msg;
			msg << e.what() << " " << e.message() << " lib could not be loaded";
			throw NotFoundException( msg.str() );
		}

		Metainfo *info = new Metainfo();

		if ( lib->hasSymbol( "getBundleMetainfo" ) )
		{
			try
			{
				BundleInfo bundleInfo;
				MetainfoFunc func = ( MetainfoFunc ) lib->getSymbol( "getBundleMetainfo" );

				bundle::BundleMetainfo metainfo( *info );
				func( metainfo );
				bundleInfo.library = lib;
				bundleInfo.metainfo = info;

				bundleInfo.metainfo->setInstallDirectory( path );
				bundleInfo.metainfo->cleanup();

				m_LoadedBundles.insert( make_pair( path, bundleInfo ) );
			}
			catch ( Exception &e )
			{
				delete lib;
				delete info;
				throw e;
			}
			BundleMetadata const& meta = info->getBundleData();
			if ( meta.getName() == "undefined" )
			{
				ostringstream msg;
				msg << "bundle " << meta.getInstallDirectory() << " does not define a name";
				throw NotFoundException( msg.str() );
			}

			return meta;
		}
		else
		{
			delete lib;
			delete info;

			ostringstream msg;
			msg << "shared library " << path << " does not contain metadata";
			throw NotFoundException( msg.str() );
		}
	}