Commit Graph

65 Commits

Author SHA1 Message Date
Sona Kurazyan d2dd87b0a6 Remove the protected constructor from QCoapClient
This change is based on the feedback from API review.

Change-Id: I99f00d15e9474b2844a436113ac7771ead7b33c6
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-05-14 15:14:44 +00:00
Sona Kurazyan ae8d1fef58 Hide the API of QCoapProtocol
No need to keep this class public, there is no public API for accessing
it anyway.

Change-Id: I231a560becb5799667819c30eca6372282adeb41
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-05-14 15:14:39 +00:00
Sona Kurazyan 804b10f329 Hide the APIs of QCoapConnection and QCoapQUdpConnection
At the moment only the QCoapQUdpConnection class implements the
QCoapConnection interface. If later we decide to add other
implementations, and it turns out that the current API is not good
enough, it won't be possible to change it  without breaking the source
compatibility. Let's make these classes private, we can make them public
when there is a need for it.

Change-Id: I41336dda0e6eaa762f0eb9c8f4aa98a9c7b62a2c
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2019-05-14 15:14:33 +00:00
Sona Kurazyan 18289e7c1d Remove the "Error" ending from QtCoap::Error enum value names
QtCoap::Error is a scoped enum class, so its value names will get the
"Error::" prefix anyway. No need to have it as a suffix for the value
names.

For the same reason replaced QtCoap::Error::NoError by
QtCoap::Error::Ok.

Change-Id: Iaf7b51cdab6ea330e940e5af73ba93a55eb48315
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2019-05-03 08:36:16 +00:00
Sona Kurazyan 7a16e8d9b5 Use scoped enums
Execptions are made for QCoapOption::OptionName and QtCoap::Port enums,
because the values of these types are not limited only to the values
listed in the enums. In case of using custom values, it would be more
convenient to use integers directly, instead of using a static_cast each
time the user needs a custom value.

Change-Id: Ibc63e26c59629702c03528dd7e5e5eedc6bcc90a
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2019-05-03 08:36:09 +00:00
Sona Kurazyan e8b9f3c8a9 Fix the location of '&' in a method signature
Change-Id: Ibf19500b897c0d2eb3a9ab9420ee98b04074b20a
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2019-04-26 12:25:11 +00:00
Sona Kurazyan 4f4ea77b62 Document the quickmulticastclient example
Change-Id: I8bc64842a2d0ed70fc40a5ae4492cb4b2a3611b8
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2019-04-26 12:06:18 +00:00
Sona Kurazyan 4505ac832c Move the declaration of QCoapInternalMessage to the private header
This class is intended for internal use only, so it should not have a
public header.

Change-Id: I18f2433d06e978582b470e14dc89a7c0e404f7d4
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2019-04-26 09:11:33 +00:00
Sona Kurazyan 13e9719921 Replace the Q_DECL_OVERRIDE macros with 'override'
Change-Id: I32f3712ed2c160e1dc26397d58114fa441c0fc9b
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2019-04-26 09:11:29 +00:00
Sona Kurazyan 053cd35954 Make QCoapMessage::addOption non-virtual
This method doesn't need to be virtual, no one overrides it.

Change-Id: Ia8c06c40fcb7cb97e413da6dc0458553540803cf
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2019-04-26 09:11:22 +00:00
Sona Kurazyan 17e8aeede0 Mention CBOR when documenting CoAP's content formats
Change-Id: Ifb15180619c1d7e056a5578c30d22e2e9e16edd5
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2019-04-25 14:54:21 +00:00
Sona Kurazyan e2faedb48d Add an API for closing the connection's transport
Change-Id: I916ddb226b653aaf563ecf0adc3a1110d6da3132
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2019-04-25 06:36:27 +00:00
Sona Kurazyan cf5699e405 Add documentation for Qt CoAP overview
Change-Id: I1ebf03d68c267f87ca2b690d4c666c26717f8d07
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2019-04-17 08:06:30 +00:00
Sona Kurazyan d996cb47f1 Document the qmlsecurecoapclient example
Change-Id: I4f193b0d65bb3104db6483749cf9dc36547e1861
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2019-04-17 08:06:12 +00:00
Sona Kurazyan 7706ea9792 Add a button for closing the connection in secure client example
Change-Id: Icc21315a5a20eeee02b578dc56459d4697a6361d
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2019-04-17 08:05:49 +00:00
Sona Kurazyan 637b228a38 Add secure CoAP client example
This example demonstrates sending secure CoAP GET requests
in PreSharedKey and Certificate modes.

Change-Id: I90ea8c77232bfca1ca86bdd7a73223b6ba8b0c9b
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2019-04-17 08:05:25 +00:00
Sona Kurazyan f633087e26 Add QML-based multicast discovery example
Change-Id: If210c040ec40a828d4c997251ef2a635e2e70d32
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2019-04-17 08:05:16 +00:00
Sona Kurazyan a9a0561e52 Fix URL adjustment of URLs with no host
QUrl can have an empty host, but still considered to be valid.
This is possible, for example, when setting an invalid host address or
when the URL is a path. Adjusting such URLs leads to unexpected results.

