summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk/contrib/samples/CppCalculator/sample.calculator
diff options
context:
space:
mode:
Diffstat (limited to 'sca-cpp/trunk/contrib/samples/CppCalculator/sample.calculator')
-rw-r--r--sca-cpp/trunk/contrib/samples/CppCalculator/sample.calculator/Calculator.h34
-rw-r--r--sca-cpp/trunk/contrib/samples/CppCalculator/sample.calculator/CalculatorImpl.componentType31
-rw-r--r--sca-cpp/trunk/contrib/samples/CppCalculator/sample.calculator/CalculatorImpl.cpp90
-rw-r--r--sca-cpp/trunk/contrib/samples/CppCalculator/sample.calculator/CalculatorImpl.h41
-rw-r--r--sca-cpp/trunk/contrib/samples/CppCalculator/sample.calculator/Divide.h34
-rw-r--r--sca-cpp/trunk/contrib/samples/CppCalculator/sample.calculator/DivideImpl.componentType27
-rw-r--r--sca-cpp/trunk/contrib/samples/CppCalculator/sample.calculator/DivideImpl.cpp48
-rw-r--r--sca-cpp/trunk/contrib/samples/CppCalculator/sample.calculator/DivideImpl.h39
-rw-r--r--sca-cpp/trunk/contrib/samples/CppCalculator/sample.calculator/Makefile.am53
-rw-r--r--sca-cpp/trunk/contrib/samples/CppCalculator/sample.calculator/sample.calculator.composite33
10 files changed, 430 insertions, 0 deletions
diff --git a/sca-cpp/trunk/contrib/samples/CppCalculator/sample.calculator/Calculator.h b/sca-cpp/trunk/contrib/samples/CppCalculator/sample.calculator/Calculator.h
new file mode 100644
index 0000000000..90e97b5319
--- /dev/null
+++ b/sca-cpp/trunk/contrib/samples/CppCalculator/sample.calculator/Calculator.h
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+
+/* $Rev$ $Date$ */
+
+#ifndef sample_calculator_h
+#define sample_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 // sample_calculator_h
diff --git a/sca-cpp/trunk/contrib/samples/CppCalculator/sample.calculator/CalculatorImpl.componentType b/sca-cpp/trunk/contrib/samples/CppCalculator/sample.calculator/CalculatorImpl.componentType
new file mode 100644
index 0000000000..72fe9842e8
--- /dev/null
+++ b/sca-cpp/trunk/contrib/samples/CppCalculator/sample.calculator/CalculatorImpl.componentType
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+
+<componentType xmlns="http://www.osoa.org/xmlns/sca/1.0">
+
+ <service name="CalculatorService">
+ <interface.cpp header="Calculator.h"/>
+ </service>
+
+ <reference name="divideService">
+ <interface.cpp header="Divide.h"/>
+ </reference>
+
+</componentType> \ No newline at end of file
diff --git a/sca-cpp/trunk/contrib/samples/CppCalculator/sample.calculator/CalculatorImpl.cpp b/sca-cpp/trunk/contrib/samples/CppCalculator/sample.calculator/CalculatorImpl.cpp
new file mode 100644
index 0000000000..01dac77c92
--- /dev/null
+++ b/sca-cpp/trunk/contrib/samples/CppCalculator/sample.calculator/CalculatorImpl.cpp
@@ -0,0 +1,90 @@
+/*
+ * 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.
+ */
+
+/* $Rev$ $Date$ */
+
+#include <stdio.h>
+
+#include "osoa/sca/ComponentContext.h"
+#include "osoa/sca/ServiceRuntimeException.h"
+
+#include "CalculatorImpl.h"
+#include "Divide.h"
+
+CalculatorImpl::CalculatorImpl()
+{
+}
+
+CalculatorImpl::~CalculatorImpl()
+{
+}
+
+// Calculator interface
+float CalculatorImpl::add(float arg1, float arg2)
+{
+ float result = arg1 + arg2;
+
+ printf("CalculatorImpl::add %f + %f = %f\n", arg1, arg2, result);
+ return result;
+}
+
+float CalculatorImpl::sub(float arg1, float arg2)
+{
+ float result = arg1 - arg2;
+ printf("CalculatorImpl::sub %f - %f = %f\n", arg1, arg2, result);
+ return result;
+}
+
+float CalculatorImpl::mul(float arg1, float arg2)
+{
+ float result = arg1 * arg2;
+ printf("CalculatorImpl::mul %f * %f = %f\n", arg1, arg2, result);
+ return result;
+}
+
+float CalculatorImpl::div(float arg1, float arg2)
+{
+ float result = 0;
+
+ // This method shows how to invoke a service on a different component from within a component
+
+ // First, get the current ComponentContext
+ osoa::sca::ComponentContext myContext = osoa::sca::ComponentContext::getCurrent();
+
+ try
+ {
+ // Find the required service, as referenced in CalculatorImpl.componentType
+ Divide* divideService = (Divide*)myContext.getService("divideService");
+
+ // Finally, invoke the service
+ result = divideService->divide(arg1, arg2);
+
+ printf("CalculatorImpl::div Divide returned result: %f\n", result);
+
+ }
+ catch (osoa::sca::ServiceRuntimeException& e)
+ {
+ // Print out error message and carry on
+ printf("CalculatorImpl::div Error whilst invoking Divide: %s", e.getMessageText());
+ }
+
+ return result;
+}
+
+
diff --git a/sca-cpp/trunk/contrib/samples/CppCalculator/sample.calculator/CalculatorImpl.h b/sca-cpp/trunk/contrib/samples/CppCalculator/sample.calculator/CalculatorImpl.h
new file mode 100644
index 0000000000..af8a5eeab1
--- /dev/null
+++ b/sca-cpp/trunk/contrib/samples/CppCalculator/sample.calculator/CalculatorImpl.h
@@ -0,0 +1,41 @@
+/*
+ * 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.
+ */
+
+/* $Rev$ $Date$ */
+
+#ifndef sample_calculatorimpl_h
+#define sample_calculatorimpl_h
+
+#include "Calculator.h"
+
+class CalculatorImpl : public Calculator
+{
+public:
+ CalculatorImpl();
+ virtual ~CalculatorImpl();
+
+ // Calculator interface
+ virtual float add(float arg1, float arg2);
+ virtual float sub(float arg1, float arg2);
+ virtual float mul(float arg1, float arg2);
+ virtual float div(float arg1, float arg2);
+};
+
+#endif // sample_calculatorimpl_h
+
diff --git a/sca-cpp/trunk/contrib/samples/CppCalculator/sample.calculator/Divide.h b/sca-cpp/trunk/contrib/samples/CppCalculator/sample.calculator/Divide.h
new file mode 100644
index 0000000000..6e171ed733
--- /dev/null
+++ b/sca-cpp/trunk/contrib/samples/CppCalculator/sample.calculator/Divide.h
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+
+/* $Rev$ $Date$ */
+
+
+#ifndef sample_divide_h
+#define sample_divide_h
+
+class Divide
+{
+public:
+ virtual float divide(float arg1, float arg2) = 0;
+};
+
+#endif // sample_divide_h
+
+
diff --git a/sca-cpp/trunk/contrib/samples/CppCalculator/sample.calculator/DivideImpl.componentType b/sca-cpp/trunk/contrib/samples/CppCalculator/sample.calculator/DivideImpl.componentType
new file mode 100644
index 0000000000..d7369e3ff0
--- /dev/null
+++ b/sca-cpp/trunk/contrib/samples/CppCalculator/sample.calculator/DivideImpl.componentType
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+
+<componentType xmlns="http://www.osoa.org/xmlns/sca/1.0">
+
+ <service name="DivideService">
+ <interface.cpp header="Divide.h"/>
+ </service>
+
+</componentType>
diff --git a/sca-cpp/trunk/contrib/samples/CppCalculator/sample.calculator/DivideImpl.cpp b/sca-cpp/trunk/contrib/samples/CppCalculator/sample.calculator/DivideImpl.cpp
new file mode 100644
index 0000000000..f1a927cf4c
--- /dev/null
+++ b/sca-cpp/trunk/contrib/samples/CppCalculator/sample.calculator/DivideImpl.cpp
@@ -0,0 +1,48 @@
+/*
+ * 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.
+ */
+
+/* $Rev$ $Date$ */
+
+#include <stdio.h>
+
+#include "DivideImpl.h"
+
+DivideImpl::DivideImpl()
+{
+}
+
+DivideImpl::~DivideImpl()
+{
+}
+
+// Divide interface
+float DivideImpl::divide(float arg1, float arg2)
+{
+ if(arg2 == 0.0)
+ {
+ printf("DivideImpl::div %f / %f !! Cannot divide by zero, so returning 0\n", arg1, arg2);
+ return 0;
+ }
+
+ float result = arg1 / arg2;
+ printf("DivideImpl::div %f / %f = %f\n", arg1, arg2, result);
+ return result;
+}
+
+
diff --git a/sca-cpp/trunk/contrib/samples/CppCalculator/sample.calculator/DivideImpl.h b/sca-cpp/trunk/contrib/samples/CppCalculator/sample.calculator/DivideImpl.h
new file mode 100644
index 0000000000..64045f1899
--- /dev/null
+++ b/sca-cpp/trunk/contrib/samples/CppCalculator/sample.calculator/DivideImpl.h
@@ -0,0 +1,39 @@
+/*
+ * 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.
+ */
+
+/* $Rev$ $Date$ */
+
+
+#ifndef sample_divideimpl_h
+#define sample_divideimpl_h
+
+#include "Divide.h"
+
+class DivideImpl : public Divide
+{
+public:
+ DivideImpl();
+ virtual ~DivideImpl();
+
+ // Divide interface
+ virtual float divide(float arg1, float arg2);
+};
+
+#endif // sample_divideimpl_h
+
diff --git a/sca-cpp/trunk/contrib/samples/CppCalculator/sample.calculator/Makefile.am b/sca-cpp/trunk/contrib/samples/CppCalculator/sample.calculator/Makefile.am
new file mode 100644
index 0000000000..de6dad787d
--- /dev/null
+++ b/sca-cpp/trunk/contrib/samples/CppCalculator/sample.calculator/Makefile.am
@@ -0,0 +1,53 @@
+# 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.
+
+deploydir=$(prefix)/CppCalculator/deploy
+compositedir=$(deploydir)/sample.calculator
+
+BUILT_SOURCES = scagen
+
+noinst_HEADERS = *.h
+
+scagen:
+ java -jar $(TUSCANY_SCACPP)/bin/scagen.jar -dir . -output .
+
+composite_LTLIBRARIES = libCalculator.la
+composite_DATA = *.composite *.componentType
+EXTRA_DIST = *.composite *.componentType
+
+dist_libCalculator_la_SOURCES = \
+CalculatorImpl.cpp \
+DivideImpl.cpp
+
+nodist_libCalculator_la_SOURCES = \
+CalculatorImpl_CalculatorService_Proxy.cpp \
+CalculatorImpl_CalculatorService_Wrapper.cpp \
+CalculatorImpl_divideService_Proxy.cpp \
+DivideImpl_DivideService_Proxy.cpp \
+DivideImpl_DivideService_Wrapper.cpp
+
+libCalculator_la_LIBADD = \
+-L${TUSCANY_SCACPP}/lib \
+ -ltuscany_sca \
+-L${TUSCANY_SCACPP}/extensions/cpp/lib \
+ -ltuscany_sca_cpp
+
+INCLUDES = \
+-I$(TUSCANY_SCACPP)/extensions/cpp/include \
+-I$(TUSCANY_SCACPP)/include \
+-I${TUSCANY_SDOCPP}/include
+
diff --git a/sca-cpp/trunk/contrib/samples/CppCalculator/sample.calculator/sample.calculator.composite b/sca-cpp/trunk/contrib/samples/CppCalculator/sample.calculator/sample.calculator.composite
new file mode 100644
index 0000000000..6903cf21d8
--- /dev/null
+++ b/sca-cpp/trunk/contrib/samples/CppCalculator/sample.calculator/sample.calculator.composite
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ name="sample.calculator">
+
+ <component name="CalculatorComponent">
+ <implementation.cpp library="Calculator" header="CalculatorImpl.h"/>
+ <reference name="divideService">DivideComponent/DivideService</reference>
+ </component>
+
+ <component name="DivideComponent">
+ <implementation.cpp library="Calculator" header="DivideImpl.h"/>
+ </component>
+
+</composite> \ No newline at end of file