| ## |
| ## Licensed to the Apache Software Foundation (ASF) under one |
| ## or more contributor license agreements. See the NOTICE file |
| ## distributed with this work for additional information |
| ## regarding copyright ownership. The ASF licenses this file |
| ## to you under the Apache License, Version 2.0 (the |
| ## "License"); you may not use this file except in compliance |
| ## with the License. You may obtain a copy of the License at |
| ## |
| ## http://www.apache.org/licenses/LICENSE-2.0 |
| ## |
| ## Unless required by applicable law or agreed to in writing, |
| ## software distributed under the License is distributed on an |
| ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| ## KIND, either express or implied. See the License for the |
| ## specific language governing permissions and limitations |
| ## under the License. |
| ## |
| #set($i = $intf.name()) |
| #set($intfname = "$i$suffix") |
| #set($baseclname = "Base$intfname") |
| #set($clname = "Impl$intfname") |
| #if ($helper.isServer($mc)) |
| #set($peer = "client") |
| #set($peerclass = "Remote${i}Client") |
| #else |
| #set($peer = "server") |
| #set($peerclass = "Remote${i}Server") |
| #end |
| |
| // This file automatically generated by: |
| // $version |
| // $now |
| // This file is automatically created for your convenience and will not be |
| // overwritten once it exists! Please edit this file as necessary to implement |
| // your service logic. |
| |
| \#include "${peerclass}.h" |
| #if ($helper.isServer($mc)) |
| \#include "Main${i}Listener.h" |
| \#include "Impl${i}Server.h" |
| #else |
| \#include "Main${i}Client.h" |
| \#include "Impl${i}Client.h" |
| #end |
| |
| \#include "capu/os/Thread.h" |
| \#include "common/EtchTypes.h" |
| \#include "support/EtchRuntime.h" |
| \#include "transport/EtchTransportData.h" |
| |
| |
| using namespace $namespace; |
| |
| #if ($helper.isServer($mc)) |
| ${i}Server* Main${i}Listener::new${i}Server(Remote${i}Client* client) |
| { |
| return new Impl${i}Server(client); |
| } |
| |
| /** |
| * Main program for ${i}Server. |
| * |
| * @param args command line arguments. |
| * @throws Exception |
| */ |
| int main(int argc, const char* argv[]) |
| { |
| status_t status; |
| |
| EtchRuntime* runtime = new EtchRuntime(); |
| status = runtime->start(); |
| if (status != ETCH_OK) { |
| //TODO Handle error |
| } |
| |
| //TODO Change to correct URI |
| EtchString uri("tcp://0.0.0.0:4001"); |
| |
| Main${i}Listener main${i}listener; |
| |
| EtchServerFactory *listener; |
| status = ${i}Helper::newListener(runtime, uri, NULL, &main${i}listener, listener); |
| if (status != ETCH_OK) { |
| //TODO Handle error |
| } |
| |
| // Start the Listener |
| status = listener->transportControl(new EtchString(EtchTransportData::START_AND_WAIT_UP()), new EtchInt32(4000)); |
| if (status != ETCH_OK) { |
| //TODO Handle error |
| } |
| |
| //Wait for finish... |
| capu::Thread::Sleep(20000); |
| |
| //Stop the Listener |
| status = listener->transportControl(new EtchString(EtchTransportData::STOP_AND_WAIT_DOWN()), new EtchInt32(4000)); |
| if (status != ETCH_OK) { |
| //TODO Handle error |
| } |
| |
| delete listener; |
| |
| |
| status = runtime->shutdown(); |
| if (status != ETCH_OK) { |
| //TODO Handle error |
| } |
| |
| delete runtime; |
| return 0; |
| } |
| |
| #else |
| ${i}Client* Main${i}Client::new${i}Client(Remote${i}Server* server) |
| { |
| return new Impl${i}Client(server); |
| } |
| |
| /** |
| * Main program for ${i}Client. |
| * |
| * @param args command line arguments. |
| * @throws Exception |
| */ |
| capu::int32_t main(int argc, const char* argv[]) |
| { |
| status_t status; |
| |
| EtchRuntime* runtime = new EtchRuntime(); |
| status = runtime->start(); |
| if (status != ETCH_OK) { |
| //TODO Handle error |
| } |
| |
| // TODO Change to correct URI |
| EtchString uri("tcp://127.0.0.1:4001"); |
| |
| Main${i}Client mc; |
| |
| Remote${i}Server *remote = NULL; |
| status = ${i}Helper::newServer(runtime, uri, NULL, mc, remote); |
| if (status != ETCH_OK) { |
| //TODO Handle error |
| } |
| |
| // Connect to the service |
| status = remote->transportControl(new EtchString(EtchTransportData::START_AND_WAIT_UP()), new EtchInt32(4000)); |
| if (status != ETCH_OK) { |
| //TODO Handle error |
| } |
| |
| //Add calls to remote here |
| |
| // Disconnect from the service |
| status = remote->transportControl(new EtchString(EtchTransportData::STOP_AND_WAIT_DOWN()), new EtchInt32(4000)); |
| if (status != ETCH_OK) { |
| //TODO Handle error |
| } |
| |
| delete remote; |
| |
| result = runtime->shutdown(); |
| |
| delete runtime; |
| return 0; |
| } |
| |
| #end |