Skip to content

Commit

Permalink
added config for test server
Browse files Browse the repository at this point in the history
  • Loading branch information
krjw-eyev committed Jul 5, 2023
1 parent 6c7038d commit c1f3378
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 108 deletions.
1 change: 1 addition & 0 deletions lib/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@ export 'src/domain/repositories/trigger_repository.dart' show TriggerRepository;
export 'src/domain/repositories/versions_repository.dart' show VersionsRepository;
export 'src/domain/repositories/video_stream_repository.dart' show VideoStreamRepository;
export 'src/et.dart' show ET, Connection;
export 'src/test/skyle_simulated_service.dart' show SkyleSimulatedServiceConfiguration;
export 'src/test/test_client.dart' show TestClient;
export 'src/test/test_server.dart' show TestServer;
27 changes: 19 additions & 8 deletions lib/src/test/skyle_simulated_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,20 @@ import '../generated/Skyle.pbgrpc.dart';
import '../generated/google/protobuf/empty.pb.dart';
import 'positionings.dart';

class SkyleSimulatedServiceConfiguration {
final bool positioningStream;
final bool gazeStream;
SkyleSimulatedServiceConfiguration({
this.gazeStream = true,
this.positioningStream = true,
});
}

class SkyleSimulatedService extends SkyleServiceBase {
final SkyleSimulatedServiceConfiguration config;

SkyleSimulatedService({required this.config});

Options options = defaultOptions;
List<Profile> profiles = [defaultProfile];
Profile currentP = defaultProfile;
Expand Down Expand Up @@ -145,6 +158,7 @@ class SkyleSimulatedService extends SkyleServiceBase {

@override
Stream<Point> gaze(ServiceCall call, Empty request) async* {
if (!config.gazeStream) return;
while (!call.isCanceled) {
for (final gaze in gazes) {
yield gaze;
Expand Down Expand Up @@ -172,6 +186,7 @@ class SkyleSimulatedService extends SkyleServiceBase {

@override
Stream<PositioningMessage> positioning(ServiceCall call, Empty request) async* {
if (!config.positioningStream) return;
for (final positioning in positionings) {
yield positioning;
await Future.delayed(const Duration(milliseconds: 20));
Expand Down Expand Up @@ -223,26 +238,22 @@ class SkyleSimulatedService extends SkyleServiceBase {

@override
Stream<TriggerMessage> trigger(ServiceCall call, Empty request) {
// TODO(krjw-eyev): implement trigger
throw UnimplementedError();
return Stream.empty();
}

@override
Stream<Point> cursorCalibration(ServiceCall call, Stream<CalibCursorMessages> request) {
// TODO(krjw-eyev): implement cursorCalibration
throw UnimplementedError();
return Stream.empty();
}

@override
Stream<BinocularGaze> rawBinocularGaze(ServiceCall call, Empty request) {
// TODO: implement rawBinocularGaze
throw UnimplementedError();
return Stream.empty();
}

@override
Stream<RawImage> rawImages(ServiceCall call, Empty request) {
// TODO: implement rawImages
throw UnimplementedError();
return Stream.empty();
}
}

Expand Down
9 changes: 6 additions & 3 deletions lib/src/test/test_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ import 'constants.dart';
import 'skyle_simulated_service.dart';

class TestServer {
final service = SkyleSimulatedService();
final SkyleSimulatedService service;
late Server _server;
_MJPEGTestServer? _mjpegTestServer;

TestServer({String imagePath = 'assets'}) {
_server = Server([service]);
TestServer({
String imagePath = 'assets',
SkyleSimulatedServiceConfiguration? config,
}) : service = SkyleSimulatedService(config: config ?? SkyleSimulatedServiceConfiguration()) {
_server = Server.create(services: [service]);
_mjpegTestServer = _MJPEGTestServer(imagePath: imagePath, service: service);
}

Expand Down
Loading

0 comments on commit c1f3378

Please sign in to comment.