1717 * under the License.
1818 */
1919
20- #include "bundle_revision_private.h"
21-
2220#include "celix_bundle_manifest.h"
2321#include "celix_bundle_private.h"
2422#include "celix_module.h"
2725#include "framework_private.h"
2826#include "utils.h"
2927#include "celix_file_utils.h"
30- #include "bundle_archive_private.h"
3128#include "bundle_context_private.h"
3229#include "service_tracker_private.h"
3330
3431#include <stdlib.h>
3532#include <string.h>
3633#include <assert.h>
34+ #include <celix_constants.h>
3735#include <unistd.h>
3836
3937static char * celix_bundle_getBundleOrPersistentStoreEntry (const celix_bundle_t * bnd , bool bundleEntry , const char * name );
4038celix_status_t bundle_createModule (bundle_pt bundle , celix_module_t * * module );
4139celix_status_t bundle_closeRevisions (const_bundle_pt bundle );
4240
43- celix_status_t celix_bundle_createFromArchive (celix_framework_t * framework , bundle_archive_pt archive , celix_bundle_t * * bundleOut ) {
41+ celix_status_t celix_bundle_createFromArchive (celix_framework_t * framework , celix_bundle_archive_t * archive , celix_bundle_t * * bundleOut ) {
4442 celix_status_t status = CELIX_SUCCESS ;
4543 celix_bundle_t * bundle = calloc (1 , sizeof (* bundle ));
4644
@@ -92,7 +90,7 @@ celix_status_t bundle_destroy(bundle_pt bundle) {
9290 return CELIX_SUCCESS ;
9391}
9492
95- celix_status_t bundle_getArchive (const_bundle_pt bundle , bundle_archive_pt * archive ) {
93+ celix_status_t bundle_getArchive (const_bundle_pt bundle , celix_bundle_archive_t * * archive ) {
9694 celix_status_t status = CELIX_SUCCESS ;
9795 if (bundle != NULL && * archive == NULL ) {
9896 * archive = bundle -> archive ;
@@ -201,22 +199,16 @@ celix_status_t bundle_addModule(bundle_pt bundle, celix_module_t* module) {
201199 return CELIX_SUCCESS ;
202200}
203201
204- celix_status_t bundle_isSystemBundle (const_bundle_pt bundle , bool * systemBundle ) {
205- celix_status_t status ;
206- long bundleId ;
207- bundle_archive_pt archive = NULL ;
208-
209- status = bundle_getArchive (bundle , & archive );
210- if (status == CELIX_SUCCESS ) {
211- status = bundleArchive_getId (archive , & bundleId );
212- if (status == CELIX_SUCCESS ) {
213- * systemBundle = (bundleId == 0 );
214- }
215- }
216-
217- framework_logIfError (bundle -> framework -> logger , status , NULL , "Failed to check if bundle is the systembundle" );
218-
219- return status ;
202+ celix_status_t bundle_isSystemBundle (const_bundle_pt bundle , bool * systemBundle ) {
203+ celix_bundle_archive_t * archive = celix_bundle_getArchive (bundle );
204+ if (archive ) {
205+ long bundleId = celix_bundleArchive_getId (archive );
206+ * systemBundle = (bundleId == CELIX_FRAMEWORK_BUNDLE_ID );
207+ } else {
208+ fw_log (bundle -> framework -> logger , CELIX_LOG_LEVEL_ERROR , "Failed to check if bundle is the systembundle" );
209+ return CELIX_BUNDLE_EXCEPTION ;
210+ }
211+ return CELIX_SUCCESS ;
220212}
221213
222214celix_status_t bundle_getBundleId (const bundle_t * bundle , long * bndId ) {
@@ -239,31 +231,6 @@ celix_status_t bundle_getFramework(const_bundle_pt bundle, framework_pt *framewo
239231 return CELIX_SUCCESS ;
240232}
241233
242- celix_status_t bundle_getBundleLocation (const_bundle_pt bundle , const char * * location ){
243-
244- celix_status_t status ;
245-
246- bundle_archive_pt archive = NULL ;
247-
248- status = bundle_getArchive (bundle , & archive );
249- if (status != CELIX_SUCCESS ){
250- printf ("[ ERROR ]: Bundle - getBundleLocation (BundleArchive) \n" );
251- return status ;
252- }
253-
254- status = bundleArchive_getLocation (archive , location );
255- if (status != CELIX_SUCCESS ){
256- printf ("[ ERROR ]: Bundle - getBundleLocation (BundleArchiveLocation) \n" );
257- return status ;
258- }
259-
260- return CELIX_SUCCESS ;
261- }
262-
263-
264-
265-
266-
267234
268235/**********************************************************************************************************************
269236 **********************************************************************************************************************
@@ -272,25 +239,25 @@ celix_status_t bundle_getBundleLocation(const_bundle_pt bundle, const char **loc
272239 **********************************************************************************************************************/
273240
274241long celix_bundle_getId (const bundle_t * bnd ) {
275- long bndId = -1 ;
276- bundle_archive_pt archive = NULL ;
277- bundle_getArchive (( bundle_t * ) bnd , & archive );
278- if ( archive != NULL ) {
279- bundleArchive_getId ( archive , & bndId );
280- }
281-
282- if ( bndId < 0 ) {
283- framework_logIfError ( celix_frameworkLogger_globalLogger (), CELIX_BUNDLE_EXCEPTION , NULL , "Failed to get bundle id" );
284- }
285- return bndId ;
242+ long bndId = -1 ;
243+ celix_bundle_archive_t * archive = celix_bundle_getArchive ( bnd ) ;
244+ if ( archive ) {
245+ bndId = celix_bundleArchive_getId ( archive );
246+ } else {
247+ framework_logIfError ( celix_frameworkLogger_globalLogger (),
248+ CELIX_BUNDLE_EXCEPTION ,
249+ NULL ,
250+ "Failed to get bundle id" );
251+ }
252+ return bndId ;
286253}
287254
288255celix_bundle_state_e celix_bundle_getState (const celix_bundle_t * bnd ) {
289256 return __atomic_load_n (& bnd -> state , __ATOMIC_ACQUIRE );
290257}
291258
292259static char * celix_bundle_getBundleOrPersistentStoreEntry (const celix_bundle_t * bnd , bool bundleEntry , const char * name ) {
293- bundle_archive_pt archive = NULL ;
260+ celix_bundle_archive_t * archive = NULL ;
294261 celix_status_t status = bundle_getArchive (bnd , & archive );
295262 if (status != CELIX_SUCCESS ) {
296263 fw_logCode (bnd -> framework -> logger , CELIX_BUNDLE_EXCEPTION , status , "Failed to get bundle archive" );
@@ -373,7 +340,11 @@ const char* celix_bundle_getDescription(const celix_bundle_t* bnd) {
373340char * celix_bundle_getLocation (const celix_bundle_t * bnd ) {
374341 char * result = NULL ;
375342 if (bnd -> archive != NULL ) {
376- result = celix_bundleArchive_getLocation (bnd -> archive );
343+ const char * loc = celix_bundleArchive_getLocation (bnd -> archive );
344+ result = celix_utils_strdup (loc );
345+ if (!result ) {
346+ fw_log (bnd -> framework -> logger , CELIX_BUNDLE_EXCEPTION , "Failed to allocate memory for bundle location" );
347+ }
377348 }
378349 return result ;
379350}
@@ -454,8 +425,8 @@ celix_array_list_t* celix_bundle_listServiceTrackers(const celix_bundle_t *bnd)
454425 return result ;
455426}
456427
457- bundle_archive_t * celix_bundle_getArchive (const celix_bundle_t * bundle ) {
458- bundle_archive_t * archive = NULL ;
459- bundle_getArchive (bundle , & archive );
428+ celix_bundle_archive_t * celix_bundle_getArchive (const celix_bundle_t * bundle ) {
429+ celix_bundle_archive_t * archive = NULL ;
430+ ( void ) bundle_getArchive (bundle , & archive );
460431 return archive ;
461432}
0 commit comments