Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce code deprecation and virtual methods #1629

Merged
merged 17 commits into from
Feb 19, 2019

Conversation

mikee47
Copy link
Contributor

@mikee47 mikee47 commented Feb 17, 2019

  • Use SMING_DEPRECATED attribute to ensure marked code not referenced within framework
  • Apply override to all inherited virtual methods
  • Ensure base virtual classes have virtual destructors
  • Remove virtual from overriden destructors
  • Remove empty overridden destructors and overriden methods that do not change base behaviour
  • Ensure consistent ordering of constructors/destructor in header

Some samples use deprecated methods. If no suitable alternative has yet been provided, those methods have been un-deprecated and noted in the method comment using @todo. The follow methods have been un-deprecated completely:

`HttpResponse::sendTemplate()`
`WebsocketConnection::operator==(WebsocketConnection&)`

Additional style changes:

  • Move trivial code into headers
  • Use nullptr instead of NULL or 0 where appropriate
  • Remove use of __forceinline or inline where there is no specific need
  • Reduce sample applications #include <SmingCore/*> to #include <*>
  • Fix ill-formed doxygen comments
  • Fix doxygen build error and include SSL code in output

Closes #1620

@mikee47
Copy link
Contributor Author

mikee47 commented Feb 17, 2019

@slaff As this PR deals with coding style changes I've gone further and updated all the core files to standardise comment headers and that #include guards are named correctly. It affects unrelated files though so I'll assume it's a separate PR; I can commit here if you want.

@slaff
Copy link
Contributor

slaff commented Feb 18, 2019

It affects unrelated files though so I'll assume it's a separate PR; I can commit here if you want.

As long as the unrelated files are not part of third-party libraries or Arduino libraries it should be fine to add it also here. But before you do this can you explain what you mean by 'unrelated files` ?

@mikee47
Copy link
Contributor Author

mikee47 commented Feb 18, 2019

unrelated files meaning files that otherwise wouldn't be modified as a result of deprecate/override

@slaff
Copy link
Contributor

slaff commented Feb 18, 2019

unrelated files meaning files that otherwise wouldn't be modified as a result of deprecate/override

Separate PR please.

Copy link
Contributor

@slaff slaff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic work! Only small indentation changes needed.

@@ -64,8 +68,14 @@ class HardwarePWM
* @param duty Value of duty cycle to set pin to
* @param update Update PWM output
* @retval bool True on success
* @note This function is used to set the pwm duty cycle for a given pin. If parameter 'update' is false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, indent the next two lines with the one above.

class Printable
{
public:
virtual ~Printable() { }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation needs fixing.

@@ -32,6 +32,9 @@
*/
#define SMING_UNUSED __attribute__((unused))

/* Flags a compiler warning when Sming framework methods, functions or types are changed */
#define __deprecated __attribute__((deprecated))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other definitions of attributes are uppercase. Can you make also this one to be __DEPRECATED or SMING_DEPRECATED ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like SMING_DEPRECATED, it's specific

@@ -121,9 +120,10 @@ class WebsocketConnection
void* getUserData();

// @deprecated
bool operator==(const WebsocketConnection& rhs) const;
bool operator==(const WebsocketConnection& rhs) const __deprecated;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slaff You deprecated this method on 04/05/2017, and enforcing deprecation means there's a corresponding change in the HttpServer_WebSockets sample and possibly user apps; Keep it deprecated?

Copy link
Contributor

@slaff slaff Feb 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You deprecated this method on 04/05/2017, and enforc ....

Hm... cannot remember why. You can un-deprecate it if needed.

Rename `__deprecated` to `SMING_DEPRECATED`
Fix indenting
Tidy #includes for all files modified by this PR
Revert include guard renaming (separate PR)
Revert changes to files not related to deprecate/override (separate PR)
Revert deprecation of `WebsocketConnection::operator==`
Ensure `@deprecated` usage resides within doxygen comment
Fix doxygen error and include SSL in output
@slaff slaff added this to the 3.7.2 milestone Feb 18, 2019
@slaff
Copy link
Contributor

slaff commented Feb 18, 2019

@mikee47 Ready to merge?

{
}
};

