summaryrefslogtreecommitdiff
path: root/CommonAPI-Examples/E01HelloWorld/src
diff options
context:
space:
mode:
Diffstat (limited to 'CommonAPI-Examples/E01HelloWorld/src')
-rw-r--r--CommonAPI-Examples/E01HelloWorld/src/E01HelloWorldClient.cpp56
-rw-r--r--CommonAPI-Examples/E01HelloWorld/src/E01HelloWorldService.cpp33
-rw-r--r--CommonAPI-Examples/E01HelloWorld/src/E01HelloWorldStubImpl.cpp24
-rw-r--r--CommonAPI-Examples/E01HelloWorld/src/E01HelloWorldStubImpl.hpp22
4 files changed, 135 insertions, 0 deletions
diff --git a/CommonAPI-Examples/E01HelloWorld/src/E01HelloWorldClient.cpp b/CommonAPI-Examples/E01HelloWorld/src/E01HelloWorldClient.cpp
new file mode 100644
index 0000000..111fd5f
--- /dev/null
+++ b/CommonAPI-Examples/E01HelloWorld/src/E01HelloWorldClient.cpp
@@ -0,0 +1,56 @@
+/* Copyright (C) 2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include <iostream>
+#include <string>
+
+#ifndef WIN32
+#include <unistd.h>
+#endif
+
+#include <CommonAPI/CommonAPI.hpp>
+#include <v0_1/commonapi/examples/E01HelloWorldProxy.hpp>
+
+using namespace v0_1::commonapi::examples;
+
+int main() {
+ CommonAPI::Runtime::setProperty("LogContext", "E01C");
+ CommonAPI::Runtime::setProperty("LibraryBase", "E01HelloWorld");
+
+ std::shared_ptr < CommonAPI::Runtime > runtime = CommonAPI::Runtime::get();
+
+ std::string domain = "local";
+ std::string instance = "commonapi.examples.HelloWorld";
+ std::string connection = "client-sample";
+
+ std::shared_ptr<E01HelloWorldProxy<>> myProxy = runtime->buildProxy<E01HelloWorldProxy>(domain,
+ instance, connection);
+
+ std::cout << "Checking availability!" << std::endl;
+ while (!myProxy->isAvailable())
+ usleep(10);
+ std::cout << "Available..." << std::endl;
+
+ const std::string name = "World";
+ CommonAPI::CallStatus callStatus;
+ std::string returnMessage;
+
+ CommonAPI::CallInfo info(1000);
+ info.sender_ = 1234;
+
+ while (true) {
+ myProxy->sayHello(name, callStatus, returnMessage, &info);
+ if (callStatus != CommonAPI::CallStatus::SUCCESS) {
+ std::cerr << "Remote call failed!\n";
+ return -1;
+ }
+ info.timeout_ = info.timeout_ + 1000;
+
+ std::cout << "Got message: '" << returnMessage << "'\n";
+ std::this_thread::sleep_for(std::chrono::seconds(1));
+ }
+
+ return 0;
+}
diff --git a/CommonAPI-Examples/E01HelloWorld/src/E01HelloWorldService.cpp b/CommonAPI-Examples/E01HelloWorld/src/E01HelloWorldService.cpp
new file mode 100644
index 0000000..f92ae81
--- /dev/null
+++ b/CommonAPI-Examples/E01HelloWorld/src/E01HelloWorldService.cpp
@@ -0,0 +1,33 @@
+/* Copyright (C) 2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include <iostream>
+#include <thread>
+
+#include <CommonAPI/CommonAPI.hpp>
+#include "E01HelloWorldStubImpl.hpp"
+
+using namespace std;
+
+int main() {
+ CommonAPI::Runtime::setProperty("LogContext", "E01S");
+ CommonAPI::Runtime::setProperty("LibraryBase", "E01HelloWorld");
+
+ std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::get();
+
+ std::string domain = "local";
+ std::string instance = "commonapi.examples.HelloWorld";
+ std::string connection = "service-sample";
+
+ std::shared_ptr<E01HelloWorldStubImpl> myService = std::make_shared<E01HelloWorldStubImpl>();
+ runtime->registerService(domain, instance, myService, connection);
+
+ while (true) {
+ std::cout << "Waiting for calls... (Abort with CTRL+C)" << std::endl;
+ std::this_thread::sleep_for(std::chrono::seconds(60));
+ }
+
+ return 0;
+}
diff --git a/CommonAPI-Examples/E01HelloWorld/src/E01HelloWorldStubImpl.cpp b/CommonAPI-Examples/E01HelloWorld/src/E01HelloWorldStubImpl.cpp
new file mode 100644
index 0000000..df13c01
--- /dev/null
+++ b/CommonAPI-Examples/E01HelloWorld/src/E01HelloWorldStubImpl.cpp
@@ -0,0 +1,24 @@
+/* Copyright (C) 2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "E01HelloWorldStubImpl.hpp"
+
+E01HelloWorldStubImpl::E01HelloWorldStubImpl() {
+}
+
+E01HelloWorldStubImpl::~E01HelloWorldStubImpl() {
+}
+
+void E01HelloWorldStubImpl::sayHello(const std::shared_ptr<CommonAPI::ClientId> _client,
+ std::string _name,
+ sayHelloReply_t _reply) {
+
+ std::stringstream messageStream;
+
+ messageStream << "Hello " << _name << "!";
+ std::cout << "sayHello('" << _name << "'): '" << messageStream.str() << "'\n";
+
+ _reply(messageStream.str());
+};
diff --git a/CommonAPI-Examples/E01HelloWorld/src/E01HelloWorldStubImpl.hpp b/CommonAPI-Examples/E01HelloWorld/src/E01HelloWorldStubImpl.hpp
new file mode 100644
index 0000000..83a4112
--- /dev/null
+++ b/CommonAPI-Examples/E01HelloWorld/src/E01HelloWorldStubImpl.hpp
@@ -0,0 +1,22 @@
+/* Copyright (C) 2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef E01HELLOWORLDSTUBIMPL_H_
+#define E01HELLOWORLDSTUBIMPL_H_
+
+#include <CommonAPI/CommonAPI.hpp>
+#include <v0_1/commonapi/examples/E01HelloWorldStubDefault.hpp>
+
+class E01HelloWorldStubImpl: public v0_1::commonapi::examples::E01HelloWorldStubDefault {
+
+public:
+ E01HelloWorldStubImpl();
+ virtual ~E01HelloWorldStubImpl();
+
+ virtual void sayHello(const std::shared_ptr<CommonAPI::ClientId> _client, std::string _name, sayHelloReply_t _return);
+
+};
+
+#endif /* E01HELLOWORLDSTUBIMPL_H_ */