MCPcopy Create free account
hub / github.com/Hieromon/AutoConnect / attach

Method attach

src/AutoConnectUpdate.cpp:124–180  ·  view source on GitHub ↗

* Attach the AutoConnectUpdateAct to the AutoConnect which constitutes * the bedrock of the update process. This function creates dialog pages * for update operation as an instance of AutoConnectAux and joins to * the AutoConnect which is the bedrock of the process. * @param portal A reference of AutoConnect */

Source from the content-addressed store, hash-verified

122 * @param portal A reference of AutoConnect
123 */
124void AutoConnectUpdateAct::attach(AutoConnectExt<AutoConnectConfigExt>& portal) {
125 AutoConnectAux* updatePage;
126
127 updatePage = new AutoConnectAux(String(FPSTR(_pageCatalog.uri)), String(FPSTR(_pageCatalog.title)), _pageCatalog.menu);
128 _buildAux(updatePage, &_pageCatalog, lengthOf(_elmCatalog));
129 _auxCatalog.reset(updatePage);
130
131 updatePage = new AutoConnectAux(String(FPSTR(_pageProgress.uri)), String(FPSTR(_pageProgress.title)), _pageProgress.menu);
132 _buildAux(updatePage, &_pageProgress, lengthOf(_elmProgress));
133 _auxProgress.reset(updatePage);
134
135 updatePage = new AutoConnectAux(String(FPSTR(_pageResult.uri)), String(FPSTR(_pageResult.title)), _pageResult.menu);
136 _buildAux(updatePage, &_pageResult, lengthOf(_elmResult));
137 _auxResult.reset(updatePage);
138
139 _auxCatalog->on(std::bind(&AutoConnectUpdateAct::_onCatalog, this, std::placeholders::_1, std::placeholders::_2), AC_EXIT_AHEAD);
140 _auxProgress->on(std::bind(&AutoConnectUpdateAct::_onUpdate, this, std::placeholders::_1, std::placeholders::_2), AC_EXIT_AHEAD);
141 _auxResult->on(std::bind(&AutoConnectUpdateAct::_onResult, this, std::placeholders::_1, std::placeholders::_2), AC_EXIT_AHEAD);
142
143 portal.join(*_auxCatalog.get());
144 portal.join(*_auxProgress.get());
145 portal.join(*_auxResult.get());
146
147 // Register the callback to inform the update progress
148 _dialog = AutoConnectUtil::onProgress<UpdateVariedClass>(Update, std::bind(&AutoConnectUpdateAct::_inProgress, this, std::placeholders::_1, std::placeholders::_2));
149 // Adjust the client dialog pattern according to the callback validity
150 // of the UpdateClass.
151 AutoConnectStyle& loader = _auxProgress->getElement<AutoConnectStyle>(F("loader"));
152 AutoConnectElement* progress_meter = _auxProgress->getElement(F("progress_meter"));
153 AutoConnectElement* progress_loader = _auxProgress->getElement(F("progress_loader"));
154 AutoConnectElement* enable_loader = _auxProgress->getElement(F("enable_loader"));
155 AutoConnectElement* inprogress_meter = _auxProgress->getElement(F("inprogress_meter"));
156 switch (_dialog) {
157 case UPDATEDIALOG_LOADER:
158 progress_meter->enable =false;
159 inprogress_meter->enable = false;
160 break;
161 case UPDATEDIALOG_METER:
162 loader.enable = false;
163 progress_loader->enable =false;
164 enable_loader->enable =false;
165 break;
166 }
167
168 // Attach this to the AutoConnectUpdateAct
169 portal._update.reset(this);
170 AC_DBG("AutoConnectUpdate attached\n");
171 if (WiFi.status() == WL_CONNECTED)
172 enable();
173
174 // Attach the update progress monitoring handler
175 _webServer = &(portal.host());
176 _webServer->on(String(F(AUTOCONNECT_URI_UPDATE_PROGRESS)), HTTP_ANY, std::bind(&AutoConnectUpdateAct::_progress, this));
177
178 // Reset the update progress status
179 _status = UPDATE_IDLE;
180}
181

Callers

nothing calls this directly

Calls 6

FFunction · 0.85
resetMethod · 0.80
getElementMethod · 0.80
onMethod · 0.45
joinMethod · 0.45
statusMethod · 0.45

Tested by

no test coverage detected