The Pedigree Project 0.1
modules/drivers/hosted/diskimage/main.cc
1/*
2 * Copyright (c) 2008-2014, Pedigree Developers
3 *
4 * Please see the CONTRIB file in the root of the source tree for a full
5 * list of contributors.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20#include "DiskImage.h"
21#include "modules/Module.h"
22
23namespace {
24DiskImage* g_DiskImage = nullptr;
25
26Device* removeDiskImage(Device* device) {
27 if (device != g_DiskImage) {
28 return device;
29 }
30
31 g_DiskImage = nullptr;
32 return nullptr;
33}
34} // namespace
35
36bool entry() {
37 if (g_DiskImage) {
38 return true;
39 }
40
41 g_DiskImage = new DiskImage();
42 if (!g_DiskImage->initialise()) {
43 delete g_DiskImage;
44 g_DiskImage = nullptr;
45
46 // Don't mess up the rest of the startup - we may still be able to
47 // run without a disk.
48 return true;
49 }
50
51 Device::addToRoot(g_DiskImage);
52 return true;
53}
54
55void exit() {
56 if (!g_DiskImage) {
57 return;
58 }
59
60 Device::foreach (removeDiskImage);
61 if (g_DiskImage) {
62 delete g_DiskImage;
63 g_DiskImage = nullptr;
64 }
65}
66
67MODULE_INFO("diskimage", &entry, &exit);
static void addToRoot(Device *device)
Definition Device.cc:114
static void foreach(Callback callback, Device *root=0)
Definition Device.cc:107