Skip to content

Commit

Permalink
refactor: rework option system
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Oct 16, 2022
1 parent 6738dec commit 6973cca
Show file tree
Hide file tree
Showing 32 changed files with 1,404 additions and 970 deletions.
2 changes: 1 addition & 1 deletion example/log_events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ FutureOr<void> main() async {
final uri = Uri(scheme: 'coap', host: 'coap.me', port: conf.defaultPort);
final client = CoapClient(uri, config: conf);

final opt = CoapOption.createUriQuery(
final opt = UriQueryOption(
'${LinkFormatParameter.title.short}=This is an SJH Post request',
);

Expand Down
2 changes: 1 addition & 1 deletion example/post_blockwise.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ FutureOr<void> main() async {
final uri = Uri(scheme: 'coap', host: 'coap.me', port: conf.defaultPort);
final client = CoapClient(uri, config: conf);

final opt = CoapOption.createUriQuery(
final opt = UriQueryOption(
'${LinkFormatParameter.title.short}=This is an SJH Post request',
);

Expand Down
2 changes: 1 addition & 1 deletion example/post_resource.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ FutureOr<void> main() async {
final uri = Uri(scheme: 'coap', host: 'coap.me', port: conf.defaultPort);
final client = CoapClient(uri, config: conf);

final opt = CoapOption.createUriQuery(
final opt = UriQueryOption(
'${LinkFormatParameter.title.short}=This is an SJH Post request',
);

Expand Down
4 changes: 2 additions & 2 deletions example/put_resource.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ FutureOr<void> main() async {
final uri = Uri(scheme: 'coap', host: 'coap.me', port: conf.defaultPort);
final client = CoapClient(uri, config: conf);

final opt = CoapOption.createUriQuery(
'${LinkFormatParameter.title}=This is an SJH Put request',
final opt = UriQueryOption(
'${LinkFormatParameter.title.short}=This is an SJH Put request',
);

try {
Expand Down
10 changes: 7 additions & 3 deletions lib/coap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export 'config/coap_config_openssl.dart';
export 'config/coap_config_tinydtls.dart';

/// The Coap package exported interface
export 'src/coap_block_option.dart';
export 'src/coap_client.dart';
export 'src/coap_code.dart';
export 'src/coap_config.dart';
Expand All @@ -25,8 +24,6 @@ export 'src/coap_defined_address.dart';
export 'src/coap_media_type.dart';
export 'src/coap_message_type.dart';
export 'src/coap_observe_client_relation.dart';
export 'src/coap_option.dart';
export 'src/coap_option_type.dart';
export 'src/coap_request.dart';
export 'src/coap_response.dart';
export 'src/deduplication/crop_rotation_deduplicator.dart';
Expand All @@ -40,3 +37,10 @@ export 'src/link-format/coap_web_link.dart';
export 'src/link-format/resources/coap_resource.dart';
export 'src/network/credentials/ecdsa_keys.dart';
export 'src/network/credentials/psk_credentials.dart';
export 'src/option/coap_block_option.dart';
export 'src/option/empty_option.dart';
export 'src/option/integer_option.dart';
export 'src/option/opaque_option.dart';
export 'src/option/option.dart';
export 'src/option/oscore_option.dart';
export 'src/option/string_option.dart';
104 changes: 0 additions & 104 deletions lib/src/coap_block_option.dart

This file was deleted.

36 changes: 19 additions & 17 deletions lib/src/coap_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import 'package:synchronized/synchronized.dart';
import 'package:typed_data/typed_data.dart';

import '../config/coap_config_default.dart';
import 'coap_block_option.dart';
import 'coap_code.dart';
import 'coap_config.dart';
import 'coap_constants.dart';
Expand All @@ -22,8 +21,6 @@ import 'coap_media_type.dart';
import 'coap_message.dart';
import 'coap_message_type.dart';
import 'coap_observe_client_relation.dart';
import 'coap_option.dart';
import 'coap_option_type.dart';
import 'coap_request.dart';
import 'coap_response.dart';
import 'event/coap_event_bus.dart';
Expand All @@ -34,8 +31,13 @@ import 'net/endpoint.dart';
import 'network/coap_inetwork.dart';
import 'network/credentials/ecdsa_keys.dart';
import 'network/credentials/psk_credentials.dart';
import 'option/coap_block_option.dart';
import 'option/empty_option.dart';
import 'option/integer_option.dart';
import 'option/option.dart';

/// The matching scheme to use for supplied ETags on PUT
// FIXME: The name MatchETags might be a bit misleading, c.f. https://datatracker.ietf.org/doc/html/rfc7252#section-5.10.8.2
enum MatchEtags {
/// When the ETag matches
onMatch,
Expand Down Expand Up @@ -136,7 +138,7 @@ class CoapClient {
final String path, {
final CoapMediaType? accept,
final bool confirmable = true,
final List<CoapOption>? options,
final List<Option<Object?>>? options,
final bool earlyBlock2Negotiation = false,
final int maxRetransmit = 0,
final CoapMulticastResponseHandler? onMulticastResponse,
Expand All @@ -160,7 +162,7 @@ class CoapClient {
final CoapMediaType? format,
final CoapMediaType? accept,
final bool confirmable = true,
final List<CoapOption>? options,
final List<Option<Object?>>? options,
final bool earlyBlock2Negotiation = false,
final int maxRetransmit = 0,
final CoapMulticastResponseHandler? onMulticastResponse,
Expand All @@ -185,7 +187,7 @@ class CoapClient {
final CoapMediaType? format,
final CoapMediaType? accept,
final bool confirmable = true,
final List<CoapOption>? options,
final List<Option<Object?>>? options,
final bool earlyBlock2Negotiation = false,
final int maxRetransmit = 0,
final CoapMulticastResponseHandler? onMulticastResponse,
Expand All @@ -212,7 +214,7 @@ class CoapClient {
final bool confirmable = true,
final List<Uint8Buffer>? etags,
final MatchEtags matchEtags = MatchEtags.onMatch,
final List<CoapOption>? options,
final List<Option<Object?>>? options,
final bool earlyBlock2Negotiation = false,
final int maxRetransmit = 0,
final CoapMulticastResponseHandler? onMulticastResponse,
Expand Down Expand Up @@ -241,7 +243,7 @@ class CoapClient {
final List<Uint8Buffer>? etags,
final CoapMediaType? accept,
final bool confirmable = true,
final List<CoapOption>? options,
final List<Option<Object?>>? options,
final bool earlyBlock2Negotiation = false,
final int maxRetransmit = 0,
final CoapMulticastResponseHandler? onMulticastResponse,
Expand All @@ -266,7 +268,7 @@ class CoapClient {
final String path, {
final CoapMediaType? accept,
final bool confirmable = true,
final List<CoapOption>? options,
final List<Option<Object?>>? options,
final bool earlyBlock2Negotiation = false,
final int maxRetransmit = 0,
final CoapMulticastResponseHandler? onMulticastResponse,
Expand All @@ -292,7 +294,7 @@ class CoapClient {
final String path, {
final CoapMediaType? accept,
final bool confirmable = true,
final List<CoapOption>? options,
final List<Option<Object?>>? options,
final bool earlyBlock2Negotiation = false,
final int maxRetransmit = 0,
final CoapMulticastResponseHandler? onMulticastResponse,
Expand Down Expand Up @@ -322,7 +324,7 @@ class CoapClient {
final bool confirmable = true,
final List<Uint8Buffer>? etags,
final MatchEtags matchEtags = MatchEtags.onMatch,
final List<CoapOption>? options,
final List<Option<Object?>>? options,
final bool earlyBlock2Negotiation = false,
final int maxRetransmit = 0,
final CoapMulticastResponseHandler? onMulticastResponse,
Expand Down Expand Up @@ -355,7 +357,7 @@ class CoapClient {
final List<Uint8Buffer>? etags,
final CoapMediaType? accept,
final bool confirmable = true,
final List<CoapOption>? options,
final List<Option<Object?>>? options,
final bool earlyBlock2Negotiation = false,
final int maxRetransmit = 0,
final CoapMulticastResponseHandler? onMulticastResponse,
Expand Down Expand Up @@ -388,7 +390,7 @@ class CoapClient {
final bool confirmable = true,
final List<Uint8Buffer>? etags,
final MatchEtags matchEtags = MatchEtags.onMatch,
final List<CoapOption>? options,
final List<Option<Object?>>? options,
final bool earlyBlock2Negotiation = false,
final int maxRetransmit = 0,
final CoapMulticastResponseHandler? onMulticastResponse,
Expand Down Expand Up @@ -421,7 +423,7 @@ class CoapClient {
final List<Uint8Buffer>? etags,
final CoapMediaType? accept,
final bool confirmable = true,
final List<CoapOption>? options,
final List<Option<Object?>>? options,
final bool earlyBlock2Negotiation = false,
final int maxRetransmit = 0,
final CoapMulticastResponseHandler? onMulticastResponse,
Expand Down Expand Up @@ -454,7 +456,7 @@ class CoapClient {
unawaited(
() async {
final resp = await _waitForResponse(request, responseStream);
if (!resp.hasOption(OptionType.observe)) {
if (!resp.hasOption<ObserveOption>()) {
relation.isCancelled = true;
}
}(),
Expand Down Expand Up @@ -561,7 +563,7 @@ class CoapClient {
final CoapRequest request,
final String path,
final CoapMediaType? accept,
final List<CoapOption>? options,
final List<Option<Object?>>? options,
final bool earlyBlock2Negotiation,
final int maxRetransmit, {
final MatchEtags matchEtags = MatchEtags.onMatch,
Expand All @@ -580,7 +582,7 @@ class CoapClient {
etags.forEach(request.addIfMatchOpaque);
break;
case MatchEtags.onNoneMatch:
etags.forEach(request.addIfNoneMatchOpaque);
request.addOption(IfNoneMatchOption());
}
}
if (earlyBlock2Negotiation) {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/coap_empty_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'coap_code.dart';
import 'coap_constants.dart';
import 'coap_message.dart';
import 'coap_message_type.dart';
import 'coap_option.dart';
import 'option/option.dart';

/// Represents an empty CoAP message. An empty message has either
/// the MessageType ACK or RST.
Expand Down Expand Up @@ -47,7 +47,7 @@ class CoapEmptyMessage extends CoapMessage {
required final CoapMessageType type,
required final int id,
required final Uint8Buffer token,
required final List<CoapOption> options,
required final List<Option<Object?>> options,
required final Uint8Buffer? payload,
required final bool hasUnknownCriticalOption,
required final bool hasFormatError,
Expand Down
Loading

0 comments on commit 6973cca

Please sign in to comment.