Added a check for preventing sending requests to URLs with no host.

Fixes: QTBUG-75155
Change-Id: I6c899f824233f32cddb8c9255fd3d1c333bb6385
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2019-04-17 07:30:51 +00:00
Sona Kurazyan 435bee7c8f Add navigation homepage for the QtCoAP module
Change-Id: I565cd306ab36230371cde6475d8417b40752a2a5
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
2019-04-16 12:59:30 +00:00
Sona Kurazyan 3439fd561e Document the simplecoapclient example
Change-Id: I066acf1d2765f4c48392371e50f86f694c1af7bc
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2019-04-15 10:56:02 +00:00
Sona Kurazyan 8b9b59f09f Move example folders to the 'coap' subdirectory
Change-Id: Iebded58e8cfd307cd54fc3bdcca3a1002aa21bd4
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2019-04-15 10:55:57 +00:00
Sona Kurazyan 551e79f4be Fix observation canceling in the simplecoapclient example
Changed th lambda for canceling the resource observation to capture
variables by value instead of capturing by reference. If we capture
'url' by reference, it will be already destroyed, when the lambda is
called.

Fixes: QTBUG-75156
Change-Id: I76792555d4eff8391b0a5075d45cd48b9e3bb918
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2019-04-15 09:07:17 +00:00
Sona Kurazyan df260c0893 Try to resolve host names in the simplecoapclient example
This will allow to specify hostames instead of IP addresses,
when running the example.

Change-Id: Ie7c6e1489508e590351a20b58e6a69510b1c4491
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2019-04-12 12:58:17 +00:00
Sona Kurazyan 89a3677c42 Add example documentation project
Change-Id: I00c8d6221aa730051733c48816aed3cc4f79abb4
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2019-04-10 09:38:44 +00:00
Sona Kurazyan da05c10e32 Rename the console example from 'testapp' to 'consolecoapclient'
Change-Id: I5d1375c195e8a8d1b25b71ab071e1531a77ce659
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2019-04-10 07:30:27 +00:00
Sona Kurazyan 1587a5a784 Remove the disabled method for setting a custom protocol
Firstly, the current QCoapProtocol interface only supports customizing
some parameters like timeouts, counters, etc., which can also be done
via the QCoapClient class, so there is no need for a setter method for
the protocol.

Secondly, the protocol runs on a separate thread, so it is not a good
idea to allow users to change the protocol at runtime. Even if later we
decide to support custom protocols, it can be set during the
construction of the client. So the setter method is not needed.

Removed the setter method and added the missing methods for customizing
protocol-related parameters.

Change-Id: I89375ac502be4d29d3cb617da9c2f99a3ab410ec
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2019-04-10 07:30:13 +00:00
Sona Kurazyan 6473d2e807 Add parameter for specifying the port for multicast discovery
Change-Id: I75db1a9fc3bf17df87a834a90d0e5bb5150ccc1c
Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
2019-03-29 12:32:43 +00:00
Sona Kurazyan 64b696e517 Close the DTLS connection during destruction
Change-Id: Id7bc8ac1506ae543c7964b0bdcacf39588cd7334
Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
2019-03-29 12:32:33 +00:00
Sona Kurazyan d1e1548ccf Initialize QCoapPrivateKey correctly
This fixes the handling of an empty QCoapPrivateKey.

Change-Id: I0dd92b2edcb0aacf56a8cb1933227f6673404f52
Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
2019-03-29 12:32:23 +00:00
Sona Kurazyan b2ddb9bc50 Add missing metatype declarations for QtCoap namespace
Change-Id: I5a98f9d27a1aeaa81ee7d132d44f9473c801e8cc
Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
2019-03-29 12:32:05 +00:00
Mikko Gronoff 6e7c7ee4af Add docs license file
Change-Id: I19cf64637c629fc6688aa811919edfec2837b9ae
Reviewed-by: Jani Heikkinen <jani.heikkinen@qt.io>
2019-03-27 11:26:29 +00:00
Sona Kurazyan de8abc2dd3 Do not capture q-pointer by reference
This fixes a crash introduced by one of the recent commits.

Change-Id: I4742a77585d764a1da8e07de44869b974009f626
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2019-03-22 08:20:58 +00:00
Sona Kurazyan 2e23643ce1 Add missing type registrations for enums from QtCoap namespace
Change-Id: Ie286cabb6a451899cf70a55aad4b8a85694ea56b
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2019-03-21 08:57:00 +00:00
Sona Kurazyan f28c1a1b93 Update the README file according to the latest changes
Change-Id: I600a7d1c933374bb021ee46cd3102408e04fb4b0
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2019-03-21 08:20:40 +00:00
Sona Kurazyan 7b72a8d270 Use Q_INVOKABLE for the methods not meant to be used as slots
Declaring methods to be invoked via QMetaObject::invokeMethod
in the Q_SLOTS section, makes the API confusing. Use Q_INVOKABLE
instead.

