Skip to content

Commit

Permalink
Return object reference& instead of pointer (never null)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikee47 committed Nov 6, 2020
1 parent 97990e8 commit 36fa814
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Sming/Libraries/DIAL/sample/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void onConnected(Dial::Client& client, const XML::Document& doc, const HttpHeade
Serial.printf(_F("Friendly name: %s.\n"), node->value());
}

auto app = client.getApp("YouTube");
auto& app = client.getApp("YouTube");
app.status(onStatus);
}

Expand Down
4 changes: 2 additions & 2 deletions Sming/Libraries/DIAL/src/Dial/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ bool Client::connect(const Url& descriptionUrl, Connected callback)
return true;
}

App* Client::getApp(const String& applicationId)
App& Client::getApp(const String& applicationId)
{
auto app = apps[applicationId];
if(!app) {
app = new App(applicationId, applicationUrl);
}

return app;
return *app;
}

// EEEKK!!! Cannot do this - returns dangling pointer
Expand Down
6 changes: 3 additions & 3 deletions Sming/Libraries/DIAL/src/Dial/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ class Client : public UPnP::ControlPoint
void onNotify(SSDP::BasicMessage& msg) override;

/**
* @brief Gets pointer to an application object
* @brief Get application object by name
* @param applicationId the unique application.
* A list of registered ids can be found here: http://www.dial-multiscreen.org/dial-registry/namespace-database#TOC-Registered-Names
* @retval pointer to an application obeject
* @retval App& Application object reference
*/
App* getApp(const String& applicationId);
App& getApp(const String& applicationId);

protected:
static HttpClient http;
Expand Down

0 comments on commit 36fa814

Please sign in to comment.