1 | /** @file
|
---|
2 | *
|
---|
3 | * VirtualBox COM class implementation
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
18 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
19 | * additional information or have any questions.
|
---|
20 | */
|
---|
21 |
|
---|
22 | #ifndef ____H_DVDIMAGEIMPL
|
---|
23 | #define ____H_DVDIMAGEIMPL
|
---|
24 |
|
---|
25 | #include "VirtualBoxBase.h"
|
---|
26 | #include "Collection.h"
|
---|
27 |
|
---|
28 | #include <iprt/path.h>
|
---|
29 |
|
---|
30 | class VirtualBox;
|
---|
31 |
|
---|
32 | class ATL_NO_VTABLE DVDImage :
|
---|
33 | public VirtualBoxBaseNEXT,
|
---|
34 | public VirtualBoxSupportErrorInfoImpl <DVDImage, IDVDImage>,
|
---|
35 | public VirtualBoxSupportTranslation <DVDImage>,
|
---|
36 | public IDVDImage
|
---|
37 | {
|
---|
38 | public:
|
---|
39 |
|
---|
40 | VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (DVDImage)
|
---|
41 |
|
---|
42 | DECLARE_NOT_AGGREGATABLE(DVDImage)
|
---|
43 |
|
---|
44 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
45 |
|
---|
46 | BEGIN_COM_MAP(DVDImage)
|
---|
47 | COM_INTERFACE_ENTRY(ISupportErrorInfo)
|
---|
48 | COM_INTERFACE_ENTRY(IDVDImage)
|
---|
49 | END_COM_MAP()
|
---|
50 |
|
---|
51 | NS_DECL_ISUPPORTS
|
---|
52 |
|
---|
53 | DECLARE_EMPTY_CTOR_DTOR (DVDImage)
|
---|
54 |
|
---|
55 | HRESULT FinalConstruct();
|
---|
56 | void FinalRelease();
|
---|
57 |
|
---|
58 | // public initializer/uninitializer for internal purposes only
|
---|
59 | HRESULT init (VirtualBox *aParent, const BSTR aFilePath,
|
---|
60 | BOOL aRegistered, const Guid &aId);
|
---|
61 | void uninit();
|
---|
62 |
|
---|
63 | // IDVDImage properties
|
---|
64 | STDMETHOD(COMGETTER(Id)) (GUIDPARAMOUT aId);
|
---|
65 | STDMETHOD(COMGETTER(FilePath)) (BSTR *aFilePath);
|
---|
66 | STDMETHOD(COMGETTER(Accessible)) (BOOL *aAccessible);
|
---|
67 | STDMETHOD(COMGETTER(Size)) (ULONG64 *sSize);
|
---|
68 |
|
---|
69 | // public methods for internal purposes only
|
---|
70 | // (ensure there is a caller and a read lock before calling them!)
|
---|
71 |
|
---|
72 | const Bstr &filePath() { return mImageFile; }
|
---|
73 | const Bstr &filePathFull() { return mImageFileFull; }
|
---|
74 | const Guid &id() { return mUuid; }
|
---|
75 |
|
---|
76 | void updatePath (const char *aNewFullPath, const char *aNewPath);
|
---|
77 |
|
---|
78 | // for VirtualBoxSupportErrorInfoImpl
|
---|
79 | static const wchar_t *getComponentName() { return L"DVDImage"; }
|
---|
80 |
|
---|
81 | private:
|
---|
82 |
|
---|
83 | /** weak parent */
|
---|
84 | const ComObjPtr <VirtualBox, ComWeakRef> mParent;
|
---|
85 |
|
---|
86 | BOOL mAccessible;
|
---|
87 |
|
---|
88 | const Guid mUuid;
|
---|
89 | const Bstr mImageFile;
|
---|
90 | const Bstr mImageFileFull;
|
---|
91 | };
|
---|
92 |
|
---|
93 | COM_DECL_READONLY_ENUM_AND_COLLECTION_BEGIN (DVDImage)
|
---|
94 |
|
---|
95 | STDMETHOD(FindByPath) (INPTR BSTR aPath, IDVDImage **aDVDImage)
|
---|
96 | {
|
---|
97 | if (!aPath)
|
---|
98 | return E_INVALIDARG;
|
---|
99 | if (!aDVDImage)
|
---|
100 | return E_POINTER;
|
---|
101 |
|
---|
102 | Utf8Str path = aPath;
|
---|
103 | *aDVDImage = NULL;
|
---|
104 | Vector::value_type found;
|
---|
105 | Vector::iterator it = vec.begin();
|
---|
106 | while (it != vec.end() && !found)
|
---|
107 | {
|
---|
108 | Bstr filePath;
|
---|
109 | (*it)->COMGETTER(FilePath) (filePath.asOutParam());
|
---|
110 | if (RTPathCompare (Utf8Str (filePath), path) == 0)
|
---|
111 | found = *it;
|
---|
112 | ++ it;
|
---|
113 | }
|
---|
114 |
|
---|
115 | if (!found)
|
---|
116 | return setError (E_INVALIDARG, DVDImageCollection::tr (
|
---|
117 | "The DVD image named '%ls' could not be found"), aPath);
|
---|
118 |
|
---|
119 | return found.queryInterfaceTo (aDVDImage);
|
---|
120 | }
|
---|
121 |
|
---|
122 | COM_DECL_READONLY_ENUM_AND_COLLECTION_END (DVDImage)
|
---|
123 |
|
---|
124 |
|
---|
125 | #endif // ____H_DVDIMAGEIMPL
|
---|