1/* 2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7#include "GlobalFactory.h" 8 9#include <new> 10 11#include <package/hpkg/HPKGDefsPrivate.h> 12 13 14static const uint32 kMaxCachedBuffers = 32; 15 16/*static*/ GlobalFactory* GlobalFactory::sDefaultInstance = NULL; 17 18 19GlobalFactory::GlobalFactory() 20 : 21 fBufferCache(B_HPKG_DEFAULT_DATA_CHUNK_SIZE_ZLIB, kMaxCachedBuffers), 22 fPackageDataReaderFactory(&fBufferCache) 23{ 24} 25 26 27GlobalFactory::~GlobalFactory() 28{ 29} 30 31 32/*static*/ status_t 33GlobalFactory::CreateDefault() 34{ 35 if (sDefaultInstance != NULL) 36 return B_OK; 37 38 GlobalFactory* factory = new(std::nothrow) GlobalFactory; 39 if (factory == NULL) 40 return B_NO_MEMORY; 41 42 status_t error = factory->_Init(); 43 if (error != B_OK) { 44 delete factory; 45 return error; 46 } 47 48 sDefaultInstance = factory; 49 return B_OK; 50} 51 52 53/*static*/ void 54GlobalFactory::DeleteDefault() 55{ 56 delete sDefaultInstance; 57 sDefaultInstance = NULL; 58} 59 60 61/*static*/ GlobalFactory* 62GlobalFactory::Default() 63{ 64 return sDefaultInstance; 65} 66 67 68status_t 69GlobalFactory::CreatePackageDataReader(BDataReader* dataReader, 70 const BPackageData& data, BPackageDataReader*& _reader) 71{ 72 return fPackageDataReaderFactory.CreatePackageDataReader(dataReader, data, 73 _reader); 74} 75 76 77status_t 78GlobalFactory::_Init() 79{ 80 status_t error = fBufferCache.Init(); 81 if (error != B_OK) 82 return error; 83 84 return B_OK; 85} 86