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 Aug 21, 2022
1 parent ccf17ec commit 75c9ba2
Show file tree
Hide file tree
Showing 30 changed files with 1,371 additions and 967 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, 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, 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, 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, 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/coap_crop_rotation_deduplicator.dart';
Expand All @@ -40,3 +37,10 @@ export 'src/link-format/coap_web_link.dart';
export 'src/link-format/resources/coap_iresource.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.

26 changes: 14 additions & 12 deletions lib/src/coap_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import 'package:collection/collection.dart';
import 'package:synchronized/synchronized.dart';
import 'package:typed_data/typed_data.dart';

import 'coap_block_option.dart';
import 'coap_code.dart';
import 'coap_config.dart';
import 'coap_constants.dart';
Expand All @@ -21,8 +20,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/coap_iendpoint.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 @@ -131,7 +133,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 @@ -155,7 +157,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 @@ -180,7 +182,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 @@ -207,7 +209,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 @@ -236,7 +238,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 @@ -261,7 +263,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 @@ -291,7 +293,7 @@ class CoapClient {
unawaited(
() async {
final resp = await _waitForResponse(request);
if (!resp.hasOption(OptionType.observe)) {
if (!resp.hasOption<ObserveOption>()) {
relation.isCancelled = true;
}
}(),
Expand Down Expand Up @@ -378,7 +380,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 @@ -397,7 +399,7 @@ class CoapClient {
etags.forEach(request.addIfMatchOpaque);
break;
case MatchEtags.onNoneMatch:
etags.forEach(request.addIfNoneMatchOpaque);
request.addOption(IfNoneMatchOption());
}
}
if (earlyBlock2Negotiation) {
Expand Down
Loading

0 comments on commit 75c9ba2

Please sign in to comment.