xref: /haiku/src/kits/storage/AddOnImage.cpp (revision 51978af14a173e7fae0563b562be5603bc652aeb)
1 //----------------------------------------------------------------------
2 //  This software is part of the OpenBeOS distribution and is covered
3 //  by the OpenBeOS license.
4 //---------------------------------------------------------------------
5 
6 #include "AddOnImage.h"
7 
8 // constructor
9 AddOnImage::AddOnImage()
10 	: fID(-1)
11 {
12 }
13 
14 // destructor
15 AddOnImage::~AddOnImage()
16 {
17 	Unload();
18 }
19 
20 // Load
21 status_t
22 AddOnImage::Load(const char *path)
23 {
24 	Unload();
25 	status_t error = (path ? B_OK : B_BAD_VALUE);
26 	if (error == B_OK) {
27 		image_id id = load_add_on(path);
28 		if (id >= 0)
29 			fID = id;
30 		else
31 			error = id;
32 	}
33 	return error;
34 }
35 
36 // Unload
37 void
38 AddOnImage::Unload()
39 {
40 	if (fID >= 0) {
41 		unload_add_on(fID);
42 		fID = -1;
43 	}
44 }
45 
46 // SetID
47 void
48 AddOnImage::SetID(image_id id)
49 {
50 	Unload();
51 	if (id >= 0)
52 		fID = id;
53 }
54 
55