diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-16 06:33:33 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-16 06:33:33 +0000 |
commit | b72b7e219af9b9c6826372eeb581ee85ca653d75 (patch) | |
tree | aae8306f2fa82b755681935bc0315d775490c9d1 /sca-cpp/tags/cpp-0.1.incubating-M1-final/sca/samples/Calculator/Client | |
parent | c0a2dcce89b1f374fc1987753dd28c6541bbbfe5 (diff) |
Cleaning up SVN structure, moving tag under sca-cpp/tags.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@880617 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp/tags/cpp-0.1.incubating-M1-final/sca/samples/Calculator/Client')
6 files changed, 393 insertions, 0 deletions
diff --git a/sca-cpp/tags/cpp-0.1.incubating-M1-final/sca/samples/Calculator/Client/Calc.cpp b/sca-cpp/tags/cpp-0.1.incubating-M1-final/sca/samples/Calculator/Client/Calc.cpp new file mode 100644 index 0000000000..124cf96c63 --- /dev/null +++ b/sca-cpp/tags/cpp-0.1.incubating-M1-final/sca/samples/Calculator/Client/Calc.cpp @@ -0,0 +1,172 @@ +/* + * + * Copyright 2006 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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. + */ + + +#include "Calculator.h" +#include "osoa/sca/sca.h" +using namespace osoa::sca; +using namespace std; +#include "tuscany/sca/core/TuscanyRuntime.h" +using namespace tuscany::sca; + +#include <iostream> +#include <stdlib.h> +using namespace std; + + +void usage(); +bool IsNumber(const char *p); + +int main(int argc, char* argv[]) +{ + const char *operation; + float arg1 = 0; + float arg2 = 0; + + if (argc == 4) + { + operation = argv[1]; + + if (!IsNumber(argv[2])) + { + cout << "Calc.exe: Argument 1 is not a number" << endl; + usage(); + } + else + { + arg1 = atof(argv[2]); + } + + if (!IsNumber(argv[3])) + { + cout << "Calc.exe: Argument 2 is not a number" << endl; + usage(); + } + else + { + arg2 = atof(argv[3]); + } + } + else + { + usage(); + } + + try + { + // Set the default module environment variable: <subsystem>/<moduleName> + string systemRoot = getenv("TUSCANY_SCACPP"); + if (systemRoot == "") + { + cout << "TUSCANY_SCACPP environment variable not set" <<endl; + return -1; + } + systemRoot += "/../samples/Calculator/deploy"; + + char *defaultModule = "CalculatorSubsystem/CalculatorService"; + +// TuscanyRuntime rt; +// rt.setSystemRoot(systemRoot); +// rt.setDefaultModuleComponent(defaultModule); +// rt.start(); + + // Locate a service + ModuleContext myContext = ModuleContext::getCurrent(); + Calculator *calcService = (Calculator*) myContext.locateService("CalculatorServiceComponent"); + if (calcService == 0) + { + cout << "Calc.exe: Unable to find Calculator service" << endl; + } + else + { + try + { + float result = 0; + if (strcmp(operation, "add") == 0) + { + result = calcService->add(arg1, arg2); + cout << "Calculator: add(" << arg1 << "," << arg2 << ") = " << result << endl; + } + else + if (strcmp(operation, "sub") == 0) + { + result = calcService->sub(arg1, arg2); + cout << "Calculator: sub(" << arg1 << "," << arg2 << ") = " << result << endl; + } + else + if (strcmp(operation, "mul") == 0) + { + result = calcService->mul(arg1, arg2); + cout << "Calculator: mul(" << arg1 << "," << arg2 << ") = " << result << endl; + } + else + if (strcmp(operation, "div") == 0) + { + result = calcService->div(arg1, arg2); + cout << "Calculator: div(" << arg1 << "," << arg2 << ") = " << result << endl; + } + else + { + cout << "Calculator: Unrecognized operation: " << operation << endl; + } + } + catch (char* x) + { + cout << "Calc.exe: exception caught: " << x << endl; + } + } + + } + catch (ServiceRuntimeException& ex) + { + cout << ex << endl; + } + return 0; +} + +void usage() +{ + cout << "Usage: calc add|sub|mul|div arg1 arg2" << endl; + exit(1); +} + +bool IsNumber (const char *p) +{ + int len = strlen(p); + int pointcount = 0; + + if (!isdigit (p[0]) && p[0] != '-' && p[0] != '+') + { + return false; + } + for (int i = 1; i < len; i++) + { + if (!isdigit (p[i])) + { + if (p[i] == '.') + { + if (pointcount > 0) return false; + pointcount++; + } + else + { + return false; + } + } + } + return true; +} diff --git a/sca-cpp/tags/cpp-0.1.incubating-M1-final/sca/samples/Calculator/Client/Calculator.h b/sca-cpp/tags/cpp-0.1.incubating-M1-final/sca/samples/Calculator/Client/Calculator.h new file mode 100644 index 0000000000..57975548c1 --- /dev/null +++ b/sca-cpp/tags/cpp-0.1.incubating-M1-final/sca/samples/Calculator/Client/Calculator.h @@ -0,0 +1,32 @@ +/* + * + * Copyright 2006 The Apache Software Foundation or its licensors, as applicable. + * + * Licensed 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. + */ + + +#ifndef CALCULATOR_H +#define CALCULATOR_H +class Calculator +{ +public: + virtual float add(float arg1, float arg2) = 0; + virtual float sub(float arg1, float arg2) = 0; + virtual float mul(float arg1, float arg2) = 0; + virtual float div(float arg1, float arg2) = 0; +}; + +#endif + + diff --git a/sca-cpp/tags/cpp-0.1.incubating-M1-final/sca/samples/Calculator/Client/Makefile.am b/sca-cpp/tags/cpp-0.1.incubating-M1-final/sca/samples/Calculator/Client/Makefile.am new file mode 100644 index 0000000000..75052b5bc0 --- /dev/null +++ b/sca-cpp/tags/cpp-0.1.incubating-M1-final/sca/samples/Calculator/Client/Makefile.am @@ -0,0 +1,27 @@ +deploydir=$(prefix)/samples/Calculator/deploy +prgbindir=$(deploydir)/bin + +prgbin_PROGRAMS = calculator_client +prgbin_SCRIPTS = runclient.sh +EXTRA_DIST = runclient.sh + +AM_CPPFLAGS = $(CPPFLAGS) +calculator_client_SOURCES = Calc.cpp + +calculator_client_LDADD = -L${TUSCANY_SCACPP}/lib -ltuscany_sca -ltuscany_sca_ws_reference \ + -L${TUSCANY_SDOCPP}/lib -ltuscany_sdo -ltuscany_sdo_axiom \ + -L$(AXIS2C_HOME)/lib \ + -laxis2_util \ + -laxis2_axiom \ + -laxis2_wsdl \ + -laxis2_engine \ + -laxis2_parser \ + -laxis2_minizip \ + -lpthread \ + -laxis2_http_sender \ + -laxis2_http_receiver + + +INCLUDES = -I$(top_builddir)/Calculator/CalculatorModule \ + -I${TUSCANY_SCACPP}/include \ + -I${TUSCANY_SDOCPP}/include diff --git a/sca-cpp/tags/cpp-0.1.incubating-M1-final/sca/samples/Calculator/Client/readme.txt b/sca-cpp/tags/cpp-0.1.incubating-M1-final/sca/samples/Calculator/Client/readme.txt new file mode 100644 index 0000000000..62672483af --- /dev/null +++ b/sca-cpp/tags/cpp-0.1.incubating-M1-final/sca/samples/Calculator/Client/readme.txt @@ -0,0 +1,64 @@ +Tuscany SCA for C++ Samples - Calculator Sample +=============================================== + +This is a very simple sample to show how an SCA module with a single component +can be built and called from an executable. + +There are three sub projects in this workspace: + - CalculatorModule + This contains the source code and SCA artifacts for the SCA module. This + is the module that will be deployed into the SCA runtime. + - CalculatorSubsystem + This contains the sca.subsystem file which describes a subsystem to the + SCA runtime. + - Client + An example client which will call the service exposed by the single component + in the CalculatorModule. + + +Build instructions +------------------ + +Notes: + +The projects are set up to locate SCA and SDO libraries using the environment variables +TUSCANY_SCACPP and TUSCANY_SDOCPP. These must be set before building. + +scagan is a code generation tool written in java. This will need to be built before you +can run it. To build scagen, you must go to the tools/scagen directory, and type "ant". +(You must have apache ant installed, and have a valid java virtual machine installed - +upwards of version 1.4.2). Once scagen has successfully built, it can be run from the +sca/bin directory. + +1) Build the SCA module. + - Set CalculatorModule project as the active project. + Right click->Set as active project + + - Run the SCA generation tool to create the proxy and wrapper classes. + Either Tools->SCA Gen if you have added SCA Gen as an external tool + Or run from the command line: + scagen -dir <projectDirectory> -output <projectDirectory> + where the projectDirectory is the directory with the sca.module file. + + - Rebuild All + Build->Rebuild All + +2) Package and deploy the SCA module + - There is a script file in the sca/samples/Calculator directory which will + copy across all the files needed for deployment to the Tuscany runtime. + On a command line run pack_deploy.cmd + As a default, the sample will be copied to sca/samples/runtime directory + Both the SCA module and the subsystem will be copied. + +3) Build the client + - Set the Client project as the active project. + Right click->Set as active project + + - Rebuild All + Build->Rebuild All + +4) Run the client + - Use the command file in the sca/samples/Calculator/Client directory to run the + client. This command file will set the SCA environment variables before running + the client. For example, + runclient add 4 9 diff --git a/sca-cpp/tags/cpp-0.1.incubating-M1-final/sca/samples/Calculator/Client/runclient.cmd b/sca-cpp/tags/cpp-0.1.incubating-M1-final/sca/samples/Calculator/Client/runclient.cmd new file mode 100644 index 0000000000..1758d12ef5 --- /dev/null +++ b/sca-cpp/tags/cpp-0.1.incubating-M1-final/sca/samples/Calculator/Client/runclient.cmd @@ -0,0 +1,51 @@ +@echo off + + +@REM Copyright 2006 The Apache Software Foundation or its licensors, as applicable. +@REM +@REM Licensed under the Apache License, Version 2.0 (the "License"); +@REM you may not use this file except in compliance with the License. +@REM You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, software +@REM distributed under the License is distributed on an "AS IS" BASIS, +@REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@REM See the License for the specific language governing permissions and +@REM limitations under the License. + +rem Runs the client after setting the SCA environment variables to use the +rem CalculatorSubsystem +setlocal + +if "%AXIS2C_HOME%" == "" ( +echo "AXIS2C_HOME not set" +goto end +) +echo using Axis2C: %AXIS2C_HOME% + +if "%TUSCANY_SDOCPP%" == "" ( +echo "TUSCANY_SDOCPP not set" +goto end +) +echo using TUSCANY_SDOCPP: %TUSCANY_SDOCPP% + +if "%TUSCANY_SCACPP%" == "" ( +echo "TUSCANY_SCACPP not set" +goto end +) +echo using TUSCANY_SCACPP: %TUSCANY_SCACPP% + +set TUSCANY_SCACPP_SYSTEM_ROOT=%~d0%~p0\..\ + +rem Only need to specify the subsystem (and not the moduleComponent as well) because +rem there is only one moduleComponent in the subsystem - it is a very simple sample. +set TUSCANY_SCACPP_DEFAULT_MODULE=CalculatorSubsystem + +rem Run the client + +set PATH=%TUSCANY_SCACPP%\bin;%TUSCANY_SDOCPP%\bin;%AXIS2C_HOME%\lib;%PATH% +Client.exe %* +:end +endlocal diff --git a/sca-cpp/tags/cpp-0.1.incubating-M1-final/sca/samples/Calculator/Client/runclient.sh b/sca-cpp/tags/cpp-0.1.incubating-M1-final/sca/samples/Calculator/Client/runclient.sh new file mode 100755 index 0000000000..4dfea2f4a8 --- /dev/null +++ b/sca-cpp/tags/cpp-0.1.incubating-M1-final/sca/samples/Calculator/Client/runclient.sh @@ -0,0 +1,47 @@ +#!/bin/sh + +# Copyright 2005 The Apache Software Foundation or its licensors, as applicable. +# +# Licensed 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. + +APFULLDIR=`pwd` + +if [ x$TUSCANY_SCACPP = x ]; then +echo "TUSCANY_SCACPP not set" +exit; +fi +echo "Using SCA installed at $TUSCANY_SCACPP" + +if [ x$TUSCANY_SDOCPP = x ]; then +echo "TUSCANY_SDOCPP not set" +exit; +fi +echo "Using SDO installed at $TUSCANY_SDOCPP" + +if [ x$AXIS2C_HOME = x ]; then +echo "AXIS2C_HOME not set" +exit; +fi +echo "Using Axis2C installed at $AXIS2C_HOME" + +TEST_SYSTEM=$APFULLDIR/../ + +export LD_LIBRARY_PATH=$TUSCANY_SCACPP/lib:$TUSCANY_SDOCPP/lib:$AXIS2C_HOME/lib:$LD_LIBRARY_PATH + +export TUSCANY_SCACPP_SYSTEM_ROOT=$TEST_SYSTEM +export TUSCANY_SCACPP_DEFAULT_MODULE=CalculatorSubsystem + +./calculator_client add 4.7 9 +./calculator_client div 7.2 3.6 +./calculator_client mul 7 6 + |