VirtualBox

source: vbox/trunk/src/VBox/Main/include/UpdateAgentImpl.h

Last change on this file was 98103, checked in by vboxsync, 16 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.5 KB
Line 
1/* $Id: UpdateAgentImpl.h 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * Update agent COM class implementation - Header
4 */
5
6/*
7 * Copyright (C) 2020-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28#ifndef MAIN_INCLUDED_UpdateAgentImpl_h
29#define MAIN_INCLUDED_UpdateAgentImpl_h
30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
33
34#include <iprt/http.h>
35
36#include <VBox/settings.h>
37
38#include "EventImpl.h"
39#include "UpdateAgentWrap.h"
40#include "HostUpdateAgentWrap.h"
41
42class UpdateAgentTask;
43struct UpdateAgentTaskParms;
44
45struct UpdateAgentTaskResult
46{
47 Utf8Str strVer;
48 Utf8Str strWebUrl;
49 Utf8Str strDownloadUrl;
50 UpdateSeverity_T enmSeverity;
51 Utf8Str strReleaseNotes;
52};
53
54class UpdateAgentBase
55{
56protected: /* Not directly instancable. */
57
58 UpdateAgentBase()
59 : m_VirtualBox(NULL)
60 , m(new settings::UpdateAgent) { }
61
62 virtual ~UpdateAgentBase() { delete m; }
63
64public:
65
66 /** @name Pure virtual public methods for internal purposes only
67 * (ensure there is a caller and a read lock before calling them!)
68 * @{ */
69 virtual HRESULT i_loadSettings(const settings::UpdateAgent &data) = 0;
70 virtual HRESULT i_saveSettings(settings::UpdateAgent &data) = 0;
71
72 virtual HRESULT i_setCheckCount(ULONG aCount) = 0;
73 virtual HRESULT i_setLastCheckDate(const com::Utf8Str &aDate) = 0;
74 /** @} */
75
76protected:
77
78 /** @name Pure virtual internal task callbacks.
79 * @{ */
80 friend UpdateAgentTask;
81 virtual DECLCALLBACK(HRESULT) i_checkForUpdateTask(UpdateAgentTask *pTask) = 0;
82 /** @} */
83
84 /** @name Static helper methods.
85 * @{ */
86 static Utf8Str i_getPlatformInfo(void);
87 const char *i_proxyModeToStr(ProxyMode_T enmMode);
88 bool i_urlSchemeIsSupported(const Utf8Str &strUrl) const;
89 /** @} */
90
91protected:
92 /** The update agent's event source. */
93 const ComObjPtr<EventSource> m_EventSource;
94 VirtualBox * const m_VirtualBox;
95
96 /** @name Data members.
97 * @{ */
98 settings::UpdateAgent *m;
99
100 struct Data
101 {
102 UpdateAgentTaskResult m_lastResult;
103 Utf8Str m_strName;
104 /** Vector of update channels this agent supports. */
105 const std::vector<UpdateChannel_T> m_enmChannels;
106 bool m_fHidden;
107 UpdateState_T m_enmState;
108 uint32_t m_uOrder;
109
110 Data(void)
111 {
112 m_fHidden = true;
113 m_enmState = UpdateState_Invalid;
114 m_uOrder = UINT32_MAX;
115 }
116 } mData;
117 /** @} */
118};
119
120class ATL_NO_VTABLE UpdateAgent :
121 public UpdateAgentWrap,
122 public UpdateAgentBase
123{
124public:
125 DECLARE_COMMON_CLASS_METHODS(UpdateAgent)
126
127 /** @name COM and internal init/term/mapping cruft.
128 * @{ */
129 HRESULT FinalConstruct();
130 void FinalRelease();
131
132 HRESULT init(VirtualBox *aVirtualBox);
133 void uninit(void);
134 /** @} */
135
136 /** @name Public methods for internal purposes only
137 * (ensure there is a caller and a read lock before calling them!)
138 * @{ */
139 HRESULT i_loadSettings(const settings::UpdateAgent &data);
140 HRESULT i_saveSettings(settings::UpdateAgent &data);
141
142 virtual HRESULT i_setCheckCount(ULONG aCount);
143 virtual HRESULT i_setLastCheckDate(const com::Utf8Str &aDate);
144 /** @} */
145
146protected:
147
148 /** @name Internal helper methods.
149 * @{ */
150 HRESULT i_getProxyMode(ProxyMode_T *aMode);
151 HRESULT i_getProxyURL(com::Utf8Str &aAddress);
152 HRESULT i_configureProxy(RTHTTP hHttp);
153 HRESULT i_commitSettings(AutoWriteLock &aLock);
154 HRESULT i_reportError(int vrc, const char *pcszMsgFmt, ...);
155 /** @} */
156
157protected:
158 /** @name Wrapped IUpdateAgent attributes and methods.
159 * @{ */
160 HRESULT checkFor(ComPtr<IProgress> &aProgress);
161 HRESULT download(ComPtr<IProgress> &aProgress);
162 HRESULT install(ComPtr<IProgress> &aProgress);
163 HRESULT rollback(void);
164
165 HRESULT getName(com::Utf8Str &aName);
166 HRESULT getEventSource(ComPtr<IEventSource> &aEventSource);
167 HRESULT getOrder(ULONG *aOrder);
168 HRESULT getDependsOn(std::vector<com::Utf8Str> &aDeps);
169 HRESULT getVersion(com::Utf8Str &aVer);
170 HRESULT getDownloadUrl(com::Utf8Str &aUrl);
171 HRESULT getWebUrl(com::Utf8Str &aUrl);
172 HRESULT getReleaseNotes(com::Utf8Str &aRelNotes);
173 HRESULT getEnabled(BOOL *aEnabled);
174 HRESULT setEnabled(BOOL aEnabled);
175 HRESULT getHidden(BOOL *aHidden);
176 HRESULT getState(UpdateState_T *aState);
177 HRESULT getCheckCount(ULONG *aCount);
178 HRESULT getCheckFrequency(ULONG *aFreqSeconds);
179 HRESULT setCheckFrequency(ULONG aFreqSeconds);
180 HRESULT getChannel(UpdateChannel_T *aChannel);
181 HRESULT setChannel(UpdateChannel_T aChannel);
182 HRESULT getRepositoryURL(com::Utf8Str &aRepo);
183 HRESULT setRepositoryURL(const com::Utf8Str &aRepo);
184 HRESULT getLastCheckDate(com::Utf8Str &aData);
185 HRESULT getIsCheckNeeded(BOOL *aCheckNeeded);
186 HRESULT getSupportedChannels(std::vector<UpdateChannel_T> &aSupportedChannels);
187 /** @} */
188};
189
190/** @todo Put this into an own module, e.g. HostUpdateAgentImpl.[cpp|h]. */
191
192class ATL_NO_VTABLE HostUpdateAgent :
193 public UpdateAgent
194{
195public:
196 /** @name COM and internal init/term/mapping cruft.
197 * @{ */
198 DECLARE_COMMON_CLASS_METHODS(HostUpdateAgent)
199
200 HRESULT init(VirtualBox *aVirtualBox);
201 void uninit(void);
202
203 HRESULT FinalConstruct(void);
204 void FinalRelease(void);
205 /** @} */
206
207private:
208 /** @name Implemented (pure) virtual methods from UpdateAgent.
209 * @{ */
210 HRESULT checkFor(ComPtr<IProgress> &aProgress);
211
212 DECLCALLBACK(HRESULT) i_checkForUpdateTask(UpdateAgentTask *pTask);
213 /** @} */
214
215 HRESULT i_checkForUpdate(void);
216 HRESULT i_checkForUpdateInner(RTHTTP hHttp, com::Utf8Str const &strUrl, com::Utf8Str const &strUserAgent);
217};
218
219#endif /* !MAIN_INCLUDED_UpdateAgentImpl_h */
220
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use