VirtualBox

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

Last change on this file since 96407 was 96407, checked in by vboxsync, 21 months ago

scm copyright and license note update

  • 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 96407 2022-08-22 17:43:14Z vboxsync $ */
2/** @file
3 * Update agent COM class implementation - Header
4 */
5
6/*
7 * Copyright (C) 2020-2022 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 HRESULT i_loadSettings(const settings::UpdateAgent &data);
139 HRESULT i_saveSettings(settings::UpdateAgent &data);
140
141 virtual HRESULT i_setCheckCount(ULONG aCount);
142 virtual HRESULT i_setLastCheckDate(const com::Utf8Str &aDate);
143 /** @} */
144
145protected:
146
147 /** @name Internal helper methods.
148 * @{ */
149 HRESULT i_getProxyMode(ProxyMode_T *aMode);
150 HRESULT i_getProxyURL(com::Utf8Str &aAddress);
151 HRESULT i_configureProxy(RTHTTP hHttp);
152 HRESULT i_commitSettings(AutoWriteLock &aLock);
153 HRESULT i_reportError(int vrc, const char *pcszMsgFmt, ...);
154 /** @} */
155
156protected:
157 /** @name Wrapped IUpdateAgent attributes and methods.
158 * @{ */
159 HRESULT checkFor(ComPtr<IProgress> &aProgress);
160 HRESULT download(ComPtr<IProgress> &aProgress);
161 HRESULT install(ComPtr<IProgress> &aProgress);
162 HRESULT rollback(void);
163
164 HRESULT getName(com::Utf8Str &aName);
165 HRESULT getEventSource(ComPtr<IEventSource> &aEventSource);
166 HRESULT getOrder(ULONG *aOrder);
167 HRESULT getDependsOn(std::vector<com::Utf8Str> &aDeps);
168 HRESULT getVersion(com::Utf8Str &aVer);
169 HRESULT getDownloadUrl(com::Utf8Str &aUrl);
170 HRESULT getWebUrl(com::Utf8Str &aUrl);
171 HRESULT getReleaseNotes(com::Utf8Str &aRelNotes);
172 HRESULT getEnabled(BOOL *aEnabled);
173 HRESULT setEnabled(BOOL aEnabled);
174 HRESULT getHidden(BOOL *aHidden);
175 HRESULT getState(UpdateState_T *aState);
176 HRESULT getCheckCount(ULONG *aCount);
177 HRESULT getCheckFrequency(ULONG *aFreqSeconds);
178 HRESULT setCheckFrequency(ULONG aFreqSeconds);
179 HRESULT getChannel(UpdateChannel_T *aChannel);
180 HRESULT setChannel(UpdateChannel_T aChannel);
181 HRESULT getRepositoryURL(com::Utf8Str &aRepo);
182 HRESULT setRepositoryURL(const com::Utf8Str &aRepo);
183 HRESULT getLastCheckDate(com::Utf8Str &aData);
184 HRESULT getIsCheckNeeded(BOOL *aCheckNeeded);
185 HRESULT getSupportedChannels(std::vector<UpdateChannel_T> &aSupportedChannels);
186 /** @} */
187};
188
189/** @todo Put this into an own module, e.g. HostUpdateAgentImpl.[cpp|h]. */
190
191class ATL_NO_VTABLE HostUpdateAgent :
192 public UpdateAgent
193{
194public:
195 /** @name COM and internal init/term/mapping cruft.
196 * @{ */
197 DECLARE_COMMON_CLASS_METHODS(HostUpdateAgent)
198
199 HRESULT init(VirtualBox *aVirtualBox);
200 void uninit(void);
201
202 HRESULT FinalConstruct(void);
203 void FinalRelease(void);
204 /** @} */
205
206private:
207 /** @name Implemented (pure) virtual methods from UpdateAgent.
208 * @{ */
209 HRESULT checkFor(ComPtr<IProgress> &aProgress);
210
211 DECLCALLBACK(HRESULT) i_checkForUpdateTask(UpdateAgentTask *pTask);
212 /** @} */
213
214 HRESULT i_checkForUpdate(void);
215 HRESULT i_checkForUpdateInner(RTHTTP hHttp, com::Utf8Str const &strUrl, com::Utf8Str const &strUserAgent);
216};
217
218#endif /* !MAIN_INCLUDED_UpdateAgentImpl_h */
219
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use