Skip to content

Commit 82053e2

Browse files
fix: change order on starting olink service
Adds information that server should be started when all services are added to registry. Changes order of starting a server in examples. If client wants to make a connection before the server is up, the olink client will reconnect until it will succeed. On server start, connection gets established, but if a services is not already to service, the Olink will fail to link service side with a client side. To avoid such sitiation the services should be added to registry befor server starts listening.
1 parent 6887248 commit 82053e2

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

docs/docs/features/olink.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,15 @@ As mentioned earlier you need a network layer, here provided by a `ApiGear::Obje
184184
// Prepare the registry, the server, and an object which you want to expose.
185185
ApiGear::ObjectLink::RemoteRegistry registry;
186186
ApiGear::ObjectLink::OLinkHost server(registry);
187-
server.listen("localhost", 8182);
188187
auto ioWorldHello = std::make_shared<io_world::Hello>();
189188
190189
// Create your OLinkHelloAdapter and add it to registry.
191190
auto ioWorldOlinkHelloService = std::make_shared<io_world::OLinkHelloAdapter>(registry, ioWorldHello.get());
192191
registry.addSource(ioWorldOlinkHelloService);
193192
193+
// Start server with source added to registry.
194+
server.listen("localhost", 8182);
195+
194196
// use your ioWorldHello implementation, all property changes, and signals will be passed to connected OLink clients.
195197
auto lastMessage = ioWorldHello->last();
196198
ioWorldHello->say(lastMessage, io_world::When::Soon);

goldenmaster/examples/olinkserver/main.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ int main(int argc, char *argv[]){
8787

8888
QCoreApplication app(argc, argv); ApiGear::ObjectLink::RemoteRegistry registry;
8989
ApiGear::ObjectLink::OLinkHost server(registry);
90-
server.listen("localhost", 8182);
9190
auto testbed2ManyParamInterface = std::make_shared<testbed2::ManyParamInterface>();
9291
testbed2::ManyParamInterfaceTraced testbed2ManyParamInterfaceTraced(testbed2ManyParamInterface );
9392
auto testbed2OlinkManyParamInterfaceService = std::make_shared<testbed2::OLinkManyParamInterfaceAdapter>(registry, &testbed2ManyParamInterfaceTraced);
@@ -180,6 +179,10 @@ int main(int argc, char *argv[]){
180179
counter::CounterTraced counterCounterTraced(counterCounter );
181180
auto counterOlinkCounterService = std::make_shared<counter::OLinkCounterAdapter>(registry, &counterCounterTraced);
182181
registry.addSource(counterOlinkCounterService);
182+
183+
// Start your server after all the services are added.
184+
// This way you are sure that any new client that connects, will find the source it needs.
185+
server.listen("localhost", 8182);
183186

184187
auto result = app.exec();
185188
// Use the server.

templates/examples/olinkserver/main.cpp.tpl

+4-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ int main(int argc, char *argv[]){
2929
3030
QCoreApplication app(argc, argv); ApiGear::ObjectLink::RemoteRegistry registry;
3131
ApiGear::ObjectLink::OLinkHost server(registry);
32-
server.listen("localhost", 8182);
3332
3433
{{- range.System.Modules }}
3534
{{- $module := . }}
@@ -50,6 +49,10 @@ int main(int argc, char *argv[]){
5049
registry.addSource( {{- $serviceInstanceName }});
5150
{{- end }}
5251
{{- end }}
52+
53+
// Start your server after all the services are added.
54+
// This way you are sure that any new client that connects, will find the source it needs.
55+
server.listen("localhost", 8182);
5356

5457
auto result = app.exec();
5558
// Use the server.

0 commit comments

Comments
 (0)