Change-Id: I1a04b279fe2ddb505e63dfd48efa1a3b4cb7ad7a
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
2019-03-20 08:19:22 +00:00
Sona Kurazyan 0868e398fe Hide the API for sending byte array requests
Users should not be able to send "manually" constructed requests
with raw byte array data. Only QCoapProtocol knows how to correctly
construct/send coap messages and make the proper signal/slot
connections.

Change-Id: I8fd64638ea7f8e7b20671b80e6db4e1a7758c4fa
Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2019-03-20 08:18:59 +00:00
Sona Kurazyan db37d03101 Add CoAP client example
Simple Qt Widgets based example demonstrating how to use CoAP API.
Covers:
 - Sending GET/POST/PUT/DELETE requests
 - Observing resources
 - Resource discovery

Change-Id: I2abb3fd670ff86958e73331413d1f0d0e8ce4a5d
Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2019-03-20 08:18:45 +00:00
Sona Kurazyan 7a3552189c Improve logging of the CoAP module
- Introduced different log categories and categorized
  log messages accordingly.

- Improved logs from console example by:
    * Changing debug messages to info or warning,
    * Removing extra spaces from the log messages.

Change-Id: Ia6b2006db5e7cce853e59fb7d0a1c20064444c8e
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2019-03-19 19:50:48 +00:00
Mikko Gronoff d11f60a695 Add license file
Change-Id: Ia45dac88c05a44fe0becc67f8ff382adfdbf837e
Reviewed-by: Jani Heikkinen <jani.heikkinen@qt.io>
2019-03-19 19:50:45 +00:00
Sona Kurazyan dcc2cb63e9 Add the sender address to responses for a multicast request
For the responses to multicast requests the address of the
sender of the reply does not match with the host address in
the request URI. There should be a way to find out who
has sent the response.

Change-Id: Icbc6c6ae926198870dbc7dbbb92dc319c46d7de7
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2019-03-11 16:53:50 +00:00
Sona Kurazyan 872ab757fd Hide APIs for specifying the request method
Since the request method is set anyway when sending a request
(get, put, post, etc.), allowing users to specify the request
method is fatuous (it will be overridden anyway when sending
the request).

Change-Id: Ibf079bd513f145c791d5d703aa5685bfe66dda7d
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2019-03-11 16:53:31 +00:00
Sona Kurazyan d9d26033bb Fix URL adjustment for URLs with no scheme
Prepend the "scheme://" part a to URL only if it is relative
and doesn't have a host. Non-relative URLs having a host already
contain the "://" part.

Change-Id: If2ac3db4f2eb0d18ffa1893415f44b9d2c85db26
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2019-03-06 10:01:08 +00:00
Sona Kurazyan 09d1d3bf20 Move resourcesFromCoreLinkList() where it fits better
Change-Id: I930f53462598fd7019da2144ddf1bf04dc5930c8
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2019-03-06 10:01:04 +00:00
Sona Kurazyan 6755d58fc8 Code cleanup: replace int by uint, where it makes sense
This saves us several checks and "static_cast"s.

Change-Id: I81e2253929f1fe0a7a052e8c2988e28229b0c9db
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2019-03-05 08:34:06 +00:00
Sona Kurazyan eb4fd1cd02 Improve the documentation and fix warnings
Change-Id: I9b26337ba976079608ece4781999ad0ef49a4f19
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2019-03-05 08:33:53 +00:00
Sona Kurazyan ebd1954617 Fix documentation for the QtCoap::Error enum
Change-Id: I3401d7f66f7f14273c07b2df236a047dca4d348f
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2019-03-04 13:06:17 +00:00
Sona Kurazyan 185575746b Change QtCoap to be a namespace and improve the docs
- QtCoap was changed to be a namespace instead of a class.
- Moved the static QtCoap::randomGenerator to a method returning
  a reference to a local static object.
- The corresponding documentation and function definitions were
  moved to its .cpp file.
- Added the missing documentation.

Change-Id: Ie0c60189b18b8f5e8d9a94f91b6fb7b9259984dd
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2019-03-04 13:06:08 +00:00
Sona Kurazyan 98b4ac3db7 Code cleanup: avoid calling lambdas with deleted contexts
Change-Id: I65e59f609decac4f7c26eb4980624a58c4d2bcb3
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2019-02-21 16:50:57 +00:00
Sona Kurazyan 7a60005561 Add an API for multicast discovery
Use CoAP multicast group addresses, if the user haven't
provided a group discovery URI.

Change-Id: Id4e4eedc2c4596d738b3e9c3c0461ca3feddf3ef
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
2019-02-21 16:18:14 +00:00
Sona Kurazyan 2588244a49 Fix resource discovery example
Change-Id: I56f8c2be5394b0ce9bb50cfda5d893ae44eb22ad
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2019-02-21 16:17:59 +00:00