From 32de23c976c632eab3b9cbcbe3ddf1107f9cec6a Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sat, 22 Feb 2003 23:46:59 +0000 Subject: [PATCH] Helper class: Represents a loaded add-on image. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2797 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/storage/AddOnImage.cpp | 54 +++++++++++++++++++++++++++++++++ src/kits/storage/AddOnImage.h | 32 +++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 src/kits/storage/AddOnImage.cpp create mode 100644 src/kits/storage/AddOnImage.h diff --git a/src/kits/storage/AddOnImage.cpp b/src/kits/storage/AddOnImage.cpp new file mode 100644 index 0000000000..2614153c5e --- /dev/null +++ b/src/kits/storage/AddOnImage.cpp @@ -0,0 +1,54 @@ +//---------------------------------------------------------------------- +// This software is part of the OpenBeOS distribution and is covered +// by the OpenBeOS license. +//--------------------------------------------------------------------- + +#include "AddOnImage.h" + +// constructor +AddOnImage::AddOnImage() + : fID(-1) +{ +} + +// destructor +AddOnImage::~AddOnImage() +{ + Unload(); +} + +// Load +status_t +AddOnImage::Load(const char *path) +{ + Unload(); + status_t error = (path ? B_OK : B_BAD_VALUE); + if (error == B_OK) { + image_id id = load_add_on(path); + if (id >= 0) + fID = id; + else + error = id; + } + return error; +} + +// Unload +void +AddOnImage::Unload() +{ + if (fID >= 0) { + unload_add_on(fID); + fID = -1; + } +} + +// SetID +void +AddOnImage::SetID(image_id id) +{ + Unload(); + if (id >= 0) + fID = id; +} + diff --git a/src/kits/storage/AddOnImage.h b/src/kits/storage/AddOnImage.h new file mode 100644 index 0000000000..48f0c2357c --- /dev/null +++ b/src/kits/storage/AddOnImage.h @@ -0,0 +1,32 @@ +//---------------------------------------------------------------------- +// This software is part of the OpenBeOS distribution and is covered +// by the OpenBeOS license. +//--------------------------------------------------------------------- + +#ifndef _ADD_ON_IMAGE_H +#define _ADD_ON_IMAGE_H + +#include + +namespace BPrivate { + +class AddOnImage { +public: + AddOnImage(); + ~AddOnImage(); + + status_t Load(const char *path); + void Unload(); + + void SetID(image_id id); + image_id ID() const { return fID; } + +private: + image_id fID; +}; + +} // namespace BPrivate + +using BPrivate::AddOnImage; + +#endif // _ADD_ON_IMAGE_H