Skip to content

Commit

Permalink
fixup! Implement ExposedThing functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Jul 9, 2024
1 parent d554d09 commit a748279
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 32 deletions.
102 changes: 72 additions & 30 deletions lib/src/core/implementation/exposed_thing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -288,84 +288,126 @@ class ExposedThing implements scripting_api.ExposedThing, ExposableThing {
}

@override
Stream<Content> handleObserveProperty(
String propertyName, {
Future<void> handleReadAllProperties(
List<String> propertyNames,
PropertyContentMap inputs, {
int? formIndex,
Map<String, Object>? uriVariables,
Object? data,
}) {
final property = _obtainProperty(propertyName);

// TODO: implement handleObserveProperty
// TODO: implement handleReadAllProperties
throw UnimplementedError();
}

@override
Future<void> handleReadAllProperties(
Future<PropertyContentMap> handleReadMultipleProperties(
List<String> propertyNames,
PropertyContentMap inputs, {
Content input, {
int? formIndex,
Map<String, Object>? uriVariables,
Object? data,
}) {
// TODO: implement handleReadAllProperties
// TODO: implement handleReadMultipleProperties
throw UnimplementedError();
}

@override
Future<PropertyContentMap> handleReadMultipleProperties(
Future<void> handleWriteMultipleProperties(
List<String> propertyNames,
Content input, {
int? formIndex,
Map<String, Object>? uriVariables,
Object? data,
}) {
// TODO: implement handleReadMultipleProperties
// TODO: implement handleWriteMultipleProperties
throw UnimplementedError();
}

@override
Stream<Content> handleSubscribeEvent(
String eventName, {
Future<void> handleObserveProperty(
String propertyName, {
int? formIndex,
Map<String, Object>? uriVariables,
Object? data,
}) {
// TODO: implement handleSubscribeEvent
throw UnimplementedError();
}) async {
final observeHandler = _propertyObserveHandlers[propertyName];

if (observeHandler == null) {
throw Exception(
"Observe handler for property $propertyName is not defined.",
);
}

await observeHandler(
data: data,
uriVariables: uriVariables,
formIndex: formIndex,
);
}

@override
Future<void> handleUnsubscribeEvent(
String eventName, {
Future<void> handleUnobserveProperty(
String propertyName, {
int? formIndex,
Map<String, Object>? uriVariables,
Object? data,
}) {
// TODO: implement handleUnsubscribeEvent
throw UnimplementedError();
}) async {
final unobserveHandler = _propertyUnobserveHandlers[propertyName];

if (unobserveHandler == null) {
throw Exception(
"Unobserve handler for property $propertyName is not defined.",
);
}

await unobserveHandler(
data: data,
uriVariables: uriVariables,
formIndex: formIndex,
);
}

@override
Future<void> handleWriteMultipleProperties(
List<String> propertyNames,
Content input, {
Future<void> handleSubscribeEvent(
String eventName, {
int? formIndex,
Map<String, Object>? uriVariables,
Object? data,
}) {
// TODO: implement handleWriteMultipleProperties
throw UnimplementedError();
}) async {
final subscribeHandler = _eventSubscribeHandlers[eventName];

if (subscribeHandler == null) {
throw Exception(
"Observe handler for property $eventName is not defined.",
);
}

await subscribeHandler(
data: data,
uriVariables: uriVariables,
formIndex: formIndex,
);
}

@override
Future<void> handleUnobserveProperty(
Future<void> handleUnsubscribeEvent(
String eventName, {
int? formIndex,
Map<String, Object>? uriVariables,
Object? data,
}) {
// TODO: implement handleUnobserveProperty
throw UnimplementedError();
}) async {
final unsubscribeHandler = _eventUnsubscribeHandlers[eventName];

if (unsubscribeHandler == null) {
throw Exception(
"Observe handler for property $eventName is not defined.",
);
}

await unsubscribeHandler(
data: data,
uriVariables: uriVariables,
formIndex: formIndex,
);
}
}
4 changes: 2 additions & 2 deletions lib/src/core/protocol_interfaces/exposable_thing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ abstract interface class ExposableThing {
});

/// Handles an `observeproperty` operation triggered by a TD consumer.
Stream<Content> handleObserveProperty(
Future<void> handleObserveProperty(
String eventName, {
int? formIndex,
Map<String, Object>? uriVariables,
Expand All @@ -86,7 +86,7 @@ abstract interface class ExposableThing {
});

/// Handles a `subscribeevent` operation triggered by a TD consumer.
Stream<Content> handleSubscribeEvent(
Future<void> handleSubscribeEvent(
String eventName, {
int? formIndex,
Map<String, Object>? uriVariables,
Expand Down

0 comments on commit a748279

Please sign in to comment.