VirtualBox

source: vbox/trunk/src/VBox/Main/include/MachineImpl.h@ 26550

Last change on this file since 26550 was 26459, checked in by vboxsync, 15 years ago

Main: HPET machine property, cleanups

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 40.5 KB
Line 
1/* $Id: MachineImpl.h 26459 2010-02-12 11:42:36Z vboxsync $ */
2
3/** @file
4 *
5 * VirtualBox COM class declaration
6 */
7
8/*
9 * Copyright (C) 2006-2010 Sun Microsystems, Inc.
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
20 * Clara, CA 95054 USA or visit http://www.sun.com if you need
21 * additional information or have any questions.
22 */
23
24#ifndef ____H_MACHINEIMPL
25#define ____H_MACHINEIMPL
26
27#include "VirtualBoxBase.h"
28#include "SnapshotImpl.h"
29#include "VRDPServerImpl.h"
30#include "MediumAttachmentImpl.h"
31#include "NetworkAdapterImpl.h"
32#include "AudioAdapterImpl.h"
33#include "SerialPortImpl.h"
34#include "ParallelPortImpl.h"
35#include "BIOSSettingsImpl.h"
36#include "StorageControllerImpl.h" // required for MachineImpl.h to compile on Windows
37#include "VBox/settings.h"
38#ifdef VBOX_WITH_RESOURCE_USAGE_API
39#include "PerformanceImpl.h"
40#endif /* VBOX_WITH_RESOURCE_USAGE_API */
41
42// generated header
43#include "SchemaDefs.h"
44
45#include <VBox/types.h>
46
47#include <iprt/file.h>
48#include <iprt/thread.h>
49#include <iprt/time.h>
50
51#include <list>
52
53// defines
54////////////////////////////////////////////////////////////////////////////////
55
56// helper declarations
57////////////////////////////////////////////////////////////////////////////////
58
59class Progress;
60class Keyboard;
61class Mouse;
62class Display;
63class MachineDebugger;
64class USBController;
65class Snapshot;
66class SharedFolder;
67class HostUSBDevice;
68class StorageController;
69
70class SessionMachine;
71
72namespace settings
73{
74 class MachineConfigFile;
75 struct Snapshot;
76 struct Hardware;
77 struct Storage;
78 struct StorageController;
79 struct MachineRegistryEntry;
80}
81
82// Machine class
83////////////////////////////////////////////////////////////////////////////////
84
85class ATL_NO_VTABLE Machine :
86 public VirtualBoxBaseWithChildrenNEXT,
87 public VirtualBoxSupportErrorInfoImpl<Machine, IMachine>,
88 public VirtualBoxSupportTranslation<Machine>,
89 VBOX_SCRIPTABLE_IMPL(IMachine)
90{
91 Q_OBJECT
92
93public:
94
95 enum InitMode { Init_New, Init_Import, Init_Registered };
96
97 enum StateDependency
98 {
99 AnyStateDep = 0, MutableStateDep, MutableOrSavedStateDep
100 };
101
102 /**
103 * Internal machine data.
104 *
105 * Only one instance of this data exists per every machine -- it is shared
106 * by the Machine, SessionMachine and all SnapshotMachine instances
107 * associated with the given machine using the util::Shareable template
108 * through the mData variable.
109 *
110 * @note |const| members are persistent during lifetime so can be
111 * accessed without locking.
112 *
113 * @note There is no need to lock anything inside init() or uninit()
114 * methods, because they are always serialized (see AutoCaller).
115 */
116 struct Data
117 {
118 /**
119 * Data structure to hold information about sessions opened for the
120 * given machine.
121 */
122 struct Session
123 {
124 /** Control of the direct session opened by openSession() */
125 ComPtr<IInternalSessionControl> mDirectControl;
126
127 typedef std::list<ComPtr<IInternalSessionControl> > RemoteControlList;
128
129 /** list of controls of all opened remote sessions */
130 RemoteControlList mRemoteControls;
131
132 /** openRemoteSession() and OnSessionEnd() progress indicator */
133 ComObjPtr<Progress> mProgress;
134
135 /**
136 * PID of the session object that must be passed to openSession() to
137 * finalize the openRemoteSession() request (i.e., PID of the
138 * process created by openRemoteSession())
139 */
140 RTPROCESS mPid;
141
142 /** Current session state */
143 SessionState_T mState;
144
145 /** Session type string (for indirect sessions) */
146 Bstr mType;
147
148 /** Session machine object */
149 ComObjPtr<SessionMachine> mMachine;
150
151 /**
152 * Successfully locked media list. The 2nd value in the pair is true
153 * if the medium is locked for writing and false if locked for
154 * reading.
155 */
156 typedef std::list<std::pair<ComPtr<IMedium>, bool > > LockedMedia;
157 LockedMedia mLockedMedia;
158 };
159
160 Data();
161 ~Data();
162
163 const Guid mUuid;
164 BOOL mRegistered;
165 InitMode mInitMode;
166
167 /** Flag indicating that the config file is read-only. */
168 BOOL mConfigFileReadonly;
169 Utf8Str m_strConfigFile;
170 Utf8Str m_strConfigFileFull;
171
172 // machine settings XML file
173 settings::MachineConfigFile *m_pMachineConfigFile;
174
175 BOOL mAccessible;
176 com::ErrorInfo mAccessError;
177
178 MachineState_T mMachineState;
179 RTTIMESPEC mLastStateChange;
180
181 /* Note: These are guarded by VirtualBoxBase::stateLockHandle() */
182 uint32_t mMachineStateDeps;
183 RTSEMEVENTMULTI mMachineStateDepsSem;
184 uint32_t mMachineStateChangePending;
185
186 BOOL mCurrentStateModified;
187
188 RTFILE mHandleCfgFile;
189
190 Session mSession;
191
192 ComObjPtr<Snapshot> mFirstSnapshot;
193 ComObjPtr<Snapshot> mCurrentSnapshot;
194 };
195
196 /**
197 * Saved state data.
198 *
199 * It's actually only the state file path string, but it needs to be
200 * separate from Data, because Machine and SessionMachine instances
201 * share it, while SnapshotMachine does not.
202 *
203 * The data variable is |mSSData|.
204 */
205 struct SSData
206 {
207 Utf8Str mStateFilePath;
208 };
209
210 /**
211 * User changeable machine data.
212 *
213 * This data is common for all machine snapshots, i.e. it is shared
214 * by all SnapshotMachine instances associated with the given machine
215 * using the util::Backupable template through the |mUserData| variable.
216 *
217 * SessionMachine instances can alter this data and discard changes.
218 *
219 * @note There is no need to lock anything inside init() or uninit()
220 * methods, because they are always serialized (see AutoCaller).
221 */
222 struct UserData
223 {
224 UserData();
225 ~UserData();
226
227 Bstr mName;
228 BOOL mNameSync;
229 Bstr mDescription;
230 Bstr mOSTypeId;
231 Bstr mSnapshotFolder;
232 Bstr mSnapshotFolderFull;
233 BOOL mTeleporterEnabled;
234 ULONG mTeleporterPort;
235 Bstr mTeleporterAddress;
236 Bstr mTeleporterPassword;
237 BOOL mRTCUseUTC;
238 };
239
240 /**
241 * Hardware data.
242 *
243 * This data is unique for a machine and for every machine snapshot.
244 * Stored using the util::Backupable template in the |mHWData| variable.
245 *
246 * SessionMachine instances can alter this data and discard changes.
247 */
248 struct HWData
249 {
250 /**
251 * Data structure to hold information about a guest property.
252 */
253 struct GuestProperty {
254 /** Property name */
255 Utf8Str strName;
256 /** Property value */
257 Utf8Str strValue;
258 /** Property timestamp */
259 ULONG64 mTimestamp;
260 /** Property flags */
261 ULONG mFlags;
262 };
263
264 HWData();
265 ~HWData();
266
267 Bstr mHWVersion;
268 Guid mHardwareUUID; /**< If Null, use mData.mUuid. */
269 ULONG mMemorySize;
270 ULONG mMemoryBalloonSize;
271 ULONG mStatisticsUpdateInterval;
272 ULONG mVRAMSize;
273 ULONG mMonitorCount;
274 BOOL mHWVirtExEnabled;
275 BOOL mHWVirtExExclusive;
276 BOOL mHWVirtExNestedPagingEnabled;
277 BOOL mHWVirtExVPIDEnabled;
278 BOOL mAccelerate2DVideoEnabled;
279 BOOL mPAEEnabled;
280 BOOL mSyntheticCpu;
281 ULONG mCPUCount;
282 BOOL mCPUHotPlugEnabled;
283 BOOL mAccelerate3DEnabled;
284 BOOL mHpetEnabled;
285
286 BOOL mCPUAttached[SchemaDefs::MaxCPUCount];
287
288 settings::CpuIdLeaf mCpuIdStdLeafs[10];
289 settings::CpuIdLeaf mCpuIdExtLeafs[10];
290
291 DeviceType_T mBootOrder[SchemaDefs::MaxBootPosition];
292
293 typedef std::list< ComObjPtr<SharedFolder> > SharedFolderList;
294 SharedFolderList mSharedFolders;
295
296 ClipboardMode_T mClipboardMode;
297
298 typedef std::list<GuestProperty> GuestPropertyList;
299 GuestPropertyList mGuestProperties;
300 BOOL mPropertyServiceActive;
301 Utf8Str mGuestPropertyNotificationPatterns;
302
303 FirmwareType_T mFirmwareType;
304 KeyboardHidType_T mKeyboardHidType;
305 PointingHidType_T mPointingHidType;
306 };
307
308 /**
309 * Hard disk and other media data.
310 *
311 * The usage policy is the same as for HWData, but a separate structure
312 * is necessary because hard disk data requires different procedures when
313 * taking or discarding snapshots, etc.
314 *
315 * The data variable is |mMediaData|.
316 */
317 struct MediaData
318 {
319 MediaData();
320 ~MediaData();
321
322 typedef std::list< ComObjPtr<MediumAttachment> > AttachmentList;
323 AttachmentList mAttachments;
324 };
325
326 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Machine)
327
328 DECLARE_NOT_AGGREGATABLE(Machine)
329
330 DECLARE_PROTECT_FINAL_CONSTRUCT()
331
332 BEGIN_COM_MAP(Machine)
333 COM_INTERFACE_ENTRY(ISupportErrorInfo)
334 COM_INTERFACE_ENTRY(IMachine)
335 COM_INTERFACE_ENTRY(IDispatch)
336 END_COM_MAP()
337
338 DECLARE_EMPTY_CTOR_DTOR(Machine)
339
340 HRESULT FinalConstruct();
341 void FinalRelease();
342
343 // public initializer/uninitializer for internal purposes only
344 HRESULT init(VirtualBox *aParent,
345 const Utf8Str &strConfigFile,
346 InitMode aMode,
347 CBSTR aName = NULL,
348 GuestOSType *aOsType = NULL,
349 BOOL aNameSync = TRUE,
350 const Guid *aId = NULL);
351 void uninit();
352
353protected:
354 HRESULT initDataAndChildObjects();
355 void uninitDataAndChildObjects();
356
357public:
358 // IMachine properties
359 STDMETHOD(COMGETTER(Parent))(IVirtualBox **aParent);
360 STDMETHOD(COMGETTER(Accessible))(BOOL *aAccessible);
361 STDMETHOD(COMGETTER(AccessError))(IVirtualBoxErrorInfo **aAccessError);
362 STDMETHOD(COMGETTER(Name))(BSTR *aName);
363 STDMETHOD(COMSETTER(Name))(IN_BSTR aName);
364 STDMETHOD(COMGETTER(Description))(BSTR *aDescription);
365 STDMETHOD(COMSETTER(Description))(IN_BSTR aDescription);
366 STDMETHOD(COMGETTER(Id))(BSTR *aId);
367 STDMETHOD(COMGETTER(OSTypeId))(BSTR *aOSTypeId);
368 STDMETHOD(COMSETTER(OSTypeId))(IN_BSTR aOSTypeId);
369 STDMETHOD(COMGETTER(HardwareVersion))(BSTR *aVersion);
370 STDMETHOD(COMSETTER(HardwareVersion))(IN_BSTR aVersion);
371 STDMETHOD(COMGETTER(HardwareUUID))(BSTR *aUUID);
372 STDMETHOD(COMSETTER(HardwareUUID))(IN_BSTR aUUID);
373 STDMETHOD(COMGETTER(MemorySize))(ULONG *memorySize);
374 STDMETHOD(COMSETTER(MemorySize))(ULONG memorySize);
375 STDMETHOD(COMGETTER(CPUCount))(ULONG *cpuCount);
376 STDMETHOD(COMSETTER(CPUCount))(ULONG cpuCount);
377 STDMETHOD(COMGETTER(CPUHotPlugEnabled))(BOOL *enabled);
378 STDMETHOD(COMSETTER(CPUHotPlugEnabled))(BOOL enabled);
379 STDMETHOD(COMGETTER(HpetEnabled))(BOOL *enabled);
380 STDMETHOD(COMSETTER(HpetEnabled))(BOOL enabled);
381 STDMETHOD(COMGETTER(MemoryBalloonSize))(ULONG *memoryBalloonSize);
382 STDMETHOD(COMSETTER(MemoryBalloonSize))(ULONG memoryBalloonSize);
383 STDMETHOD(COMGETTER(StatisticsUpdateInterval))(ULONG *statisticsUpdateInterval);
384 STDMETHOD(COMSETTER(StatisticsUpdateInterval))(ULONG statisticsUpdateInterval);
385 STDMETHOD(COMGETTER(VRAMSize))(ULONG *memorySize);
386 STDMETHOD(COMSETTER(VRAMSize))(ULONG memorySize);
387 STDMETHOD(COMGETTER(MonitorCount))(ULONG *monitorCount);
388 STDMETHOD(COMSETTER(MonitorCount))(ULONG monitorCount);
389 STDMETHOD(COMGETTER(Accelerate3DEnabled))(BOOL *enabled);
390 STDMETHOD(COMSETTER(Accelerate3DEnabled))(BOOL enabled);
391 STDMETHOD(COMGETTER(Accelerate2DVideoEnabled))(BOOL *enabled);
392 STDMETHOD(COMSETTER(Accelerate2DVideoEnabled))(BOOL enabled);
393 STDMETHOD(COMGETTER(BIOSSettings))(IBIOSSettings **biosSettings);
394 STDMETHOD(COMGETTER(SnapshotFolder))(BSTR *aSavedStateFolder);
395 STDMETHOD(COMSETTER(SnapshotFolder))(IN_BSTR aSavedStateFolder);
396 STDMETHOD(COMGETTER(MediumAttachments))(ComSafeArrayOut(IMediumAttachment *, aAttachments));
397 STDMETHOD(COMGETTER(VRDPServer))(IVRDPServer **vrdpServer);
398 STDMETHOD(COMGETTER(AudioAdapter))(IAudioAdapter **audioAdapter);
399 STDMETHOD(COMGETTER(USBController))(IUSBController * *aUSBController);
400 STDMETHOD(COMGETTER(SettingsFilePath))(BSTR *aFilePath);
401 STDMETHOD(COMGETTER(SettingsModified))(BOOL *aModified);
402 STDMETHOD(COMGETTER(SessionState))(SessionState_T *aSessionState);
403 STDMETHOD(COMGETTER(SessionType))(BSTR *aSessionType);
404 STDMETHOD(COMGETTER(SessionPid))(ULONG *aSessionPid);
405 STDMETHOD(COMGETTER(State))(MachineState_T *machineState);
406 STDMETHOD(COMGETTER(LastStateChange))(LONG64 *aLastStateChange);
407 STDMETHOD(COMGETTER(StateFilePath))(BSTR *aStateFilePath);
408 STDMETHOD(COMGETTER(LogFolder))(BSTR *aLogFolder);
409 STDMETHOD(COMGETTER(CurrentSnapshot))(ISnapshot **aCurrentSnapshot);
410 STDMETHOD(COMGETTER(SnapshotCount))(ULONG *aSnapshotCount);
411 STDMETHOD(COMGETTER(CurrentStateModified))(BOOL *aCurrentStateModified);
412 STDMETHOD(COMGETTER(SharedFolders))(ComSafeArrayOut(ISharedFolder *, aSharedFolders));
413 STDMETHOD(COMGETTER(ClipboardMode))(ClipboardMode_T *aClipboardMode);
414 STDMETHOD(COMSETTER(ClipboardMode))(ClipboardMode_T aClipboardMode);
415 STDMETHOD(COMGETTER(GuestPropertyNotificationPatterns))(BSTR *aPattern);
416 STDMETHOD(COMSETTER(GuestPropertyNotificationPatterns))(IN_BSTR aPattern);
417 STDMETHOD(COMGETTER(StorageControllers))(ComSafeArrayOut(IStorageController *, aStorageControllers));
418 STDMETHOD(COMGETTER(TeleporterEnabled))(BOOL *aEnabled);
419 STDMETHOD(COMSETTER(TeleporterEnabled))(BOOL aEnabled);
420 STDMETHOD(COMGETTER(TeleporterPort))(ULONG *aPort);
421 STDMETHOD(COMSETTER(TeleporterPort))(ULONG aPort);
422 STDMETHOD(COMGETTER(TeleporterAddress))(BSTR *aAddress);
423 STDMETHOD(COMSETTER(TeleporterAddress))(IN_BSTR aAddress);
424 STDMETHOD(COMGETTER(TeleporterPassword))(BSTR *aPassword);
425 STDMETHOD(COMSETTER(TeleporterPassword))(IN_BSTR aPassword);
426 STDMETHOD(COMGETTER(RTCUseUTC))(BOOL *aEnabled);
427 STDMETHOD(COMSETTER(RTCUseUTC))(BOOL aEnabled);
428 STDMETHOD(COMGETTER(FirmwareType)) (FirmwareType_T *aFirmware);
429 STDMETHOD(COMSETTER(FirmwareType)) (FirmwareType_T aFirmware);
430 STDMETHOD(COMGETTER(KeyboardHidType)) (KeyboardHidType_T *aKeyboardHidType);
431 STDMETHOD(COMSETTER(KeyboardHidType)) (KeyboardHidType_T aKeyboardHidType);
432 STDMETHOD(COMGETTER(PointingHidType)) (PointingHidType_T *aPointingHidType);
433 STDMETHOD(COMSETTER(PointingHidType)) (PointingHidType_T aPointingHidType);
434
435 // IMachine methods
436 STDMETHOD(SetBootOrder)(ULONG aPosition, DeviceType_T aDevice);
437 STDMETHOD(GetBootOrder)(ULONG aPosition, DeviceType_T *aDevice);
438 STDMETHOD(AttachDevice)(IN_BSTR aControllerName, LONG aControllerPort,
439 LONG aDevice, DeviceType_T aType, IN_BSTR aId);
440 STDMETHOD(DetachDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice);
441 STDMETHOD(PassthroughDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice, BOOL aPassthrough);
442 STDMETHOD(MountMedium)(IN_BSTR aControllerName, LONG aControllerPort,
443 LONG aDevice, IN_BSTR aId, BOOL aForce);
444 STDMETHOD(GetMedium)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice,
445 IMedium **aMedium);
446 STDMETHOD(GetSerialPort)(ULONG slot, ISerialPort **port);
447 STDMETHOD(GetParallelPort)(ULONG slot, IParallelPort **port);
448 STDMETHOD(GetNetworkAdapter)(ULONG slot, INetworkAdapter **adapter);
449 STDMETHOD(GetExtraDataKeys)(ComSafeArrayOut(BSTR, aKeys));
450 STDMETHOD(GetExtraData)(IN_BSTR aKey, BSTR *aValue);
451 STDMETHOD(SetExtraData)(IN_BSTR aKey, IN_BSTR aValue);
452 STDMETHOD(GetCpuProperty)(CpuPropertyType_T property, BOOL *aVal);
453 STDMETHOD(SetCpuProperty)(CpuPropertyType_T property, BOOL aVal);
454 STDMETHOD(GetCpuIdLeaf)(ULONG id, ULONG *aValEax, ULONG *aValEbx, ULONG *aValEcx, ULONG *aValEdx);
455 STDMETHOD(SetCpuIdLeaf)(ULONG id, ULONG aValEax, ULONG aValEbx, ULONG aValEcx, ULONG aValEdx);
456 STDMETHOD(RemoveCpuIdLeaf)(ULONG id);
457 STDMETHOD(RemoveAllCpuIdLeafs)();
458 STDMETHOD(GetHWVirtExProperty)(HWVirtExPropertyType_T property, BOOL *aVal);
459 STDMETHOD(SetHWVirtExProperty)(HWVirtExPropertyType_T property, BOOL aVal);
460 STDMETHOD(SaveSettings)();
461 STDMETHOD(DiscardSettings)();
462 STDMETHOD(DeleteSettings)();
463 STDMETHOD(Export)(IAppliance *aAppliance, IVirtualSystemDescription **aDescription);
464 STDMETHOD(GetSnapshot)(IN_BSTR aId, ISnapshot **aSnapshot);
465 STDMETHOD(FindSnapshot)(IN_BSTR aName, ISnapshot **aSnapshot);
466 STDMETHOD(SetCurrentSnapshot)(IN_BSTR aId);
467 STDMETHOD(CreateSharedFolder)(IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable);
468 STDMETHOD(RemoveSharedFolder)(IN_BSTR aName);
469 STDMETHOD(CanShowConsoleWindow)(BOOL *aCanShow);
470 STDMETHOD(ShowConsoleWindow)(ULONG64 *aWinId);
471 STDMETHOD(GetGuestProperty)(IN_BSTR aName, BSTR *aValue, ULONG64 *aTimestamp, BSTR *aFlags);
472 STDMETHOD(GetGuestPropertyValue)(IN_BSTR aName, BSTR *aValue);
473 STDMETHOD(GetGuestPropertyTimestamp)(IN_BSTR aName, ULONG64 *aTimestamp);
474 STDMETHOD(SetGuestProperty)(IN_BSTR aName, IN_BSTR aValue, IN_BSTR aFlags);
475 STDMETHOD(SetGuestPropertyValue)(IN_BSTR aName, IN_BSTR aValue);
476 STDMETHOD(EnumerateGuestProperties)(IN_BSTR aPattern, ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues), ComSafeArrayOut(ULONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
477 STDMETHOD(GetMediumAttachmentsOfController)(IN_BSTR aName, ComSafeArrayOut(IMediumAttachment *, aAttachments));
478 STDMETHOD(GetMediumAttachment)(IN_BSTR aConstrollerName, LONG aControllerPort, LONG aDevice, IMediumAttachment **aAttachment);
479 STDMETHOD(AddStorageController)(IN_BSTR aName, StorageBus_T aConnectionType, IStorageController **controller);
480 STDMETHOD(RemoveStorageController(IN_BSTR aName));
481 STDMETHOD(GetStorageControllerByName(IN_BSTR aName, IStorageController **storageController));
482 STDMETHOD(GetStorageControllerByInstance(ULONG aInstance, IStorageController **storageController));
483 STDMETHOD(QuerySavedThumbnailSize)(ULONG *aSize, ULONG *aWidth, ULONG *aHeight);
484 STDMETHOD(ReadSavedThumbnailToArray)(BOOL aBGR, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
485 STDMETHOD(QuerySavedScreenshotPNGSize)(ULONG *aSize, ULONG *aWidth, ULONG *aHeight);
486 STDMETHOD(ReadSavedScreenshotPNGToArray)(ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
487 STDMETHOD(HotPlugCPU(ULONG aCpu));
488 STDMETHOD(HotUnplugCPU(ULONG aCpu));
489 STDMETHOD(GetCPUStatus(ULONG aCpu, BOOL *aCpuAttached));
490
491 // public methods only for internal purposes
492
493 /**
494 * Simple run-time type identification without having to enable C++ RTTI.
495 * The class IDs are defined in VirtualBoxBase.h.
496 * @return
497 */
498 virtual VBoxClsID getClassID() const
499 {
500 return clsidMachine;
501 }
502
503 /**
504 * Override of the default locking class to be used for validating lock
505 * order with the standard member lock handle.
506 */
507 virtual VBoxLockingClass getLockingClass() const
508 {
509 return LOCKCLASS_MACHINEOBJECT;
510 }
511
512 /// @todo (dmik) add lock and make non-inlined after revising classes
513 // that use it. Note: they should enter Machine lock to keep the returned
514 // information valid!
515 bool isRegistered() { return !!mData->mRegistered; }
516
517 // unsafe inline public methods for internal purposes only (ensure there is
518 // a caller and a read lock before calling them!)
519
520 /**
521 * Returns the VirtualBox object this machine belongs to.
522 *
523 * @note This method doesn't check this object's readiness. Intended to be
524 * used by ready Machine children (whose readiness is bound to the parent's
525 * one) or after doing addCaller() manually.
526 */
527 const ComObjPtr<VirtualBox, ComWeakRef>& getVirtualBox() const { return mParent; }
528
529 /**
530 * Returns this machine ID.
531 *
532 * @note This method doesn't check this object's readiness. Intended to be
533 * used by ready Machine children (whose readiness is bound to the parent's
534 * one) or after adding a caller manually.
535 */
536 const Guid& getId() const { return mData->mUuid; }
537
538 /**
539 * Returns the snapshot ID this machine represents or an empty UUID if this
540 * instance is not SnapshotMachine.
541 *
542 * @note This method doesn't check this object's readiness. Intended to be
543 * used by ready Machine children (whose readiness is bound to the parent's
544 * one) or after adding a caller manually.
545 */
546 inline const Guid& getSnapshotId() const;
547
548 /**
549 * Returns this machine's full settings file path.
550 *
551 * @note This method doesn't lock this object or check its readiness.
552 * Intended to be used only after doing addCaller() manually and locking it
553 * for reading.
554 */
555 const Utf8Str& getSettingsFileFull() const { return mData->m_strConfigFileFull; }
556
557 /**
558 * Returns this machine name.
559 *
560 * @note This method doesn't lock this object or check its readiness.
561 * Intended to be used only after doing addCaller() manually and locking it
562 * for reading.
563 */
564 const Bstr& getName() const { return mUserData->mName; }
565
566 enum
567 {
568 IsModified_MachineData = 0x0001,
569 IsModified_Storage = 0x0002,
570 IsModified_NetworkAdapters = 0x0008,
571 IsModified_SerialPorts = 0x0010,
572 IsModified_ParallelPorts = 0x0020,
573 IsModified_VRDPServer = 0x0040,
574 IsModified_AudioAdapter = 0x0080,
575 IsModified_USB = 0x0100,
576 IsModified_BIOS = 0x0200,
577 IsModified_SharedFolders = 0x0400
578 };
579
580 void setModified(uint32_t fl);
581
582 // callback handlers
583 virtual HRESULT onNetworkAdapterChange(INetworkAdapter * /* networkAdapter */, BOOL /* changeAdapter */) { return S_OK; }
584 virtual HRESULT onSerialPortChange(ISerialPort * /* serialPort */) { return S_OK; }
585 virtual HRESULT onParallelPortChange(IParallelPort * /* parallelPort */) { return S_OK; }
586 virtual HRESULT onVRDPServerChange() { return S_OK; }
587 virtual HRESULT onUSBControllerChange() { return S_OK; }
588 virtual HRESULT onStorageControllerChange() { return S_OK; }
589 virtual HRESULT onCPUChange(ULONG /* aCPU */, BOOL /* aRemove */) { return S_OK; }
590 virtual HRESULT onMediumChange(IMediumAttachment * /* mediumAttachment */, BOOL /* force */) { return S_OK; }
591 virtual HRESULT onSharedFolderChange() { return S_OK; }
592
593 HRESULT saveRegistryEntry(settings::MachineRegistryEntry &data);
594
595 int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
596 void calculateRelativePath(const Utf8Str &strPath, Utf8Str &aResult);
597
598 void getLogFolder(Utf8Str &aLogFolder);
599
600 HRESULT openSession(IInternalSessionControl *aControl);
601 HRESULT openRemoteSession(IInternalSessionControl *aControl,
602 IN_BSTR aType, IN_BSTR aEnvironment,
603 Progress *aProgress);
604 HRESULT openExistingSession(IInternalSessionControl *aControl);
605
606#if defined(RT_OS_WINDOWS)
607
608 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
609 ComPtr<IInternalSessionControl> *aControl = NULL,
610 HANDLE *aIPCSem = NULL, bool aAllowClosing = false);
611 bool isSessionSpawning(RTPROCESS *aPID = NULL);
612
613 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
614 ComPtr<IInternalSessionControl> *aControl = NULL,
615 HANDLE *aIPCSem = NULL)
616 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
617
618#elif defined(RT_OS_OS2)
619
620 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
621 ComPtr<IInternalSessionControl> *aControl = NULL,
622 HMTX *aIPCSem = NULL, bool aAllowClosing = false);
623
624 bool isSessionSpawning(RTPROCESS *aPID = NULL);
625
626 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
627 ComPtr<IInternalSessionControl> *aControl = NULL,
628 HMTX *aIPCSem = NULL)
629 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
630
631#else
632
633 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
634 ComPtr<IInternalSessionControl> *aControl = NULL,
635 bool aAllowClosing = false);
636 bool isSessionSpawning();
637
638 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
639 ComPtr<IInternalSessionControl> *aControl = NULL)
640 { return isSessionOpen(aMachine, aControl, true /* aAllowClosing */); }
641
642#endif
643
644 bool checkForSpawnFailure();
645
646 HRESULT trySetRegistered(BOOL aRegistered);
647
648 HRESULT getSharedFolder(CBSTR aName,
649 ComObjPtr<SharedFolder> &aSharedFolder,
650 bool aSetError = false)
651 {
652 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
653 return findSharedFolder(aName, aSharedFolder, aSetError);
654 }
655
656 HRESULT addStateDependency(StateDependency aDepType = AnyStateDep,
657 MachineState_T *aState = NULL,
658 BOOL *aRegistered = NULL);
659 void releaseStateDependency();
660
661 // for VirtualBoxSupportErrorInfoImpl
662 static const wchar_t *getComponentName() { return L"Machine"; }
663
664protected:
665
666 HRESULT registeredInit();
667
668 HRESULT checkStateDependency(StateDependency aDepType);
669
670 inline Machine *getMachine();
671
672 void ensureNoStateDependencies();
673
674 virtual HRESULT setMachineState(MachineState_T aMachineState);
675
676 HRESULT findSharedFolder(CBSTR aName,
677 ComObjPtr<SharedFolder> &aSharedFolder,
678 bool aSetError = false);
679
680 HRESULT loadSettings(bool aRegistered);
681 HRESULT loadSnapshot(const settings::Snapshot &data,
682 const Guid &aCurSnapshotId,
683 Snapshot *aParentSnapshot);
684 HRESULT loadHardware(const settings::Hardware &data);
685 HRESULT loadStorageControllers(const settings::Storage &data,
686 bool aRegistered,
687 const Guid *aSnapshotId = NULL);
688 HRESULT loadStorageDevices(StorageController *aStorageController,
689 const settings::StorageController &data,
690 bool aRegistered,
691 const Guid *aSnapshotId = NULL);
692
693 HRESULT findSnapshot(const Guid &aId, ComObjPtr<Snapshot> &aSnapshot,
694 bool aSetError = false);
695 HRESULT findSnapshot(IN_BSTR aName, ComObjPtr<Snapshot> &aSnapshot,
696 bool aSetError = false);
697
698 HRESULT getStorageControllerByName(const Utf8Str &aName,
699 ComObjPtr<StorageController> &aStorageController,
700 bool aSetError = false);
701
702 HRESULT getMediumAttachmentsOfController(CBSTR aName,
703 MediaData::AttachmentList &aAttachments);
704
705 enum
706 {
707 /* flags for #saveSettings() */
708 SaveS_ResetCurStateModified = 0x01,
709 SaveS_InformCallbacksAnyway = 0x02,
710 /* flags for #saveSnapshotSettings() */
711 SaveSS_CurStateModified = 0x40,
712 SaveSS_CurrentId = 0x80,
713 /* flags for #saveStateSettings() */
714 SaveSTS_CurStateModified = 0x20,
715 SaveSTS_StateFilePath = 0x40,
716 SaveSTS_StateTimeStamp = 0x80,
717 };
718
719 HRESULT prepareSaveSettings(bool &aRenamed, bool &aNew);
720 HRESULT saveSettings(int aFlags = 0);
721
722 HRESULT saveAllSnapshots();
723
724 HRESULT saveHardware(settings::Hardware &data);
725 HRESULT saveStorageControllers(settings::Storage &data);
726 HRESULT saveStorageDevices(ComObjPtr<StorageController> aStorageController,
727 settings::StorageController &data);
728
729 HRESULT saveStateSettings(int aFlags);
730
731 HRESULT createImplicitDiffs(const Bstr &aFolder,
732 IProgress *aProgress,
733 ULONG aWeight,
734 bool aOnline,
735 bool *pfNeedsSaveSettings);
736 HRESULT deleteImplicitDiffs(bool *pfNeedsSaveSettings);
737
738 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
739 IN_BSTR aControllerName,
740 LONG aControllerPort,
741 LONG aDevice);
742 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
743 ComObjPtr<Medium> pMedium);
744 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
745 Guid &id);
746
747 void commitMedia(bool aOnline = false);
748 void rollbackMedia();
749
750 bool isInOwnDir(Utf8Str *aSettingsDir = NULL);
751
752 void rollback(bool aNotify);
753 void commit();
754 void copyFrom(Machine *aThat);
755
756#ifdef VBOX_WITH_RESOURCE_USAGE_API
757 void registerMetrics(PerformanceCollector *aCollector, Machine *aMachine, RTPROCESS pid);
758 void unregisterMetrics(PerformanceCollector *aCollector, Machine *aMachine);
759#endif /* VBOX_WITH_RESOURCE_USAGE_API */
760
761 const ComObjPtr<Machine, ComWeakRef> mPeer;
762
763 const ComObjPtr<VirtualBox, ComWeakRef> mParent;
764
765 uint32_t m_flModifications;
766
767 Shareable<Data> mData;
768 Shareable<SSData> mSSData;
769
770 Backupable<UserData> mUserData;
771 Backupable<HWData> mHWData;
772 Backupable<MediaData> mMediaData;
773
774 // the following fields need special backup/rollback/commit handling,
775 // so they cannot be a part of HWData
776
777 const ComObjPtr<VRDPServer> mVRDPServer;
778 const ComObjPtr<SerialPort> mSerialPorts[SchemaDefs::SerialPortCount];
779 const ComObjPtr<ParallelPort> mParallelPorts[SchemaDefs::ParallelPortCount];
780 const ComObjPtr<AudioAdapter> mAudioAdapter;
781 const ComObjPtr<USBController> mUSBController;
782 const ComObjPtr<BIOSSettings> mBIOSSettings;
783 const ComObjPtr<NetworkAdapter> mNetworkAdapters[SchemaDefs::NetworkAdapterCount];
784
785 typedef std::list< ComObjPtr<StorageController> > StorageControllerList;
786 Backupable<StorageControllerList> mStorageControllers;
787
788 friend class SessionMachine;
789 friend class SnapshotMachine;
790};
791
792// SessionMachine class
793////////////////////////////////////////////////////////////////////////////////
794
795/**
796 * @note Notes on locking objects of this class:
797 * SessionMachine shares some data with the primary Machine instance (pointed
798 * to by the |mPeer| member). In order to provide data consistency it also
799 * shares its lock handle. This means that whenever you lock a SessionMachine
800 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
801 * instance is also locked in the same lock mode. Keep it in mind.
802 */
803class ATL_NO_VTABLE SessionMachine :
804 public VirtualBoxSupportTranslation<SessionMachine>,
805 public Machine,
806 VBOX_SCRIPTABLE_IMPL(IInternalMachineControl)
807{
808public:
809
810 VIRTUALBOXSUPPORTTRANSLATION_OVERRIDE(SessionMachine)
811
812 DECLARE_NOT_AGGREGATABLE(SessionMachine)
813
814 DECLARE_PROTECT_FINAL_CONSTRUCT()
815
816 BEGIN_COM_MAP(SessionMachine)
817 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
818 COM_INTERFACE_ENTRY(ISupportErrorInfo)
819 COM_INTERFACE_ENTRY(IMachine)
820 COM_INTERFACE_ENTRY(IInternalMachineControl)
821 END_COM_MAP()
822
823 DECLARE_EMPTY_CTOR_DTOR(SessionMachine)
824
825 HRESULT FinalConstruct();
826 void FinalRelease();
827
828 // public initializer/uninitializer for internal purposes only
829 HRESULT init(Machine *aMachine);
830 void uninit() { uninit(Uninit::Unexpected); }
831
832 // util::Lockable interface
833 RWLockHandle *lockHandle() const;
834
835 // IInternalMachineControl methods
836 STDMETHOD(SetRemoveSavedState)(BOOL aRemove);
837 STDMETHOD(UpdateState)(MachineState_T machineState);
838 STDMETHOD(GetIPCId)(BSTR *id);
839 STDMETHOD(SetPowerUpInfo)(IVirtualBoxErrorInfo *aError);
840 STDMETHOD(RunUSBDeviceFilters)(IUSBDevice *aUSBDevice, BOOL *aMatched, ULONG *aMaskedIfs);
841 STDMETHOD(CaptureUSBDevice)(IN_BSTR aId);
842 STDMETHOD(DetachUSBDevice)(IN_BSTR aId, BOOL aDone);
843 STDMETHOD(AutoCaptureUSBDevices)();
844 STDMETHOD(DetachAllUSBDevices)(BOOL aDone);
845 STDMETHOD(OnSessionEnd)(ISession *aSession, IProgress **aProgress);
846 STDMETHOD(BeginSavingState)(IProgress *aProgress, BSTR *aStateFilePath);
847 STDMETHOD(EndSavingState)(BOOL aSuccess);
848 STDMETHOD(AdoptSavedState)(IN_BSTR aSavedStateFile);
849 STDMETHOD(BeginTakingSnapshot)(IConsole *aInitiator,
850 IN_BSTR aName,
851 IN_BSTR aDescription,
852 IProgress *aConsoleProgress,
853 BOOL fTakingSnapshotOnline,
854 BSTR *aStateFilePath);
855 STDMETHOD(EndTakingSnapshot)(BOOL aSuccess);
856 STDMETHOD(DeleteSnapshot)(IConsole *aInitiator, IN_BSTR aId,
857 MachineState_T *aMachineState, IProgress **aProgress);
858 STDMETHOD(RestoreSnapshot)(IConsole *aInitiator,
859 ISnapshot *aSnapshot,
860 MachineState_T *aMachineState,
861 IProgress **aProgress);
862 STDMETHOD(PullGuestProperties)(ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues),
863 ComSafeArrayOut(ULONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
864 STDMETHOD(PushGuestProperties)(ComSafeArrayIn(IN_BSTR, aNames), ComSafeArrayIn(IN_BSTR, aValues),
865 ComSafeArrayIn(ULONG64, aTimestamps), ComSafeArrayIn(IN_BSTR, aFlags));
866 STDMETHOD(PushGuestProperty)(IN_BSTR aName, IN_BSTR aValue,
867 ULONG64 aTimestamp, IN_BSTR aFlags);
868 STDMETHOD(LockMedia)() { return lockMedia(); }
869 STDMETHOD(UnlockMedia)() { unlockMedia(); return S_OK; }
870
871 // public methods only for internal purposes
872
873 /**
874 * Simple run-time type identification without having to enable C++ RTTI.
875 * The class IDs are defined in VirtualBoxBase.h.
876 * @return
877 */
878 virtual VBoxClsID getClassID() const
879 {
880 return clsidSessionMachine;
881 }
882
883 bool checkForDeath();
884
885 HRESULT onNetworkAdapterChange(INetworkAdapter *networkAdapter, BOOL changeAdapter);
886 HRESULT onStorageControllerChange();
887 HRESULT onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
888 HRESULT onSerialPortChange(ISerialPort *serialPort);
889 HRESULT onParallelPortChange(IParallelPort *parallelPort);
890 HRESULT onCPUChange(ULONG aCPU, BOOL aRemove);
891 HRESULT onVRDPServerChange();
892 HRESULT onUSBControllerChange();
893 HRESULT onUSBDeviceAttach(IUSBDevice *aDevice,
894 IVirtualBoxErrorInfo *aError,
895 ULONG aMaskedIfs);
896 HRESULT onUSBDeviceDetach(IN_BSTR aId,
897 IVirtualBoxErrorInfo *aError);
898 HRESULT onSharedFolderChange();
899
900 bool hasMatchingUSBFilter(const ComObjPtr<HostUSBDevice> &aDevice, ULONG *aMaskedIfs);
901
902private:
903
904 struct SnapshotData
905 {
906 SnapshotData() : mLastState(MachineState_Null) {}
907
908 MachineState_T mLastState;
909
910 // used when taking snapshot
911 ComObjPtr<Snapshot> mSnapshot;
912
913 // used when saving state
914 Guid mProgressId;
915 Utf8Str mStateFilePath;
916 };
917
918 struct Uninit
919 {
920 enum Reason { Unexpected, Abnormal, Normal };
921 };
922
923 struct SnapshotTask;
924 struct DeleteSnapshotTask;
925 struct RestoreSnapshotTask;
926
927 friend struct DeleteSnapshotTask;
928 friend struct RestoreSnapshotTask;
929
930 void uninit(Uninit::Reason aReason);
931
932 HRESULT endSavingState(BOOL aSuccess);
933
934 typedef std::map<ComObjPtr<Machine>, MachineState_T> AffectedMachines;
935
936 void deleteSnapshotHandler(DeleteSnapshotTask &aTask);
937 void restoreSnapshotHandler(RestoreSnapshotTask &aTask);
938
939 HRESULT lockMedia();
940 void unlockMedia();
941
942 HRESULT setMachineState(MachineState_T aMachineState);
943 HRESULT updateMachineStateOnClient();
944
945 HRESULT mRemoveSavedState;
946
947 SnapshotData mSnapshotData;
948
949 /** interprocess semaphore handle for this machine */
950#if defined(RT_OS_WINDOWS)
951 HANDLE mIPCSem;
952 Bstr mIPCSemName;
953 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
954 ComPtr<IInternalSessionControl> *aControl,
955 HANDLE *aIPCSem, bool aAllowClosing);
956#elif defined(RT_OS_OS2)
957 HMTX mIPCSem;
958 Bstr mIPCSemName;
959 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
960 ComPtr<IInternalSessionControl> *aControl,
961 HMTX *aIPCSem, bool aAllowClosing);
962#elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
963 int mIPCSem;
964# ifdef VBOX_WITH_NEW_SYS_V_KEYGEN
965 Bstr mIPCKey;
966# endif /*VBOX_WITH_NEW_SYS_V_KEYGEN */
967#else
968# error "Port me!"
969#endif
970
971 static DECLCALLBACK(int) taskHandler(RTTHREAD thread, void *pvUser);
972};
973
974// SnapshotMachine class
975////////////////////////////////////////////////////////////////////////////////
976
977/**
978 * @note Notes on locking objects of this class:
979 * SnapshotMachine shares some data with the primary Machine instance (pointed
980 * to by the |mPeer| member). In order to provide data consistency it also
981 * shares its lock handle. This means that whenever you lock a SessionMachine
982 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
983 * instance is also locked in the same lock mode. Keep it in mind.
984 */
985class ATL_NO_VTABLE SnapshotMachine :
986 public VirtualBoxSupportTranslation<SnapshotMachine>,
987 public Machine
988{
989public:
990
991 VIRTUALBOXSUPPORTTRANSLATION_OVERRIDE(SnapshotMachine)
992
993 DECLARE_NOT_AGGREGATABLE(SnapshotMachine)
994
995 DECLARE_PROTECT_FINAL_CONSTRUCT()
996
997 BEGIN_COM_MAP(SnapshotMachine)
998 COM_INTERFACE_ENTRY2(IDispatch, IMachine)
999 COM_INTERFACE_ENTRY(ISupportErrorInfo)
1000 COM_INTERFACE_ENTRY(IMachine)
1001 END_COM_MAP()
1002
1003 DECLARE_EMPTY_CTOR_DTOR(SnapshotMachine)
1004
1005 HRESULT FinalConstruct();
1006 void FinalRelease();
1007
1008 // public initializer/uninitializer for internal purposes only
1009 HRESULT init(SessionMachine *aSessionMachine,
1010 IN_GUID aSnapshotId,
1011 const Utf8Str &aStateFilePath);
1012 HRESULT init(Machine *aMachine,
1013 const settings::Hardware &hardware,
1014 const settings::Storage &storage,
1015 IN_GUID aSnapshotId,
1016 const Utf8Str &aStateFilePath);
1017 void uninit();
1018
1019 // util::Lockable interface
1020 RWLockHandle *lockHandle() const;
1021
1022 // public methods only for internal purposes
1023
1024 /**
1025 * Simple run-time type identification without having to enable C++ RTTI.
1026 * The class IDs are defined in VirtualBoxBase.h.
1027 * @return
1028 */
1029 virtual VBoxClsID getClassID() const
1030 {
1031 return clsidSnapshotMachine;
1032 }
1033
1034 HRESULT onSnapshotChange(Snapshot *aSnapshot);
1035
1036 // unsafe inline public methods for internal purposes only (ensure there is
1037 // a caller and a read lock before calling them!)
1038
1039 const Guid& getSnapshotId() const { return mSnapshotId; }
1040
1041private:
1042
1043 Guid mSnapshotId;
1044
1045 friend class Snapshot;
1046};
1047
1048// third party methods that depend on SnapshotMachine definiton
1049
1050inline const Guid &Machine::getSnapshotId() const
1051{
1052 return getClassID() != clsidSnapshotMachine
1053 ? Guid::Empty
1054 : static_cast<const SnapshotMachine*>(this)->getSnapshotId();
1055}
1056
1057////////////////////////////////////////////////////////////////////////////////
1058
1059/**
1060 * Returns a pointer to the Machine object for this machine that acts like a
1061 * parent for complex machine data objects such as shared folders, etc.
1062 *
1063 * For primary Machine objects and for SnapshotMachine objects, returns this
1064 * object's pointer itself. For SessoinMachine objects, returns the peer
1065 * (primary) machine pointer.
1066 */
1067inline Machine *Machine::getMachine()
1068{
1069 if (getClassID() == clsidSessionMachine)
1070 return mPeer;
1071 return this;
1072}
1073
1074
1075#endif // ____H_MACHINEIMPL
1076/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette