diff options
author | dims <dims@13f79535-47bb-0310-9956-ffa450edef68> | 2008-06-17 00:23:01 +0000 |
---|---|---|
committer | dims <dims@13f79535-47bb-0310-9956-ffa450edef68> | 2008-06-17 00:23:01 +0000 |
commit | bdd0a41aed7edf21ec2a65cfa17a86af2ef8c48a (patch) | |
tree | 38a92061c0793434c4be189f1d70c3458b6bc41d /tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp |
Move Tuscany from Incubator to top level.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@668359 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp')
36 files changed, 3446 insertions, 0 deletions
diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/Makefile.am b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/Makefile.am new file mode 100644 index 0000000000..7fac33118a --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/Makefile.am @@ -0,0 +1,24 @@ +# 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. + +SUBDIRS = src + +datadir=$(prefix)/extensions/cpp + +nobase_data_DATA = xsd/*.xsd + +EXTRA_DIST = xsd
\ No newline at end of file diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/deploy.bat b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/deploy.bat new file mode 100644 index 0000000000..644cbfc4a3 --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/deploy.bat @@ -0,0 +1,77 @@ +@echo off + +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. 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, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. + + +setlocal + +if . == .%1 ( +echo sca root not specified +goto usage +) +set rootdir=%1 +set deploydir=%rootdir%\deploy +set extdir=%deploydir%\extensions +set cppextdir=%extdir%\cpp +set srcdir=%rootdir%\runtime\extensions\cpp\src + +if . == .%2 ( +echo input directory not specified +goto usage +) +set inpath=%2 +echo %inpath% + + +if not exist %deploydir% mkdir %deploydir% +if not exist %extdir% mkdir %extdir% +if not exist %cppextdir% mkdir %cppextdir% +if not exist %cppextdir%\module mkdir %cppextdir%\module +if not exist %cppextdir%\bin mkdir %cppextdir%\bin +if not exist %cppextdir%\lib mkdir %cppextdir%\lib +if not exist %cppextdir%\include mkdir %cppextdir%\include +if not exist %cppextdir%\include\osoa mkdir %cppextdir%\include\osoa +if not exist %cppextdir%\include\osoa\sca mkdir %cppextdir%\include\osoa\sca +if not exist %cppextdir%\include\tuscany mkdir %cppextdir%\include\tuscany +if not exist %cppextdir%\include\tuscany\sca mkdir %cppextdir%\include\tuscany\sca +if not exist %cppextdir%\include\tuscany\sca\cpp mkdir %cppextdir%\include\tuscany\sca\cpp +if not exist %cppextdir%\include\tuscany\sca\cpp\model mkdir %cppextdir%\include\tuscany\sca\cpp\model +if not exist %cppextdir%\xsd mkdir %cppextdir%\xsd + +del %cppextdir%\bin\tuscany_sca_cpp.* +del %cppextdir%\lib\*.lib + +copy %srcdir%\osoa\sca\*.h %cppextdir%\include\osoa\sca +copy %srcdir%\tuscany\sca\cpp\*.h %cppextdir%\include\tuscany\sca\cpp +copy %srcdir%\tuscany\sca\cpp\model\*.h %cppextdir%\include\tuscany\sca\cpp\model + +copy %srcdir%\..\xsd\*.* %cppextdir%\xsd + +copy %inpath%\tuscany_sca_cpp.lib %cppextdir%\lib +copy %inpath%\tuscany_sca_cpp.dll %cppextdir%\bin +copy %inpath%\tuscany_sca_cpp.dll %cppextdir%\module + +if exist %inpath%\tuscany_sca_cpp.pdb copy %inpath%\tuscany_sca_cpp.pdb %cppextdir%\bin +if exist %inpath%\tuscany_sca_cpp.pdb copy %inpath%\tuscany_sca_cpp.pdb %cppextdir%\module + +goto end +:usage +echo Usage: deploy <sca-root> <build-output> +:end + +endlocal diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/Makefile.am b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/Makefile.am new file mode 100644 index 0000000000..bb28aed8b9 --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/Makefile.am @@ -0,0 +1,57 @@ +# 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. + +libdir=$(prefix)/extensions/cpp/lib + +lib_LTLIBRARIES = libtuscany_sca_cpp.la +includedir=$(prefix)/extensions/cpp/include +nobase_include_HEADERS = \ +osoa/sca/*.h \ +tuscany/sca/cpp/*.h \ +tuscany/sca/cpp/model/*.h + +libtuscany_sca_cpp_la_SOURCES = \ +osoa/sca/ComponentContext.cpp \ +osoa/sca/CompositeContext.cpp \ +tuscany/sca/cpp/ComponentContextImpl.cpp \ +tuscany/sca/cpp/CompositeContextImpl.cpp \ +tuscany/sca/cpp/CPPExtension.cpp \ +tuscany/sca/cpp/CPPImplementationExtension.cpp \ +tuscany/sca/cpp/CPPInterfaceExtension.cpp \ +tuscany/sca/cpp/CPPServiceProxy.cpp \ +tuscany/sca/cpp/CPPServiceWrapper.cpp \ +tuscany/sca/cpp/TuscanyRuntime.cpp \ +tuscany/sca/cpp/model/CPPImplementation.cpp \ +tuscany/sca/cpp/model/CPPInterface.cpp \ +tuscany/sca/cpp/model/CPPReferenceBinding.cpp \ +tuscany/sca/cpp/model/CPPServiceBinding.cpp + +libtuscany_sca_cpp_la_LIBADD = -L${TUSCANY_SDOCPP}/lib -ltuscany_sdo \ + -L$(top_builddir)/runtime/core/src -ltuscany_sca + +INCLUDES = -Imodel -I$(top_builddir)/runtime/core/src \ + -I${TUSCANY_SDOCPP}/include + +AM_CPPFLAGS = $(CPPFLAGS) -D_DEBUG + +moduledir=$(prefix)/extensions/cpp/module +extension = libtuscany_sca_cpp$(libsuffix) + +install-exec-hook: + test -z $(moduledir) || $(mkdir_p) $(moduledir); + -rm -f $(moduledir)/$(extension) + $(LN_S) $(libdir)/$(extension) $(moduledir)/$(extension) diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/osoa/sca/ComponentContext.cpp b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/osoa/sca/ComponentContext.cpp new file mode 100644 index 0000000000..d686c4c09f --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/osoa/sca/ComponentContext.cpp @@ -0,0 +1,150 @@ +/* + * 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 "commonj/sdo/SDO.h" + +#include "osoa/sca/ComponentContext.h" +#include "osoa/sca/ServiceRuntimeException.h" + +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/cpp/ComponentContextImpl.h" +#include "tuscany/sca/core/SCARuntime.h" + +using namespace commonj::sdo; +using namespace tuscany::sca; +using namespace tuscany::sca::cpp; +using namespace tuscany::sca::model; + +namespace osoa +{ + namespace sca + { + + // ======================================================= + // getCurrent: create a context from the current component + // ======================================================= + ComponentContext ComponentContext::getCurrent() + { + logentry(); + try + { + Component* component = tuscany::sca::SCARuntime::getCurrentRuntime()->getCurrentComponent(); + if (!component) + { + throwException(ComponentContextException, "No current component"); + } + ComponentContext* cci = new ComponentContextImpl(component); + return ComponentContext(cci); + } + catch (ServiceRuntimeException&) + { + throw; + } + catch (TuscanyRuntimeException& e) + { + throwException(ServiceRuntimeException, e); + } + } + + // =========== + // Constructor + // =========== + ComponentContext::ComponentContext(ComponentContext* implementation) + : impl(implementation) + { + logentry(); + } + + // ========== + // Destructor + // ========== + ComponentContext::~ComponentContext() + { + logentry(); + delete impl; + } + + // =================================== + // Copy constructor: create a new impl + // =================================== + ComponentContext::ComponentContext(const ComponentContext& ctx) + { + logentry(); + Component* component = ((ComponentContextImpl*)impl)->getComponent(); + impl = new ComponentContextImpl(component); + } + + // ============================= + // operator= : create a new impl + // ============================= + ComponentContext& ComponentContext::operator=(const ComponentContext& ctx) + { + logentry(); + if (this != &ctx) + { + Component* component = ((ComponentContextImpl*)impl)->getComponent(); + impl = new ComponentContextImpl(component); + } + return *this; + } + + // ========== + // getService + // ========== + void* ComponentContext::getService(const std::string& referenceName) + { + logentry(); + void* service = impl->getService(referenceName); + return service; + } + + // =========== + // getServices + // =========== + std::list<void*> ComponentContext::getServices(const std::string& referenceName) + { + logentry(); + return impl->getServices(referenceName); + } + + // ============ + // getProperties + // ============= + DataObjectPtr ComponentContext::getProperties() + { + logentry(); + DataObjectPtr properties = impl->getProperties(); + return properties; + } + + // ============ + // getDataFactory + // ============= + DataFactoryPtr ComponentContext::getDataFactory() + { + logentry(); + DataFactoryPtr dataFactory = impl->getDataFactory(); + return dataFactory; + } + + + } // End namespace sca +} // End namespace osoa diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/osoa/sca/ComponentContext.h b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/osoa/sca/ComponentContext.h new file mode 100644 index 0000000000..2c305c5161 --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/osoa/sca/ComponentContext.h @@ -0,0 +1,117 @@ +/* + * 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 osoa_sca_componentcontext_h +#define osoa_sca_componentcontext_h + +#include <string> +#include <list> + +#include "commonj/sdo/SDO.h" + +#include "osoa/sca/export.h" + +namespace osoa +{ + namespace sca + { + + /** + * An SCA component implementation uses the ComponentContext class to + * retrieve information about the configured SCA component. + */ + class SCA_CPP_API ComponentContext + { + + public: + /** + * Return a new ComponentContext for the current Component. + */ + static ComponentContext getCurrent(); + + /** + * Resolve a reference name into a single configured service. + * If the component's reference is wired to more than one service + * then theis method will return an exception. + * @param referenceName The reference to be resolved. This must match + * the name of a reference configured in the component type file for + * this component. + */ + virtual void* getService(const std::string& referenceName); + + /** + * Resolve a reference name into a list of configured services. + * @param referenceName The reference to be resolved. This must match + * the name of a reference configured in the component type file for + * this component. + */ + virtual std::list<void*> getServices(const std::string& referenceName); + + /** + * Get the configured properties for the component. + * @return A data object representing all the properties that + * are configured for this component. + */ + virtual commonj::sdo::DataObjectPtr getProperties(); + + /** + * Get an SDO data factory which will allow the component to + * create data objects for all the types configured for this + * component. + * @return A data factory to be used by the component to create + * new data objects. + */ + virtual commonj::sdo::DataFactoryPtr getDataFactory(); + + /** + * Destructor + */ + virtual ~ComponentContext(); + + /** + * Constructor + */ + ComponentContext(const ComponentContext&); + + /** + * Copy operator + */ + ComponentContext& operator=(const ComponentContext&); + + /** + * Constructor to create an interface class from the contained + * implementation. + * @param implementation the actual implementation class + */ + ComponentContext(ComponentContext* implementation); + + private: + + /** + * Pointer to the class which provides the actual implementation. + */ + ComponentContext* impl; + + }; + } // End namespace sca +} // End namespace osoa + +#endif // osoa_sca_componentcontext_h diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/osoa/sca/CompositeContext.cpp b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/osoa/sca/CompositeContext.cpp new file mode 100644 index 0000000000..d3f06e1b12 --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/osoa/sca/CompositeContext.cpp @@ -0,0 +1,127 @@ +/* + * 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 "commonj/sdo/SDO.h" + +#include "osoa/sca/CompositeContext.h" +#include "osoa/sca/ServiceRuntimeException.h" + +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/cpp/CompositeContextImpl.h" +#include "tuscany/sca/core/SCARuntime.h" + +using namespace commonj::sdo; +using namespace tuscany::sca; +using namespace tuscany::sca::cpp; + + +namespace osoa +{ + namespace sca + { + // =========== + // Constructor + // =========== + CompositeContext::CompositeContext(CompositeContext* implementation) + : impl(implementation) + { + logentry(); + } + + // =================================== + // Copy constructor: create a new impl + // =================================== + CompositeContext::CompositeContext(const CompositeContext& ctx) + { + logentry(); + impl = new CompositeContextImpl( + tuscany::sca::SCARuntime::getCurrentRuntime()->getDefaultComponent()); + } + + // ============================= + // operator= : create a new impl + // ============================= + CompositeContext& CompositeContext::operator=(const CompositeContext& ctx) + { + logentry(); + if (this != &ctx) + { + impl = new CompositeContextImpl( + tuscany::sca::SCARuntime::getCurrentRuntime()->getDefaultComponent()); + } + return *this; + } + + // ========== + // Destructor + // ========== + CompositeContext::~CompositeContext() + { + logentry(); + delete impl; + } + + // ==================================================== + // getCurrent: create a context from the current composite + // ==================================================== + CompositeContext CompositeContext::getCurrent() + { + logentry(); + try + { + CompositeContext* cci = new CompositeContextImpl( + tuscany::sca::SCARuntime::getCurrentRuntime()->getDefaultComponent()); + + return CompositeContext(cci); + } + catch (ServiceRuntimeException&) + { + throw; + } + catch (TuscanyRuntimeException& e) + { + throwException(ServiceRuntimeException, e); + } + } + + // ============= + // locateService + // ============= + void* CompositeContext::locateService(const std::string& serviceName) + { + logentry(); + void* sp = impl->locateService(serviceName); + return sp; + } + + // ============= + // getDataFactory + // ============= + DataFactoryPtr CompositeContext::getDataFactory() + { + logentry(); + DataFactoryPtr df = impl->getDataFactory(); + return df; + } + + + } // End namespace sca +} // End namespace osoa diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/osoa/sca/CompositeContext.h b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/osoa/sca/CompositeContext.h new file mode 100644 index 0000000000..a047f82e46 --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/osoa/sca/CompositeContext.h @@ -0,0 +1,99 @@ +/* + * 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 osoa_sca_compositecontext_h +#define osoa_sca_compositecontext_h + +#include "commonj/sdo/SDO.h" + +#include "osoa/sca/export.h" + +namespace osoa +{ + namespace sca + { + /** + * An SCA component implementation, or a non-SCA client, uses the + * CompositeContext class to retrieve information about the configured + * SCA composite. + */ + class SCA_CPP_API CompositeContext + { + + public: + /** + * Return a new CompositeContext for the current Component. + */ + static CompositeContext getCurrent(); + + /** + * Resolve a service name into a single component service. + * @param serviceName The name of the service in the form + * "component name"/"service name". The service name is + * optional in the component has one service. + * @return A pointer to an object which can be cast to the + * business interface of the target service. + */ + virtual void* locateService(const std::string& serviceName); + + /** + * Get an SDO data factory which will allow the component to + * create data objects for all the types configured for this + * component. + * @return A data factory to be used by the component to create + * new data objects. + */ + virtual commonj::sdo::DataFactoryPtr getDataFactory(); + + /** + * Destructor. + */ + virtual ~CompositeContext(); + + /** + * Constructor + */ + CompositeContext(const CompositeContext&); + + /** + * Copy operator + */ + CompositeContext& operator=(const CompositeContext&); + + /** + * Constructor to create an interface class from the contained + * implementation. + * @param implementation The actual implementation class. + */ + CompositeContext(CompositeContext* implementation); + + private: + + /** + * Pointer to the class which provides the actual implementation. + */ + CompositeContext* impl; + + }; + } // End namespace sca +} // End namespace osoa + +#endif // osoa_sca_compositecontext_h diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/osoa/sca/ServiceRuntimeException.h b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/osoa/sca/ServiceRuntimeException.h new file mode 100644 index 0000000000..6d64a32dd6 --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/osoa/sca/ServiceRuntimeException.h @@ -0,0 +1,105 @@ +/* + * 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 osoa_sca_serviceruntimeexception_h +#define osoa_sca_serviceruntimeexception_h + +#include "osoa/sca/export.h" + +#include "tuscany/sca/core/Exceptions.h" + +namespace osoa +{ + namespace sca + { + /** + * Top level exception to represent all the exceptions that may be + * thrown by an SCA runtime implementation. + */ + class SCA_CPP_API ServiceRuntimeException : public tuscany::sca::TuscanyRuntimeException + { + public: + ServiceRuntimeException( + const char *name="ServiceRuntimeException", + severity_level sev=Severe, + const char* msg_text="") + : tuscany::sca::TuscanyRuntimeException(name, sev, msg_text) + { + } + + ServiceRuntimeException(const tuscany::sca::TuscanyRuntimeException& e) + : tuscany::sca::TuscanyRuntimeException(e) + { + } + }; // End ServiceRuntimeException class definition + + /** + * A remotable service is currently unavailable. It is possible that a retry + * may resolve this exception. + */ + class SCA_CPP_API ServiceUnavailableException: public ServiceRuntimeException + { + public: + ServiceUnavailableException(const char* serviceName) + : ServiceRuntimeException("ServiceUnavailableException", Warning, + serviceName) + { + } + private: + }; // End ServiceUnavailableException class definition + + + /** + * The target of a wire cannot be found, or the reference has not been + * configured. + */ + class SCA_CPP_API ServiceNotFoundException: public ServiceRuntimeException + { + public: + ServiceNotFoundException(const char* msg) + : ServiceRuntimeException("ServiceNotFoundException", Error, + msg) + { + } + private: + }; // End ServiceNotFoundException class definition + + + /** + * There is no current component (for example, if a non-SCA component + * tries to get the current ComponentContext). + */ + class SCA_CPP_API ComponentContextException: public ServiceRuntimeException + { + public: + ComponentContextException(const char* msg) + : ServiceRuntimeException("ComponentContextException", Error, + msg) + { + } + private: + }; // End ComponentContextException class definition + + + } // End namespace sca +} // End namespace osoa + +#endif // osoa_sca_serviceruntimeexception_h diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/osoa/sca/export.h b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/osoa/sca/export.h new file mode 100644 index 0000000000..8a69913be4 --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/osoa/sca/export.h @@ -0,0 +1,42 @@ +/* + * 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 osoa_sca_export_h +#define osoa_sca_export_h + +#if defined(WIN32) || defined (_WINDOWS) +#pragma warning(disable: 4786) + +#ifdef TUSCANY_SCA_CPP_EXPORTS +#define SCA_CPP_API __declspec(dllexport) +#else +#define SCA_CPP_API __declspec(dllimport) +#endif + +#else +#include <sys/time.h> +#include <inttypes.h> +#include <stdlib.h> +#define SCA_CPP_API +#endif + +#endif // osoa_sca_export_h diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/osoa/sca/sca.h b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/osoa/sca/sca.h new file mode 100644 index 0000000000..6cce9453d7 --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/osoa/sca/sca.h @@ -0,0 +1,31 @@ +/* + * 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 osoa_sca_sca_h +#define osoa_sca_sca_h + +#include "osoa/sca/export.h" +#include "osoa/sca/CompositeContext.h" +#include "osoa/sca/ComponentContext.h" +#include "osoa/sca/ServiceRuntimeException.h" + +#endif // osoa_sca_sca_h diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPExtension.cpp b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPExtension.cpp new file mode 100644 index 0000000000..74a30fb772 --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPExtension.cpp @@ -0,0 +1,72 @@ +/* + * 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 "tuscany/sca/cpp/CPPExtension.h" +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/core/SCARuntime.h" +#include "tuscany/sca/cpp/CPPImplementationExtension.h" +#include "tuscany/sca/cpp/CPPInterfaceExtension.h" + + +extern "C" +{ +#if defined(WIN32) || defined(_WINDOWS) + __declspec(dllexport) +#endif + void tuscany_sca_cpp_initialize() + { + tuscany::sca::cpp::CPPExtension::initialize(); + } +} + +namespace tuscany +{ + namespace sca + { + namespace cpp + { + // =================================================================== + // Constructor for the CPPExtension class. + // =================================================================== + CPPExtension::CPPExtension() + { + logentry(); + } + + // =================================================================== + // Destructor for the CPPExtension class. + // =================================================================== + CPPExtension::~CPPExtension() + { + logentry(); + } + + void CPPExtension::initialize() + { + logentry(); + SCARuntime* runtime = SCARuntime::getCurrentRuntime(); + runtime->registerImplementationExtension(new CPPImplementationExtension()); + runtime->registerInterfaceExtension(new CPPInterfaceExtension()); + } + + } // End namespace cpp + } // End namespace sca +} // End namespace tuscany diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPExtension.h b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPExtension.h new file mode 100644 index 0000000000..d6c872629d --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPExtension.h @@ -0,0 +1,57 @@ +/* + * 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 tuscany_sca_cpp_cppextension_h +#define tuscany_sca_cpp_cppextension_h + +namespace tuscany +{ + namespace sca + { + namespace cpp + { + + class CPPExtension + { + public: + /** + * Default constructor + */ + CPPExtension(); + + /** + * Destructor + */ + virtual ~CPPExtension(); + + static void initialize(); + + private: + + }; + + + } // End namespace cpp + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_cpp_cppextension_h + diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPImplementationExtension.cpp b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPImplementationExtension.cpp new file mode 100644 index 0000000000..b5312ab243 --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPImplementationExtension.cpp @@ -0,0 +1,101 @@ +/* + * 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 "tuscany/sca/cpp/CPPImplementationExtension.h" +#include "tuscany/sca/cpp/model/CPPImplementation.h" +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/util/Utils.h" + +using namespace std; +using namespace commonj::sdo; +using namespace tuscany::sca::util; +using namespace tuscany::sca::model; + + +namespace tuscany +{ + namespace sca + { + namespace cpp + { + // =================================================================== + // Constructor for the CPPImplementationExtension class. + // =================================================================== + CPPImplementationExtension::CPPImplementationExtension() + { + logentry(); + } + + // =================================================================== + // Destructor for the CPPImplementationExtension class. + // =================================================================== + CPPImplementationExtension::~CPPImplementationExtension() + { + logentry(); + } + + const string CPPImplementationExtension::extensionName("cpp"); + const string CPPImplementationExtension::typeQName("http://www.osoa.org/xmlns/sca/1.0#CPPImplementation"); + + // =================================================================== + // loadModelElement - load the info from implementation.cpp + // =================================================================== + ComponentType* CPPImplementationExtension::getImplementation(Composite *composite, DataObjectPtr scdlImplementation) + { + logentry(); + string library = scdlImplementation->getCString("library"); + string header = scdlImplementation->getCString("header"); + string className = scdlImplementation->getCString("class"); + string scopeName = scdlImplementation->getCString("scope"); + + CPPImplementation::Scope scope; + if (scopeName == "composite") + { + scope = CPPImplementation::COMPOSITE; + } + else + { + scope = CPPImplementation::STATELESS; + } + + string headerPath; + string headerStub; + + // Separate any path element + Utils::rTokeniseString("/", header, headerPath, headerStub); + if (headerPath != "") + { + headerPath += "/"; + } + + // Determine the header stub name + string tmp; + Utils::rTokeniseString(".h", headerStub, headerStub, tmp); + + CPPImplementation* cppImpl = new CPPImplementation( + composite, library, header, headerPath, headerStub, className, scope); + + return cppImpl; + } + + } // End namespace cpp + } // End namespace sca +} // End namespace tuscany diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPImplementationExtension.h b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPImplementationExtension.h new file mode 100644 index 0000000000..8eb7b88691 --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPImplementationExtension.h @@ -0,0 +1,74 @@ +/* + * 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 tuscany_sca_cpp_cppimplementationextension_h +#define tuscany_sca_cpp_cppimplementationextension_h + +#include "tuscany/sca/extension/ImplementationExtension.h" + +namespace tuscany +{ + namespace sca + { + namespace cpp + { + + class CPPImplementationExtension : public ImplementationExtension + { + public: + /** + * Default constructor + */ + CPPImplementationExtension(); + + /** + * Destructor + */ + virtual ~CPPImplementationExtension(); + + /** + * return the name of the extension + */ + virtual const std::string& getExtensionName() {return extensionName;} + + /** + * return the QName of schema type for this implementation extension + * (e.g. "http://www.osoa.org/xmlns/sca/1.0#implementation.cpp") + */ + virtual const std::string& getExtensionTypeQName() {return typeQName;} + + virtual tuscany::sca::model::ComponentType* getImplementation( + tuscany::sca::model::Composite* composite, + commonj::sdo::DataObjectPtr scdlImplementation); + + private: + static const std::string extensionName; + static const std::string typeQName; + + }; + + + } // End namespace cpp + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_cpp_cppimplementationextension_h + diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPInterfaceExtension.cpp b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPInterfaceExtension.cpp new file mode 100644 index 0000000000..7bb84a7673 --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPInterfaceExtension.cpp @@ -0,0 +1,71 @@ +/* + * 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 "tuscany/sca/cpp/CPPInterfaceExtension.h" +#include "tuscany/sca/cpp/model/CPPInterface.h" +#include "tuscany/sca/util/Logging.h" + +using namespace std; +using namespace commonj::sdo; +using namespace tuscany::sca::model; + +namespace tuscany +{ + namespace sca + { + namespace cpp + { + // =================================================================== + // Constructor for the CPPInterfaceExtension class. + // =================================================================== + CPPInterfaceExtension::CPPInterfaceExtension() + { + logentry(); + } + + // =================================================================== + // Destructor for the CPPInterfaceExtension class. + // =================================================================== + CPPInterfaceExtension::~CPPInterfaceExtension() + { + logentry(); + } + + const string CPPInterfaceExtension::extensionName("cpp"); + const string CPPInterfaceExtension::typeQName("http://www.osoa.org/xmlns/sca/1.0#CPPInterface"); + + // =================================================================== + // loadModelElement - load the info from interface.cpp + // =================================================================== + tuscany::sca::model::Interface* CPPInterfaceExtension::getInterface(Composite* composite, DataObjectPtr scdlInterface) + { + logentry(); + + string header = scdlInterface->getCString("header"); + string className = scdlInterface->getCString("class"); + bool remotable = scdlInterface->getBoolean("remotable"); + + return new CPPInterface(header, className, remotable, false); + } + + } // End namespace cpp + } // End namespace sca +} // End namespace tuscany diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPInterfaceExtension.h b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPInterfaceExtension.h new file mode 100644 index 0000000000..04ac9f6970 --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPInterfaceExtension.h @@ -0,0 +1,74 @@ +/* + * 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 tuscany_sca_cpp_cppinterfaceextension_h +#define tuscany_sca_cpp_cppinterfaceextension_h + +#include "tuscany/sca/extension/InterfaceExtension.h" + +namespace tuscany +{ + namespace sca + { + namespace cpp + { + + class CPPInterfaceExtension : public InterfaceExtension + { + public: + /** + * Default constructor + */ + CPPInterfaceExtension(); + + /** + * Destructor + */ + virtual ~CPPInterfaceExtension(); + + /** + * return the name of the extension + */ + virtual const std::string& getExtensionName() {return extensionName;} + + /** + * return the QName of schema type for this interface extension + * (e.g. "http://www.osoa.org/xmlns/sca/1.0#interface.cpp") + */ + virtual const std::string& getExtensionTypeQName() {return typeQName;} + + virtual tuscany::sca::model::Interface* getInterface( + tuscany::sca::model::Composite* composite, + commonj::sdo::DataObjectPtr scdlInterface); + + private: + static const std::string extensionName; + static const std::string typeQName; + + }; + + + } // End namespace cpp + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_cpp_cppinterfaceextension_h + diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPServiceProxy.cpp b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPServiceProxy.cpp new file mode 100644 index 0000000000..cc45ea9fb8 --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPServiceProxy.cpp @@ -0,0 +1,192 @@ +/* + * 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 "osoa/sca/ServiceRuntimeException.h" + +#include "tuscany/sca/cpp/CPPServiceProxy.h" +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/core/SCARuntime.h" +#include "tuscany/sca/model/Reference.h" +#include "tuscany/sca/model/ReferenceType.h" +#include "tuscany/sca/model/Service.h" +#include "tuscany/sca/model/ServiceType.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/ComponentType.h" +#include "tuscany/sca/core/ServiceWrapper.h" +#include "tuscany/sca/model/Composite.h" +#include "tuscany/sca/model/ServiceBinding.h" +#include "tuscany/sca/cpp/model/CPPImplementation.h" +#include "tuscany/sca/cpp/model/CPPReferenceBinding.h" + +using namespace std; +using namespace osoa::sca; +using namespace tuscany::sca::model; +using namespace tuscany::sca::util; + +namespace tuscany +{ + namespace sca + { + namespace cpp + { + + // ============================ + // Constructor: Create a proxy + // ============================ + CPPServiceProxy::CPPServiceProxy(Reference* reference) + : ServiceProxy(reference) + { + logentry(); + + // ---------------------- + // Get the component + // ---------------------- + Component* component = reference->getComponent(); + string name = reference->getType()->getName(); + + // Get the service wrapper + CPPReferenceBinding* referenceBinding = (CPPReferenceBinding*)reference->getBinding(); + + ServiceWrapper* serviceWrapper = referenceBinding->getTargetServiceBinding()->getServiceWrapper(); + + createProxy(component, name, serviceWrapper); + } + + // ============================ + // Constructor: Create a proxy + // ============================ + CPPServiceProxy::CPPServiceProxy(Service* service) + : ServiceProxy(0) + { + logentry(); + + // ---------------------- + // Get the component + // ---------------------- + Component* component = service->getComponent(); + string name = service->getType()->getName(); + + // Get the service wrapper + ServiceWrapper* serviceWrapper = service->getBinding()->getServiceWrapper(); + + createProxy(component, name, serviceWrapper); + } + + void CPPServiceProxy::createProxy(Component* component, const string& name, ServiceWrapper* serviceWrapper) + { + logentry(); + + ComponentType* componentType = component->getType(); + if (!componentType) + { + string msg = "Component " + component->getName() + " has no implementation defined"; + throwException(ServiceNotFoundException, msg.c_str()); + } + + // If we got here we have a CPP implementation + CPPImplementation* impl = (CPPImplementation *)componentType; + + // ---------------------------------------------------- + // Get implementation dll name and service factory name + // ---------------------------------------------------- + string library = impl->getLibrary(); + string headerStub = impl->getHeaderStub(); + + string fullLibraryName = component->getComposite()->getRoot() + "/" + library; + string proxyFactoryName = headerStub + "_" + name + "_Proxy_Factory"; + string proxyDestructorName = headerStub + "_" + name + "_Proxy_Destructor"; + typedef void* (* PROXYFACTORY) (ServiceWrapper*); + + // ------------ + // Load the dll + // ------------ + proxyLibrary = Library(fullLibraryName); + + // ------------------------- + // Locate the factory method + // ------------------------- + PROXYFACTORY proxyFactory = (PROXYFACTORY)proxyLibrary.getSymbol(proxyFactoryName); + if (!proxyFactory) + { + logerror("Unable to locate %s in library %s", + proxyFactoryName.c_str(), fullLibraryName.c_str()); + string msg = "Unable to locate " + proxyFactoryName + " in library " + fullLibraryName; + throwException(ServiceNotFoundException, msg.c_str()); + } + + // ----------------------------------- + // Now create an instance of the proxy + // ----------------------------------- + void* proxy = proxyFactory(serviceWrapper); + if (!proxy) + { + logerror("Factory method %s in library %s returned null", + proxyFactoryName.c_str(), fullLibraryName.c_str()); + string msg = "Factory method " + proxyFactoryName + " in library " + fullLibraryName + " returned null"; + throwException(ServiceNotFoundException, msg.c_str()); + } + else + { + proxies.push_back(proxy); + } + + // ------------------------- + // Get the destructor method + // ------------------------- + destructor = (PROXYDESTRUCTOR)proxyLibrary.getSymbol(proxyDestructorName); + } + + // ========== + // Destructor + // ========== + CPPServiceProxy::~CPPServiceProxy() + { + logentry(); + + // Delete the proxies + if (destructor != NULL && proxies.size() != 0) + { + destructor(*proxies.begin()); + } + } + + CPPServiceProxy::PROXIES CPPServiceProxy::getProxies() + { + return proxies; + } + + void* CPPServiceProxy::getProxy() + { + logentry(); + + if (proxies.size() != 0) + { + return *proxies.begin(); + } + else + { + return NULL; + } + } + + } // End namespace cpp + } // End namespace sca +} // End namespace tuscany diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPServiceProxy.h b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPServiceProxy.h new file mode 100644 index 0000000000..8406e9bc44 --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPServiceProxy.h @@ -0,0 +1,117 @@ +/* + * 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 tuscany_sca_cpp_cppserviceproxy_h +#define tuscany_sca_cpp_cppserviceproxy_h + +#include "osoa/sca/export.h" + +#include "tuscany/sca/core/ServiceProxy.h" +#include "tuscany/sca/core/ServiceWrapper.h" +#include "tuscany/sca/util/Library.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/Reference.h" +#include "tuscany/sca/model/Service.h" + + +namespace tuscany +{ + namespace sca + { + namespace cpp + { + + /** + * Holds a proxy for a given component and reference. + * The proxy which is held inside a ServiceProxy will be specific to the component + * and reference and will have been code generated and be contained in a dll + * created by a developer of an SCA application. + */ + class CPPServiceProxy : public ServiceProxy + { + public: + /** + * Create a new service proxy for a reference. The proxy will contain a pointer to + * the target ServiceWrapper. + * @param reference The reference on the source component. + * @param target The wrapper of the service which is wired to this reference. + */ + CPPServiceProxy(tuscany::sca::model::Reference* reference); + + /** + * Create a new service proxy for a service. The proxy will contain a pointer to + * the target ServiceWrapper. + * @param reference The service on the target component. + * @param target The wrapper of the target service. + */ + CPPServiceProxy(tuscany::sca::model::Service* service); + + /** + * Destructor. + */ + virtual ~CPPServiceProxy(); + + /** + * Return an instance of the proxy created for this particular component and reference. + * @return The proxy. + */ + virtual void* getProxy(); + + /** + * Return the proxies created for this particular component and reference. + * @return The proxies. + */ + typedef std::list<void*> PROXIES; + virtual PROXIES getProxies(); + + private: + + /** + * Create the proxy + */ + void createProxy(tuscany::sca::model::Component* component, + const std::string& name, + ServiceWrapper* serviceWrapper); + + /** + * Holds the instances of the code generated proxies. + */ + PROXIES proxies; + + /** + * A function pointer to the destructor of the proxy. + */ + typedef void (* PROXYDESTRUCTOR) (void*); + PROXYDESTRUCTOR destructor; + + /** + * The library which contains the code for the proxy. + */ + tuscany::sca::util::Library proxyLibrary; + + }; + + } // End namespace cpp + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_cpp_cppserviceproxy_h diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPServiceWrapper.cpp b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPServiceWrapper.cpp new file mode 100644 index 0000000000..fbf8281178 --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPServiceWrapper.cpp @@ -0,0 +1,198 @@ +/* + * 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 "osoa/sca/ServiceRuntimeException.h" + +#include "tuscany/sca/cpp/CPPServiceWrapper.h" +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/util/Utils.h" +#include "tuscany/sca/util/Library.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/Composite.h" +#include "tuscany/sca/model/Service.h" +#include "tuscany/sca/model/ServiceType.h" +#include "tuscany/sca/core/SCARuntime.h" +#include "tuscany/sca/cpp/model/CPPImplementation.h" +#include "tuscany/sca/model/Interface.h" + +using namespace std; +using namespace osoa::sca; +using namespace tuscany::sca::model; +using namespace tuscany::sca::util; + +namespace tuscany +{ + namespace sca + { + namespace cpp + { + + // =================== + // Static data members + // =================== + void* CPPServiceWrapper::staticImpl = 0; + + // =========== + // Constructor + // =========== + CPPServiceWrapper::CPPServiceWrapper(Service* service) + : ServiceWrapper(service) + { + logentry(); + + component = service->getComponent(); + interf = service->getType()->getInterface(); + implementation = (CPPImplementation*)component->getType(); + } + + // ========== + // Destructor + // ========== + CPPServiceWrapper::~CPPServiceWrapper() + { + logentry(); + } + + + // ====================================================================== + // getImplementation: get an implementation for this scope + // ====================================================================== + void* CPPServiceWrapper::getImplementation() + { + logentry(); + if (implementation->getScope() == CPPImplementation::COMPOSITE) + { + if (!staticImpl) + { + staticImpl = newImplementation(); + } + return staticImpl; + } + else // (scope == CPPInterface::STATELESS) + { + return newImplementation(); + } + } + + // ====================================================================== + // releaseImplementation: release the implementation for this scope + // ====================================================================== + void CPPServiceWrapper::releaseImplementation() + { + logentry(); + if (implementation->getScope() == CPPImplementation::STATELESS) + { + deleteImplementation(); + } + } + + // ====================================================================== + // invoke: wrapper call to service with setting the component context + // ====================================================================== + void CPPServiceWrapper::invoke(Operation& operation) + { + logentry(); + + SCARuntime* runtime = SCARuntime::getCurrentRuntime(); + runtime->setCurrentComponent(component); + + try + { + invokeService(operation); + } + catch (...) + { + runtime->unsetCurrentComponent(); + throw; + } + runtime->unsetCurrentComponent(); + } + + void CPPServiceWrapper::setLibrary(Library* lib) + { + wrapperLibrary = lib; + } + + // ====================================================================== + // getServiceWrapper: create a wrapper for the target ComponentService + // ====================================================================== + CPPServiceWrapper* CPPServiceWrapper::getServiceWrapper(Service* service) + { + logentry(); + + CPPServiceWrapper* serviceWrapper = 0; + + // ----------------------------------------------- + // Get the implementation for the target component + // ----------------------------------------------- + Component* component = service->getComponent(); + CPPImplementation* impl = (CPPImplementation*)component->getType(); + if (!impl) + { + string msg = "Component " + component->getName() + " has no implementation defined"; + throwException(ServiceNotFoundException, msg.c_str()); + } + + // ---------------------------------------------------- + // Get implementation dll name and wrapper factory name + // ---------------------------------------------------- + string libraryName = impl->getLibrary(); + string wrapperFactoryName = impl->getHeaderStub() + + "_" + service->getType()->getName() + "_Wrapper_Factory"; + + // ------------ + // Load the dll + // ------------ + string fullLibraryName = component->getComposite()->getRoot() + "/" + libraryName; + typedef CPPServiceWrapper* (* WRAPPERFACTORY) (Service*); + Library* wrapperLib = new Library(fullLibraryName); + + // ------------------------- + // Locate the factory method + // ------------------------- + WRAPPERFACTORY wrapperFactory = (WRAPPERFACTORY)wrapperLib->getSymbol(wrapperFactoryName); + if (!wrapperFactory) + { + logerror("Unable to locate %s in library %s", + wrapperFactoryName.c_str(), fullLibraryName.c_str()); + string msg = "Unable to locate " + wrapperFactoryName + " in library " + fullLibraryName; + throwException(ServiceNotFoundException, msg.c_str()); + } + + // ------------------------------------- + // Now create an instance of the wrapper + // ------------------------------------- + serviceWrapper = wrapperFactory(service); + if (!serviceWrapper) + { + logerror("Factory method %s in library %s returned null", + wrapperFactoryName.c_str(), fullLibraryName.c_str()); + string msg = "Factory method " + wrapperFactoryName + " in library " + fullLibraryName + " returned null"; + throwException(ServiceNotFoundException, msg.c_str()); + } + serviceWrapper->setLibrary(wrapperLib); + + return serviceWrapper; + } + + } // End namespace cpp + } // End namespace sca +} // End namespace tuscany diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPServiceWrapper.h b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPServiceWrapper.h new file mode 100644 index 0000000000..e8111b6423 --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/CPPServiceWrapper.h @@ -0,0 +1,160 @@ +/* + * 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 tuscany_sca_cpp_cppservicewrapper_h +#define tuscany_sca_cpp_cppservicewrapper_h + +#include "osoa/sca/export.h" + +#include "tuscany/sca/core/ServiceWrapper.h" +#include "tuscany/sca/core/Operation.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/Interface.h" +#include "tuscany/sca/cpp/model/CPPImplementation.h" +#include "tuscany/sca/util/Library.h" + +namespace tuscany +{ + namespace sca + { + namespace cpp + { + + /** + * Wraps the service on a component implementation. + * This abstract class is extended by generated code which provides + * the implementation of some of the methods. + * An instance of this class wraps the actual component implementation which + * has been written by a developer of an SCA application. + */ + class SCA_CPP_API CPPServiceWrapper : public ServiceWrapper + { + public: + /** + * Factory method to create a new CPPServiceWrapper for a given target + * service. This method will provide all the loading of dlls required to + * create the target component. + * @param target The service on the component for which this wrapper is to be + * created. + * @return A wrapper that references the given target. + */ + static CPPServiceWrapper* getServiceWrapper(tuscany::sca::model::Service* service); + + /** + * Constructor. + * @param target The component service to which this wrapper refers. + */ + CPPServiceWrapper(tuscany::sca::model::Service* service); + + /** + * Destructor. + */ + virtual ~CPPServiceWrapper(); + + /** + * All business method calls to the target component go through the invoke method. + * @param operation The details of the method, paramaters and return value for the + * business method to be called on the target component. + */ + virtual void invoke(Operation& operation); + + /** + * Return the loaded shared library for the target component. + */ + tuscany::sca::util::Library* getLibrary() const { return wrapperLibrary; } + + protected: + + /** + * Delegated method to invoke the correct method on the target component. + * Implemented by the subtype. + */ + virtual void invokeService(Operation& operation) = 0; + + /** + * Delegated method to create a new component implementation. + * Implemented by the subtype. + * @return A pointer to an instance of the component implementation class. + */ + virtual void* newImplementation() = 0; + + /** + * Delegated method to delete the current instance of the component + * implementation. + * Implemented by the subtype. + */ + virtual void deleteImplementation() = 0; + + /** + * Return the current instance of the component implementation. + * @return A pointer to an instance of the component implementation class. + */ + virtual void* getImplementation(); + + /** + * Indicates that the current instance of the component implementation + * has been finished with. + * Will call CPPServiceWrapper#deleteImplementation if the + * implementation is stateless (so that a new instance is returned + * for each call). + */ + virtual void releaseImplementation(); + + private: + /** + * Holds an implementation instance if the scope is set to composite. + */ + static void* staticImpl; + + /** + * The component to which this wrapper refers. + */ + tuscany::sca::model::Component* component; + + /** + * A pointer to the interface which the service exposes. + */ + tuscany::sca::model::Interface* interf; + + /** + * The component implementation + */ + CPPImplementation* implementation; + + /** + * Pointer to the loaded library which contains the component + * implementation. + */ + tuscany::sca::util::Library* wrapperLibrary; + + /** + * Set the loaded library which contains the component + * implementation. + * @param lib The library. + */ + void setLibrary(tuscany::sca::util::Library* lib); + }; + + } // End namespace cpp + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_cpp_cppservicewrapper_h diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/ComponentContextImpl.cpp b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/ComponentContextImpl.cpp new file mode 100644 index 0000000000..3de0cb968c --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/ComponentContextImpl.cpp @@ -0,0 +1,208 @@ +/* + * 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 "osoa/sca/ServiceRuntimeException.h" + +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/cpp/ComponentContextImpl.h" +#include "tuscany/sca/model/Composite.h" +#include "tuscany/sca/model/ReferenceBinding.h" +#include "tuscany/sca/model/ReferenceType.h" +#include "tuscany/sca/model/ServiceBinding.h" + +using namespace std; +using namespace osoa::sca; +using namespace commonj::sdo; +using namespace tuscany::sca::model; + +namespace tuscany +{ + namespace sca + { + namespace cpp + { + + // =========== + // Constructor + // =========== + ComponentContextImpl::ComponentContextImpl(Component* comp) + : ComponentContext(0), component(comp) + { + logentry(); + } + + // ========== + // Destructor + // ========== + ComponentContextImpl::~ComponentContextImpl() + { + logentry(); + } + + + // ========================================================================== + // getServices: return a list of Proxies for services wired to this reference + // ========================================================================== + std::list<void*> ComponentContextImpl::getServices(const std::string& referenceName) + { + logentry(); + try + { + // -------------------------------------------------------------- + // locate reference in the current component and determine target + // -------------------------------------------------------------- + Reference* reference = component->findReference(referenceName); + if (!reference) + { + string message = "Reference not defined: "; + message = message + referenceName; + throwException(ServiceNotFoundException, message.c_str()); + } + + // Get a service proxy from the binding configured on the reference + CPPServiceProxy* serviceProxy = (CPPServiceProxy*)reference->getBinding()->getServiceProxy(); + if (serviceProxy == NULL) + { + string message = "Reference "; + message = message + referenceName + " not wired"; + throwException(ServiceNotFoundException, message.c_str()); + } + + return serviceProxy->getProxies(); + } + catch (ServiceRuntimeException&) + { + throw; + } + catch (TuscanyRuntimeException& e) + { + throwException(ServiceRuntimeException, e); + } + + } // End getServices() + + + // =================================================================== + // getService: return a Proxy for the services wired to this reference + // =================================================================== + void* ComponentContextImpl::getService(const std::string& referenceName) + { + logentry(); + try + { + // -------------------------------------------------------------- + // locate reference in the current component and determine target + // -------------------------------------------------------------- + Reference* reference = component->findReference(referenceName); + if (!reference) + { + string message = "Reference not defined: "; + message = message + referenceName; + throwException(ServiceNotFoundException, message.c_str()); + } + + // -------------------- + // Validate the request + // -------------------- + switch (reference->getType()->getMultiplicity()) + { + case ReferenceType::ZERO_MANY: + case ReferenceType::ONE_MANY: + { + string message = "getService() called for reference with multiplicity >1 :"; + message = message + referenceName; + throwException(ServiceNotFoundException, message.c_str()); + } + default: + { + } + } // end switch + + // Get a service proxy from the binding configured on the reference + CPPServiceProxy* serviceProxy = (CPPServiceProxy*)reference->getBinding()->getServiceProxy(); + if (serviceProxy == NULL) + { + string message = "Reference "; + message = message + referenceName + " not wired"; + throwException(ServiceNotFoundException, message.c_str()); + } + + void* service = serviceProxy->getProxy(); + + return service; + } + catch (ServiceRuntimeException&) + { + throw; + } + catch (TuscanyRuntimeException& e) + { + throwException(ServiceRuntimeException, e); + } + + } // End getService() + + // ============================================== + // getProperties: return the component properties + // ============================================== + DataObjectPtr ComponentContextImpl::getProperties() + { + logentry(); + try + { + DataObjectPtr properties = component->getProperties(); + return properties; + } + catch (ServiceRuntimeException&) + { + throw; + } + catch (TuscanyRuntimeException& e) + { + throwException(ServiceRuntimeException, e); + } + } + + // ============================================== + // getDataFactory: return the data factory for the composite in which + // this component resides + // ============================================== + commonj::sdo::DataFactoryPtr ComponentContextImpl::getDataFactory() + { + logentry(); + try + { + commonj::sdo::DataFactoryPtr dataFactory = component->getComposite()->getDataFactory(); + return dataFactory; + } + catch (ServiceRuntimeException&) + { + throw; + } + catch (TuscanyRuntimeException& e) + { + throwException(ServiceRuntimeException, e); + } + } + + } // End namespace cpp + } // End namespace sca +} // End namespace tuscany diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/ComponentContextImpl.h b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/ComponentContextImpl.h new file mode 100644 index 0000000000..412c276d8c --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/ComponentContextImpl.h @@ -0,0 +1,119 @@ +/* + * 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 tuscany_sca_cpp_componentcontextimpl_h +#define tuscany_sca_cpp_componentcontextimpl_h + +#include "osoa/sca/ComponentContext.h" + +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/Service.h" +#include "tuscany/sca/model/Reference.h" +#include "tuscany/sca/core/ServiceWrapper.h" +#include "tuscany/sca/cpp/CPPServiceProxy.h" + + +namespace tuscany +{ + namespace sca + { + namespace cpp + { + + /** + * Contains the actual implementation of a ComponentContext interface. + */ + class ComponentContextImpl : public osoa::sca::ComponentContext + { + + public: + /** + * Constructor that takes a Component which represents the runtime + * model for this context. + */ + ComponentContextImpl(tuscany::sca::model::Component* component); + + /** + * Default constructor. + */ + virtual ~ComponentContextImpl(); + + /** + * See ComponentContext. + */ + virtual void* getService(const std::string& referenceName); + + /** + * See ComponentContext. + */ + virtual std::list<void*> getServices(const std::string& referenceName); + + /** + * See ComponentContext. + */ + virtual commonj::sdo::DataObjectPtr getProperties(); + + /** + * See ComponentContext. + */ + virtual commonj::sdo::DataFactoryPtr getDataFactory(); + + /** + * Returns the contained Component. + * @return The Component to which this context refers. + */ + virtual tuscany::sca::model::Component* getComponent() {return component;} + + private: + ComponentContextImpl(const ComponentContextImpl&); + ComponentContextImpl& operator=(const ComponentContextImpl&); + + /** + * Pointer to the runtime model Component to which this + * context refers. + */ + tuscany::sca::model::Component* component; + + /** + * Helper method to return a proxy to a service. + * @param serviceReference The source reference. + * @param target The target to which this source reference is wired. + * @return A pointer to an object which can be cast to the business + * class representing the target. + */ + void* getServiceProxy( + tuscany::sca::model::Reference* serviceReference, + tuscany::sca::model::Service* target); + + /** + * Helper method to return a wrapper for a target service. + * @param target The target for which this wrapper is to be created. + * @return The service wrapper. + */ + ServiceWrapper* getServiceWrapper(tuscany::sca::model::Service* target); + + }; + + } // End namespaca cpp + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_cpp_componentcontextimpl_h diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/CompositeContextImpl.cpp b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/CompositeContextImpl.cpp new file mode 100644 index 0000000000..ae8183231e --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/CompositeContextImpl.cpp @@ -0,0 +1,128 @@ +/* + * 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 "commonj/sdo/SDO.h" + +#include "osoa/sca/ServiceRuntimeException.h" + +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/cpp/CompositeContextImpl.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/Composite.h" +#include "tuscany/sca/model/Service.h" +#include "tuscany/sca/model/ServiceBinding.h" +#include "tuscany/sca/model/ServiceType.h" +#include "tuscany/sca/core/ServiceProxy.h" +#include "tuscany/sca/core/ServiceWrapper.h" +#include "tuscany/sca/cpp/CPPServiceProxy.h" + +using namespace std; +using namespace commonj::sdo; +using namespace osoa::sca; +using namespace tuscany::sca::model; + +namespace tuscany +{ + namespace sca + { + namespace cpp + { + + // =========== + // Constructor + // =========== + CompositeContextImpl::CompositeContextImpl(Component* component) + : CompositeContext(0), component(component), composite((Composite*)component->getType()) + { + logentry(); + } + + // ========== + // Destructor + // ========== + CompositeContextImpl::~CompositeContextImpl() + { + logentry(); + } + + // =========================================================================== + // locateService: return a proxy connected to a wrapper for the target service + // =========================================================================== + void* CompositeContextImpl::locateService(const std::string& serviceName) + { + logentry(); + try + { + // ---------------------------- + // Locate the component service + // ---------------------------- + Service* service = composite->findComponentService(serviceName); + string msg; + if (!service) + { + msg = "Service not found: "; + msg = msg + serviceName; + throwException(ServiceNotFoundException, msg.c_str()); + } + + // ---------------------------- + // Get a Proxy for this service + // ---------------------------- + + // The locate service API is used from CPP clients so we are using + // our default service proxy here + CPPServiceProxy* serviceProxy = new CPPServiceProxy(service); + return serviceProxy->getProxy(); + } + catch (ServiceRuntimeException&) + { + throw; + } + catch (TuscanyRuntimeException& e) + { + throwException(ServiceRuntimeException, e); + } + } + + // ============================================== + // getDataFactory: return the data factory for the current composite + // ============================================== + DataFactoryPtr CompositeContextImpl::getDataFactory() + { + logentry(); + try + { + DataFactoryPtr dataFactory = composite->getDataFactory(); + return dataFactory; + } + catch (ServiceRuntimeException&) + { + throw; + } + catch (TuscanyRuntimeException& e) + { + throwException(ServiceRuntimeException, e); + } + } + + } // End namespace cpp + } // End namespace sca +} // End namespace tuscany diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/CompositeContextImpl.h b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/CompositeContextImpl.h new file mode 100644 index 0000000000..ed0bb8b51c --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/CompositeContextImpl.h @@ -0,0 +1,89 @@ +/* + * 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 tuscany_sca_cpp_compositecontextimpl_h +#define tuscany_sca_cpp_compositecontextimpl_h + +#include "osoa/sca/CompositeContext.h" + +#include "tuscany/sca/model/Composite.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/cpp/CPPServiceProxy.h" + +namespace tuscany +{ + namespace sca + { + + namespace cpp + { + + /** + * Contains the actual implementation of a CompositeContext interface. + */ + class CompositeContextImpl : public osoa::sca::CompositeContext + { + + public: + /** + * Constructor that takes a Composite which represents the runtime + * model for this context. + */ + CompositeContextImpl(tuscany::sca::model::Component* component); + + /** + * See CompositeContext#locateService. + */ + virtual void* locateService(const std::string& serviceName); + + /** + * See CompositeContext. + */ + virtual commonj::sdo::DataFactoryPtr getDataFactory(); + + /** + * Destructor. + */ + virtual ~CompositeContextImpl(); + + private: + CompositeContextImpl(const CompositeContextImpl&); + CompositeContextImpl& operator=(const CompositeContextImpl&); + + /** + * Pointer to the runtime model Composite object to which this + * context refers. + */ + tuscany::sca::model::Composite* composite; + + /** + * Pointer to the runtime model Component object to which this + * context refers. + */ + tuscany::sca::model::Component* component; + + }; + + } // End namespace cpp + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_cpp_compositecontextimpl_h diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/TuscanyRuntime.cpp b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/TuscanyRuntime.cpp new file mode 100644 index 0000000000..f8aad90f7a --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/TuscanyRuntime.cpp @@ -0,0 +1,83 @@ +/* + * 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 "tuscany/sca/cpp/TuscanyRuntime.h" +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/util/Utils.h" +#include "tuscany/sca/core/Exceptions.h" +#include "tuscany/sca/core/SCARuntime.h" + +using namespace std; + +namespace tuscany +{ + namespace sca + { + namespace cpp + { + + // =================================================================== + // Constructor for the TuscanyRuntime class. + // =================================================================== + TuscanyRuntime::TuscanyRuntime(const string& componentName, const string& root, const string& path) + { + logentry(); + loginfo("System root: %s", root.c_str()); + systemRoot = root; + loginfo("System path: %s", path.c_str()); + systemPath = path; + loginfo("Default component name: %s", componentName.c_str()); + defaultComponentName = componentName; + + runtime = new SCARuntime("", systemRoot, systemPath, "", defaultComponentName); + } + + // =================================================================== + // Destructor for the TuscanyRuntime class. + // =================================================================== + TuscanyRuntime::~TuscanyRuntime() + { + logentry(); + + delete (SCARuntime*)runtime; + } + + // =================================================================== + // Start the runtime. + // =================================================================== + void TuscanyRuntime::start() + { + logentry(); + SCARuntime::setCurrentRuntime((SCARuntime*)runtime); + } + + // =================================================================== + // Stop the runtime. + // =================================================================== + void TuscanyRuntime::stop() + { + logentry(); + SCARuntime::setCurrentRuntime(NULL); + } + + } // End namespace cpp + } // End namespace sca +} // End namespace tuscany diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/TuscanyRuntime.h b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/TuscanyRuntime.h new file mode 100644 index 0000000000..b4cf31220a --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/TuscanyRuntime.h @@ -0,0 +1,77 @@ +/* + * 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 tuscany_sca_cpp_tuscanyruntime_h +#define tuscany_sca_cpp_tuscanyruntime_h + +#include <string> + +#include "osoa/sca/export.h" + +namespace tuscany +{ + namespace sca + { + namespace cpp + { + + /** + * A singleton which represents the executing SCA runtime. + */ + class SCA_CPP_API TuscanyRuntime + { + public: + /** + * Default constructor + */ + TuscanyRuntime(const std::string& defaultComponentName = "", + const std::string& root = "", const std::string& path = ""); + + /** + * Destructor + */ + virtual ~TuscanyRuntime(); + + /** + * start the runtime + */ + void start(); + + /** + * stop the runtime + */ + void stop(); + + + private: + std::string systemRoot; + std::string systemPath; + std::string defaultComponentName; + + void* defaultComponent; + void* runtime; + }; + + } // End namespace cpp + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_cpp_tuscanyruntime_h diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPImplementation.cpp b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPImplementation.cpp new file mode 100644 index 0000000000..9e5a227f01 --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPImplementation.cpp @@ -0,0 +1,85 @@ +/* + * 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 "tuscany/sca/util/Logging.h" +#include "tuscany/sca/cpp/model/CPPImplementation.h" +#include "tuscany/sca/cpp/model/CPPServiceBinding.h" +#include "tuscany/sca/cpp/model/CPPReferenceBinding.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/Composite.h" +#include "tuscany/sca/model/Service.h" +#include "tuscany/sca/model/Reference.h" +#include "tuscany/sca/util/Utils.h" + +using namespace std; +using namespace tuscany::sca::model; + +namespace tuscany +{ + namespace sca + { + + namespace cpp + { + + // Constructor + CPPImplementation::CPPImplementation(Composite* composite, const string& library, const string& header, + const string&headerPath, const string& headerStub, const string& className, Scope scope) + : ComponentType(composite, headerPath + headerStub), + library(library), header(header), headerPath(headerPath), + headerStub(headerStub), className(className), scope(scope) + { + } + + CPPImplementation::~CPPImplementation() + { + } + + void CPPImplementation::initializeComponent(Component* component) + { + ComponentType::initializeComponent(component); + + // Create CPP bindings for all the services + const Component::SERVICE_MAP& services = component->getServices(); + Component::SERVICE_MAP::const_iterator iter = services.begin(); + for (unsigned int i=0; i< services.size(); i++) + { + Service *service = iter->second; + CPPServiceBinding* binding = new CPPServiceBinding(service); + service->setBinding(binding); + iter++; + } + + // Create CPP bindings for all the references + const Component::REFERENCE_MAP& references = component->getReferences(); + Component::REFERENCE_MAP::const_iterator refiter = references.begin(); + for (unsigned int ri=0; ri< references.size(); ri++) + { + Reference *reference = refiter->second; + CPPReferenceBinding* binding = new CPPReferenceBinding(reference); + reference->setBinding(binding); + refiter++; + } + } + + } // End namespace cpp + } // End namespace sca +} // End namespace tuscany diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPImplementation.h b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPImplementation.h new file mode 100644 index 0000000000..11f487361d --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPImplementation.h @@ -0,0 +1,148 @@ +/* + * 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 tuscany_sca_cpp_model_cppimplementation_h +#define tuscany_sca_cpp_model_cppimplementation_h + +#include <map> +#include <string> + +#include "tuscany/sca/model/ComponentType.h" + +namespace tuscany +{ + namespace sca + { + namespace cpp + { + /** + * Holds information about an SCA implementation written in C++ + */ + class CPPImplementation : public tuscany::sca::model::ComponentType + { + + public: + /** + * Scope of the component implementation. + */ + enum Scope + { + COMPOSITE, + STATELESS + }; + + /** + * Constructor. + * @param dllName Name of the shared library. + * @param header Name of the header file that contains the class declaring the + * implementation class. + * @param className Name of the class in the header file (could be a blank string + * if this is not specified). + */ + CPPImplementation(tuscany::sca::model::Composite* composite, + const std::string& library, const std::string& header, const std::string&headerPath, + const std::string& headerStub, const std::string& className, Scope scope); + + /** + * Destructor + */ + virtual ~CPPImplementation(); + + /** + * Initialize a component of this type. + * @param component The component to initialize. + */ + virtual void initializeComponent(tuscany::sca::model::Component* component); + + /** + * Returns the name of the shared library. + * @return The name of the shared library. + */ + const std::string& getLibrary() const { return library; } + + /** + * Get the name of the header file. + * @return Name of the header file. + */ + const std::string& getHeader() const { return header; } + + /** + * Get the header file name without the extension. + * @return The name of the header file without any extension. + */ + const std::string& getHeaderStub() const { return headerStub; } + + /** + * Get the header path. + * @return The pathe element of the header. + */ + const std::string& getHeaderPath() const { return headerPath; } + + /** + * Get the name of the class. + * @return The class name if specified. + */ + const std::string& getClass() const { return className; } + + /** + * Returns the implementation scope + */ + Scope getScope() { return scope; } + + private: + + /** + * Name of the shared library. + */ + std::string library; + + /** + * Name of the header file describing the interface. + */ + std::string header; + + /** + * Name of the header file without the extension. + */ + std::string headerStub; + + /** + * Path element of the header. + */ + std::string headerPath; + + /** + * Name of the class in the header file declaring the implementation. + * May be an empty string if not set in the SCDL file. + */ + std::string className; + + /** + * Scope of the implementation + */ + Scope scope; + }; + + } // End namespace cpp + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_cpp_model_cppimplementation_h diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPInterface.cpp b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPInterface.cpp new file mode 100644 index 0000000000..2322d1bdf5 --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPInterface.cpp @@ -0,0 +1,63 @@ +/* + * 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 "tuscany/sca/util/Logging.h" +#include "tuscany/sca/util/Utils.h" +#include "tuscany/sca/cpp/model/CPPInterface.h" + +using namespace std; + +namespace tuscany +{ + namespace sca + { + namespace cpp + { + + const string CPPInterface::typeQName("http://www.osoa.org/xmlns/sca/1.0#CPPInterface"); + + // Constructor + CPPInterface::CPPInterface( + const string& header, + const string& className, + bool remotable, + bool conversational) + : Interface(remotable, conversational), header(header), className(className) + { + string::size_type dot = header.rfind(".h"); // this will also find .hpp + if (dot != string::npos) + { + headerStub = header.substr(0, dot); + } + else + { + headerStub = header; + } + + } + + CPPInterface::~CPPInterface() + { + } + + } // End namespace cpp + } // End namespace sca +} // End namespace tuscany diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPInterface.h b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPInterface.h new file mode 100644 index 0000000000..fdbf314d3d --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPInterface.h @@ -0,0 +1,117 @@ +/* + * 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 tuscany_sca_cpp_model_cppinterface_h +#define tuscany_sca_cpp_model_cppinterface_h + +#include <string> + +#include "tuscany/sca/model/Interface.h" + + +namespace tuscany +{ + namespace sca + { + namespace cpp + { + /** + * Holds information about an interface described using a C++ + * header file. + */ + class CPPInterface : public tuscany::sca::model::Interface + { + + public: + /** + * Constuctor. + * @param header Name of the header file containing the class that + * describes the interface. + * @param className Name of the class in the header file that + * describes the interface. + * @param scope The scope of the interface (stateless or composite). + * @param remotable True if the interface is remotable. + */ + CPPInterface( + const std::string& header, + const std::string& className, + bool remotable, + bool conversational); + + /** + * Destructor. + */ + virtual ~CPPInterface(); + + /** + * Get the name of the header file. + * @return The name of the header file containing the definition of the + * interface. + */ + const std::string& getHeader() { return header; } + + /** + * Return the name of the header file without the extension. + * @return Header file name without any extension. + */ + const std::string& getHeaderStub() { return headerStub; } + + /** + * Get the name of the class. + * @return The name of the class defining the interface. + */ + const std::string& getClass() { return className; } + + /** + * return the QName of the schema type for this interface type + * (e.g. "http://www.osoa.org/xmlns/sca/1.0#interface.cpp") + */ + virtual const std::string& getInterfaceTypeQName() { return typeQName; }; + + private: + + /** + * Name of the header file containing the definition of the interface. + */ + std::string header; + + /** + * Name of the header file without the extension. + */ + std::string headerStub; + + /** + * Name of the class in the header file. + */ + std::string className; + + /** + * The QName of the schema type for this interface type. + */ + static const std::string typeQName; + }; + + } // End namespace cpp + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_cpp_model_cppinterface_h + diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPReferenceBinding.cpp b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPReferenceBinding.cpp new file mode 100644 index 0000000000..ba20a1d5a0 --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPReferenceBinding.cpp @@ -0,0 +1,61 @@ +/* + * 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 "tuscany/sca/util/Logging.h" +#include "tuscany/sca/cpp/model/CPPReferenceBinding.h" +#include "tuscany/sca/cpp/CPPServiceProxy.h" + +using namespace tuscany::sca::model; + + +namespace tuscany +{ + namespace sca + { + namespace cpp + { + + // Constructor + CPPReferenceBinding::CPPReferenceBinding(Reference* reference) + : ReferenceBinding(reference, ""), serviceProxy(NULL), targetServiceBinding(NULL) + { + } + + // Destructor + CPPReferenceBinding::~CPPReferenceBinding() + { + } + + ServiceProxy* CPPReferenceBinding::getServiceProxy() + { + return serviceProxy; + } + + void CPPReferenceBinding::configure(ServiceBinding* binding) + { + targetServiceBinding = binding; + + serviceProxy = new CPPServiceProxy(getReference()); + } + + } // End namespace cpp + } // End namespace sca +} // End namespace tuscany diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPReferenceBinding.h b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPReferenceBinding.h new file mode 100644 index 0000000000..398417011f --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPReferenceBinding.h @@ -0,0 +1,96 @@ +/* + * 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 tuscany_sca_cpp_model_cppreferencebinding_h +#define tuscany_sca_cpp_model_cppreferencebinding_h + +#include <string> + +#include "tuscany/sca/model/ReferenceBinding.h" + + +namespace tuscany +{ + namespace sca + { + namespace cpp + { + /** + * Information about a CPP service binding for service or a reference. + */ + class CPPReferenceBinding : public tuscany::sca::model::ReferenceBinding + { + public: + + /** + * Constructor. + * @param uri The uri of the binding. + * @param port The definition of the port to which the entrypoint + * or external service is to be bound. This is of the form + * "namespace"#endpoint("service"/"port") + */ + CPPReferenceBinding(tuscany::sca::model::Reference* reference); + + /** + * Destructor. + */ + virtual ~CPPReferenceBinding(); + + /** + * Returns the type of binding. + */ + virtual std::string getType() { return "http://www.osoa.org/xmlns/sca/1.0#CPPImplementationBinding"; }; + + /** + * Create a proxy representing the reference to the + * client component. + */ + virtual ServiceProxy* getServiceProxy(); + + /** + * Configure this binding from a service binding. + */ + virtual void configure(tuscany::sca::model::ServiceBinding* serviceBinding); + + /** + * Returns the target service binding. + */ + tuscany::sca::model::ServiceBinding* getTargetServiceBinding() const { return targetServiceBinding; }; + + private: + + /** + * The proxy representing the reference to the client + * component. + */ + ServiceProxy* serviceProxy; + + /** + * The service binding of the target + */ + tuscany::sca::model::ServiceBinding* targetServiceBinding; + }; + + } // End namespace cpp + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_cpp_model_cppreferencebinding_h diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPServiceBinding.cpp b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPServiceBinding.cpp new file mode 100644 index 0000000000..45afea8375 --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPServiceBinding.cpp @@ -0,0 +1,54 @@ +/* + * 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 "tuscany/sca/util/Logging.h" +#include "tuscany/sca/cpp/model/CPPServiceBinding.h" +#include "tuscany/sca/cpp/CPPServiceWrapper.h" + +using namespace tuscany::sca::model; + +namespace tuscany +{ + namespace sca + { + namespace cpp + { + + // Constructor + CPPServiceBinding::CPPServiceBinding(Service* service) + : ServiceBinding(service, "") + { + serviceWrapper = CPPServiceWrapper::getServiceWrapper(service); + } + + // Destructor + CPPServiceBinding::~CPPServiceBinding() + { + } + + ServiceWrapper* CPPServiceBinding::getServiceWrapper() + { + return (ServiceWrapper*)serviceWrapper; + } + + } // End namespace ws + } // End namespace sca +} // End namespace tuscany diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPServiceBinding.h b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPServiceBinding.h new file mode 100644 index 0000000000..13b88a84dd --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/src/tuscany/sca/cpp/model/CPPServiceBinding.h @@ -0,0 +1,81 @@ +/* + * 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 tuscany_sca_cpp_model_cppservicebinding_h +#define tuscany_sca_cpp_model_cppservicebinding_h + +#include <string> + +#include "tuscany/sca/model/ServiceBinding.h" + + +namespace tuscany +{ + namespace sca + { + namespace cpp + { + /** + * Information about a CPP service binding for service or a reference. + */ + class CPPServiceBinding : public tuscany::sca::model::ServiceBinding + { + public: + + /** + * Constructor. + * @param uri The uri of the binding. + * @param port The definition of the port to which the entrypoint + * or external service is to be bound. This is of the form + * "namespace"#endpoint("service"/"port") + */ + CPPServiceBinding(tuscany::sca::model::Service* service); + + /** + * Destructor. + */ + virtual ~CPPServiceBinding(); + + /** + * Returns the type of binding. + */ + virtual std::string getType() { return "http://www.osoa.org/xmlns/sca/1.0#CPPImplementationBinding"; }; + + /** + * Create a wrapper for the service configured by this + * binding. + */ + virtual ServiceWrapper* getServiceWrapper(); + + private: + + /** + * The wrapper for the service configured by this binding. + */ + ServiceWrapper* serviceWrapper; + + }; + + } // End namespace cpp + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_cpp_model_cppservicebinding_h diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/xsd/sca-implementation-cpp.xsd b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/xsd/sca-implementation-cpp.xsd new file mode 100644 index 0000000000..7292f747b8 --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/xsd/sca-implementation-cpp.xsd @@ -0,0 +1,49 @@ +<?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. +--> + +<schema xmlns="http://www.w3.org/2001/XMLSchema" + targetNamespace="http://www.osoa.org/xmlns/sca/1.0" + xmlns:sca="http://www.osoa.org/xmlns/sca/1.0" + elementFormDefault="qualified"> + + <element name="implementation.cpp" type="sca:CPPImplementation" substitutionGroup="sca:implementation"/> + <complexType name="CPPImplementation"> + <complexContent> + <extension base="sca:Implementation"> + <sequence> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" /> + </sequence> + <attribute name="library" type="NCName" use="required"/> + <attribute name="path" type="NCName" use="optional"/> + <attribute name="header" type="NCName" use="required"/> + <attribute name="class" type="Name" use="optional"/> + <attribute name="scope" type="sca:CPPImplementationScope" use="optional" /> + <anyAttribute namespace="##any" processContents="lax"/> + </extension> + </complexContent> + </complexType> + + <simpleType name="CPPImplementationScope"> + <restriction base="string"> + <enumeration value="stateless" /> + <enumeration value="composite" /> + </restriction> + </simpleType> +</schema> diff --git a/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/xsd/sca-interface-cpp.xsd b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/xsd/sca-interface-cpp.xsd new file mode 100644 index 0000000000..585bac0dc4 --- /dev/null +++ b/tags/native-sca-1.0.incubating-M3-RC4/runtime/extensions/cpp/xsd/sca-interface-cpp.xsd @@ -0,0 +1,43 @@ +<?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. +--> + +<schema xmlns="http://www.w3.org/2001/XMLSchema" + targetNamespace="http://www.osoa.org/xmlns/sca/1.0" + xmlns:sca="http://www.osoa.org/xmlns/sca/1.0" + elementFormDefault="qualified"> + + <element name="interface.cpp" type="sca:CPPInterface" substitutionGroup="sca:interface"/> + <complexType name="CPPInterface"> + <complexContent> + <extension base="sca:Interface"> + <sequence> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" /> + </sequence> + <attribute name="header" type="NCName" use="required" /> + <attribute name="class" type="Name" use="optional" /> + <attribute name="callbackHeader" type="NCName" use="optional" /> + <attribute name="callbackClass" type="Name" use="optional" /> + <attribute name="remotable" type="boolean" use="optional" /> + <anyAttribute namespace="##any" processContents="lax" /> + </extension> + </complexContent> + </complexType> + +</schema> |