class HttpBasicAuth : public AuthAdapter
{
public:
HttpBasicAuth(const String& username, const String& password);
HttpBasicAuth(const String& username, const String& password)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikee47 You can initialize the variables in initialization list

image

@@ -47,9 +50,16 @@ class HttpBasicAuth : public AuthAdapter
class HttpDigestAuth : public AuthAdapter
{
public:
HttpDigestAuth(const String& username, const String& password);
HttpDigestAuth(const String& username, const String& password)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too: variables in initialization list

@mikee47 mikee47 force-pushed the fix/deprecated-override branch from 11ddb12 to b18982a Compare February 18, 2019 15:54
@@ -56,7 +56,8 @@ class HttpRequest
return new HttpRequest(*this);
}

HttpRequest& operator=(const HttpRequest& rhs);
/** @deprecated Please use `clone()` instead */
HttpRequest& operator=(const HttpRequest& rhs) SMING_DEPRECATED;
Copy link
Contributor Author

@mikee47 mikee47 Feb 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The copy operator provided is actually unsafe as it doesn't take copies of allocated member variables so I've marked it deprecated. I could go further and make it private, which would prevent applications building if it's used.

See also #1601 (comment). I think probably get rid of the warning in the code and document the copy constructor instead.

Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could go further and make it private, which would prevent applications building if it's used.

For now deprecate it only.

I think probably get rid of the warning in the code and document the copy constructor instead.

Sounds good.

@mikee47
Copy link
Contributor Author

mikee47 commented Feb 18, 2019

Just noticed there's a bunch of overrides missing. Will add those.

@mikee47
Copy link
Contributor Author

mikee47 commented Feb 19, 2019

@slaff I'm inclined to revert the last change relating to HttpRequest copy constructor, deal with it separately. It's a whole issue with copying HashMap objects.

@slaff
Copy link
Contributor

slaff commented Feb 19, 2019

The build is failing:

SmingCore/Network/Http/HttpRequest.cpp: In copy constructor 'HttpRequest::HttpRequest(const HttpRequest&)':
SmingCore/Network/Http/HttpRequest.cpp:19:93: error: use of deleted function 'HttpParams::HttpParams(const HttpParams&)'
 ri), method(value.method), headers(value.headers), postParams(value.postParams)
                                                                               ^
In file included from SmingCore/Network/Http/HttpRequest.h:24:0,
                 from SmingCore/Network/Http/HttpRequest.cpp:13:
SmingCore/Network/Http/HttpParams.h:30:7: note: 'HttpParams::HttpParams(const HttpParams&)' is implicitly deleted because the default definition would be ill-formed:
 class HttpParams : public HashMap<String, String>, public Printable
       ^
In file included from SmingCore/Network/Http/HttpHeaders.h:23:0,
                 from SmingCore/Network/Http/HttpResponse.h:18,
                 from SmingCore/Network/Http/HttpRequestAuth.h:16,
                 from SmingCore/Network/Http/HttpRequest.h:18,
                 from SmingCore/Network/Http/HttpRequest.cpp:13:
Wiring/WHashMap.h:321:5: error: 'HashMap<K, V>::HashMap(const HashMap<K, V>&) [with K = String; V = String]' is private
     HashMap(const HashMap<K, V>& that);
     ^
In file included from SmingCore/Network/Http/HttpRequest.h:24:0,
                 from SmingCore/Network/Http/HttpRequest.cpp:13:
SmingCore/Network/Http/HttpParams.h:30:7: error: within this context
 class HttpParams : public HashMap<String, String>, public Printable
       ^
make[3]: *** [out/build/SmingCore/Network/Http//HttpRequest.o] Error 1
make[3]: Leaving directory `/home/travis/build/SmingHub/Sming/Sming'

I'm inclined to revert the last change relating to HttpRequest copy constructor, deal with it separately

Yes, do it like this. This PR is already quite big.

@mikee47
Copy link
Contributor Author

mikee47 commented Feb 19, 2019

This PR is already quite big.

Yes, and there shouldn't be any functional changes in this PR. (Well, intentionally anyway!)

@slaff slaff merged commit 49a9c6a into SmingHub:develop Feb 19, 2019
@slaff slaff removed the 3 - Review label Feb 19, 2019
@mikee47 mikee47 deleted the fix/deprecated-override branch February 19, 2019 08:56
@mikee47
Copy link
Contributor Author

mikee47 commented Feb 19, 2019

Coding style rules updated

@slaff
Copy link
Contributor

slaff commented Feb 19, 2019

Coding style rules updated

Thanks for the changes. I have read the new text and all looks very good to me.

mikee47 added a commit to mikee47/Sming that referenced this pull request Feb 24, 2019
mikee47 added a commit to mikee47/Sming that referenced this pull request Feb 25, 2019
mikee47 added a commit to mikee47/Sming that referenced this pull request Feb 25, 2019
slaff pushed a commit that referenced this pull request Feb 26, 2019
* Fix memory leaks in `HttpConnection`

Change `waitingQueue` from un-owned `RequestQueue*` to `RequestQueue`
Free request if queue is full in `send(HttpRequest*)`

* Tidy up

* Code out of header

* Merge `HttpClientConnection` into `HttpConnection`

* HttpConnection -> HttpClientConnection

* HttpConnectionBase -> HttpConnection

* Move `isActive()` from `HttpClientConnection` into `HttpConnection` - applicable to both server and client

* Resolve `HttpClientConnection` methods temporarily un-deprecated in #1629

* Revise `HttpConnection` so it can be used with either client or server

Move `response` member variable into `HttpConnection` as both client and server have this.
Move `getResponse()` method from `HttpClientConnection` into `HttpConnection`
Add virtual `getRequest()` method to HttpConnection
Move applicable methods from `HttpClientConnection` into `HttpConnection`

Note: `send(HttpRquest*)` made virtual in previous commit

* Fix comments

* Fix deprecated method calls

* Don't initialise `userData` in `WebsocketConnection` constructor

* Un-deprecate `WebsocketConnection::getActiveWebsockets()` and make `static`, returning `const WebsocketList` to prevent dangerous modifications. See #1469
@slaff slaff mentioned this pull request Feb 27, 2019
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants