1 | /** @file
|
---|
2 | *
|
---|
3 | * VirtualBox COM class implementation
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2011 Oracle Corporation
|
---|
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 |
|
---|
18 | #include "GuestDirEntryImpl.h"
|
---|
19 | #include "GuestCtrlImplPrivate.h"
|
---|
20 | #include "Global.h"
|
---|
21 |
|
---|
22 | #include "AutoCaller.h"
|
---|
23 | #include "Logging.h"
|
---|
24 |
|
---|
25 | // constructor / destructor
|
---|
26 | /////////////////////////////////////////////////////////////////////////////
|
---|
27 |
|
---|
28 | DEFINE_EMPTY_CTOR_DTOR(GuestDirEntry)
|
---|
29 |
|
---|
30 | HRESULT GuestDirEntry::FinalConstruct()
|
---|
31 | {
|
---|
32 | LogFlowThisFunc(("\n"));
|
---|
33 | return BaseFinalConstruct();
|
---|
34 | }
|
---|
35 |
|
---|
36 | void GuestDirEntry::FinalRelease()
|
---|
37 | {
|
---|
38 | LogFlowThisFuncEnter();
|
---|
39 | uninit();
|
---|
40 | BaseFinalRelease();
|
---|
41 | LogFlowThisFuncLeave();
|
---|
42 | }
|
---|
43 |
|
---|
44 | // public initializer/uninitializer for internal purposes only
|
---|
45 | /////////////////////////////////////////////////////////////////////////////
|
---|
46 |
|
---|
47 | HRESULT GuestDirEntry::init(Guest *aParent, GuestProcessStreamBlock &streamBlock)
|
---|
48 | {
|
---|
49 | LogFlowThisFunc(("aParent=%p\n", aParent));
|
---|
50 |
|
---|
51 | /* Enclose the state transition NotReady->InInit->Ready. */
|
---|
52 | AutoInitSpan autoInitSpan(this);
|
---|
53 | AssertReturn(autoInitSpan.isOk(), E_FAIL);
|
---|
54 |
|
---|
55 | mData.mNodeId = streamBlock.GetInt64("node_id");
|
---|
56 | mData.mName = BstrFmt("%s", streamBlock.GetString("name"));
|
---|
57 | mData.mType = GuestDirEntry::fileTypeToEntryType(streamBlock.GetString("ftype"));
|
---|
58 |
|
---|
59 | /* Confirm a successful initialization when it's the case. */
|
---|
60 | autoInitSpan.setSucceeded();
|
---|
61 |
|
---|
62 | return S_OK;
|
---|
63 | }
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * Uninitializes the instance.
|
---|
67 | * Called from FinalRelease().
|
---|
68 | */
|
---|
69 | void GuestDirEntry::uninit()
|
---|
70 | {
|
---|
71 | LogFlowThisFunc(("\n"));
|
---|
72 |
|
---|
73 | /* Enclose the state transition Ready->InUninit->NotReady. */
|
---|
74 | AutoUninitSpan autoUninitSpan(this);
|
---|
75 | if (autoUninitSpan.uninitDone())
|
---|
76 | return;
|
---|
77 | }
|
---|
78 |
|
---|
79 | STDMETHODIMP GuestDirEntry::COMGETTER(NodeId)(LONG64 *aNodeId)
|
---|
80 | {
|
---|
81 | LogFlowThisFuncEnter();
|
---|
82 |
|
---|
83 | CheckComArgOutPointerValid(aNodeId);
|
---|
84 |
|
---|
85 | AutoCaller autoCaller(this);
|
---|
86 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
87 |
|
---|
88 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
89 |
|
---|
90 | *aNodeId = mData.mNodeId;
|
---|
91 |
|
---|
92 | return S_OK;
|
---|
93 | }
|
---|
94 |
|
---|
95 | STDMETHODIMP GuestDirEntry::COMGETTER(Name)(BSTR *aName)
|
---|
96 | {
|
---|
97 | LogFlowThisFuncEnter();
|
---|
98 |
|
---|
99 | CheckComArgOutPointerValid(aName);
|
---|
100 |
|
---|
101 | AutoCaller autoCaller(this);
|
---|
102 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
103 |
|
---|
104 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
105 |
|
---|
106 | mData.mName.cloneTo(aName);
|
---|
107 |
|
---|
108 | return S_OK;
|
---|
109 | }
|
---|
110 |
|
---|
111 | STDMETHODIMP GuestDirEntry::COMGETTER(Type)(GuestDirEntryType_T *aType)
|
---|
112 | {
|
---|
113 | LogFlowThisFuncEnter();
|
---|
114 |
|
---|
115 | CheckComArgOutPointerValid(aType);
|
---|
116 |
|
---|
117 | AutoCaller autoCaller(this);
|
---|
118 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
119 |
|
---|
120 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
121 |
|
---|
122 | *aType = mData.mType;
|
---|
123 |
|
---|
124 | return S_OK;
|
---|
125 | }
|
---|
126 |
|
---|
127 | GuestDirEntryType_T GuestDirEntry::fileTypeToEntryType(const char *pszFileType)
|
---|
128 | {
|
---|
129 | GuestDirEntryType_T retType = GuestDirEntryType_Unknown;
|
---|
130 |
|
---|
131 | if (!pszFileType)
|
---|
132 | return retType;
|
---|
133 |
|
---|
134 | if (!RTStrICmp(pszFileType, "-"))
|
---|
135 | retType = GuestDirEntryType_File;
|
---|
136 | else if (!RTStrICmp(pszFileType, "d"))
|
---|
137 | retType = GuestDirEntryType_Directory;
|
---|
138 | else if (!RTStrICmp(pszFileType, "l"))
|
---|
139 | retType = GuestDirEntryType_Symlink;
|
---|
140 | /** @todo Add more types here. */
|
---|
141 |
|
---|
142 | return retType;
|
---|
143 | }
|
---|
144 |
|
---|