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 /cpp/sca/runtime/extensions/ruby |
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 'cpp/sca/runtime/extensions/ruby')
22 files changed, 2797 insertions, 0 deletions
diff --git a/cpp/sca/runtime/extensions/ruby/build.xml b/cpp/sca/runtime/extensions/ruby/build.xml new file mode 100644 index 0000000000..414ff9bbf8 --- /dev/null +++ b/cpp/sca/runtime/extensions/ruby/build.xml @@ -0,0 +1,232 @@ +<?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. +--> +<project name="TuscanyScaNative_extension_ruby" default="all" basedir="../../.."> + + <import file="${basedir}/antscripts/system.xml"/> + <import file="${basedir}/antscripts/compile-targets.xml"/> + + <!-- + Notice that the basedir for this project is set to the TuscanySCA root dir + This makes path setting in system.xml much simpler, but we'll just have to + set a property here to this directory. + --> + <property name="this.dir" location="${basedir}/runtime/extensions/ruby"/> + <property name="this.src.dir" location="${basedir}/runtime/extensions/ruby/src"/> + <property name="ruby.xsd.dir" location="${this.dir}/xsd"/> + <property name="ruby.core.dir" location="${this.src.dir}/tuscany/sca/ruby"/> + <property name="ruby.model.dir" location="${this.src.dir}/tuscany/sca/ruby/model"/> + <property name="ruby.extension.dir" location="${this.dir}/extension/src"/> + <property name="lib.extension.dir" location="${this.dir}/extension/.libs"/> + <property name="lib.dir" location="${this.src.dir}/.libs"/> + <property name="ruby.core.lib" value="tuscany_sca_ruby_lang"/> + <property name="ruby.extension.lib" value="tuscany_sca_ruby"/> + <property name="ruby.install.dir" location="${tuscanySCA.install.dir}/extensions/ruby"/> + + <!-- + All the cpp files per subdirectory + New classes should be added to these properties + --> + <property + name="ruby.core.cpp.files" + value="RubyCompositeContext.cpp + RubyExtension.cpp + RubyImplementationExtension.cpp + RubyServiceProxy.cpp + RubyServiceWrapper.cpp"/> + + <property + name="ruby.model.cpp.files" + value="RubyImplementation.cpp + RubyReferenceBinding.cpp + RubyServiceBinding.cpp"/> + + <property + name="ruby.extension.cpp.files" + value="Extension.cpp"/> + + <property + name="ruby.xsd.files" + value="sca-implementation-ruby.xsd"/> + + <!-- + Public targets + --> + <target name="all" + description="Compile, link, and install all TuscanyScaNative ruby extension source code"> + <antcall target="compile"/> + <antcall target="link"/> + <antcall target="install"/> + </target> + + <target name="build" description="Compile and link all TuscanyScaNative ruby extension source code"> + <antcall target="compile"/> + <antcall target="link"/> + </target> + + <target name="compile" description="Compile all TuscanyScaNative ruby extension source code"> + <antcall target="compile.ruby.core"/> + <antcall target="compile.ruby.model"/> + <antcall target="compile.ruby.extension"/> + </target> + + <target name="link" description="Link all TuscanyScaNative ruby extension source code"> + <antcall target="link.ruby.core"/> + <antcall target="link.ruby.extension"/> + </target> + + <target name="install" description="Install TuscanyScaNative ruby extension libraries and headers"> + <antcall target="install.ruby.core"/> + <antcall target="install.ruby.extension"/> + <antcall target="install.ruby.xsd"/> + </target> + + <target name="clean" description="Clean all TuscanyScaNative ruby extension compiled source code"> + <antcall target="clean.ruby.core"/> + <antcall target="clean.ruby.extension"/> + <antcall target="clean.ruby.xsd"/> + </target> + + <!-- + Internal targets + They can still be called, they're just not described, so wont show up in "ant -p" + --> + + <!-- compile --> + + <target name="compile.ruby.core" depends="check.ruby" if="enable_ruby"> + <cpp-compile + srcdir="${ruby.core.dir}" + objdir="${lib.dir}" + infiles="${ruby.core.cpp.files}"> + <custom-cc-elements> + <includepath path="${this.src.dir}"/> + <includepath path="${ruby.include.dir}"/> + <defineset if="windows" define="TUSCANY_SCA_RUBY_LANG_EXPORTS"/> + </custom-cc-elements> + </cpp-compile> + </target> + + <target name="compile.ruby.model" depends="check.ruby" if="enable_ruby"> + <cpp-compile + srcdir="${ruby.model.dir}" + objdir="${lib.dir}" + infiles="${ruby.model.cpp.files}"> + <custom-cc-elements> + <includepath path="${this.src.dir}"/> + <includepath path="${ruby.include.dir}"/> + <defineset if="windows" define="TUSCANY_SCA_RUBY_LANG_EXPORTS"/> + </custom-cc-elements> + </cpp-compile> + </target> + + <target name="compile.ruby.extension" depends="check.ruby" if="enable_ruby"> + <cpp-compile + srcdir="${ruby.extension.dir}" + objdir="${lib.extension.dir}" + infiles="${ruby.extension.cpp.files}"> + <custom-cc-elements> + <includepath path="${this.src.dir}"/> + <includepath path="${ruby.include.dir}"/> + </custom-cc-elements> + </cpp-compile> + </target> + + <!-- link --> + + <target name="link.ruby.core" depends="check.ruby" if="enable_ruby"> + <cpp-link + outfile="${ruby.core.lib}" + outdir="${lib.dir}" + indir="${lib.dir}" + infiles="*${object.ext}"> + <custom-ld-elements> + <libset dir="${ruby.lib.dir}" libs="ruby"/> + </custom-ld-elements> + </cpp-link> + </target> + + <target name="link.ruby.extension" depends="check.ruby" if="enable_ruby"> + <cpp-link + outfile="${ruby.extension.lib}" + outdir="${lib.extension.dir}" + indir="${lib.extension.dir}" + infiles="*${object.ext}"/> + </target> + + <!-- install --> + + <target name="install.ruby.core" depends="check.ruby" if="enable_ruby"> + <cpp-install-lib + lib="${ruby.core.lib}" + srcdir="${lib.dir}" + destrootdir="${ruby.install.dir}"/> + <cpp-symlink + linkdir="${ruby.install.dir}/lib" + link="${lib.prefix}${ruby.core.lib}${lib.ext}" + resource="${lib.prefix}${ruby.core.lib}${lib.ext}${tuscanySCA.library.version}"/> + <cpp-symlink + linkdir="${ruby.install.dir}/module" + link="${lib.prefix}${ruby.core.lib}${lib.ext}" + resourcedir="${ruby.install.dir}/lib" + resource="${lib.prefix}${ruby.core.lib}${lib.ext}"/> + </target> + + <target name="install.ruby.extension" depends="check.ruby" if="enable_ruby"> + <cpp-install-file + srcfile="${lib.prefix}${ruby.extension.lib}${lib.ext}" + destfile="${ruby.extension.lib}${lib.ext}" + srcdir="${lib.extension.dir}" + destdir="${ruby.install.dir}/lib"/> + </target> + + <target name="install.ruby.xsd" depends="check.ruby" if="enable_ruby"> + <cpp-install-files + files="${ruby.xsd.files}" + srcdir="${ruby.xsd.dir}" + destdir="${ruby.install.dir}/xsd"/> + </target> + + <!-- clean --> + + <target name="clean.ruby.core"> + <cpp-clean-lib + lib="${ruby.core.lib}" + librootdir="${ruby.install.dir}"/> + <cpp-clean-files + dir="${ruby.install.dir}/module" + rmdir="true"/> + <delete dir="${lib.dir}" quiet="true"/> + </target> + + <target name="clean.ruby.extension"> + <cpp-clean-files + dir="${ruby.install.dir}/lib" + files="${ruby.extension.lib}${lib.ext}" + rmdir="true"/> + <delete dir="${lib.extension.dir}" quiet="true"/> + </target> + + <target name="clean.ruby.xsd"> + <cpp-clean-files + dir="${ruby.install.dir}/xsd" + rmdir="true"/> + </target> + +</project> diff --git a/cpp/sca/runtime/extensions/ruby/extension/src/Extension.cpp b/cpp/sca/runtime/extensions/ruby/extension/src/Extension.cpp new file mode 100644 index 0000000000..458700e5f1 --- /dev/null +++ b/cpp/sca/runtime/extensions/ruby/extension/src/Extension.cpp @@ -0,0 +1,56 @@ +/* + * 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$ */ + +#if defined(WIN32) || defined (_WINDOWS) +#define SCA_RUBYEXTENSION_API __declspec(dllexport) +#else +#define SCA_RUBYEXTENSION_API +#endif + +#include "tuscany/sca/ruby/Ruby.h" +#include "tuscany/sca/ruby/RubyCompositeContext.h" + +extern "C" +{ + + // Implement the Sca::locateService module function + SCA_RUBYEXTENSION_API VALUE tuscany_sca_ruby_locateService(VALUE module, VALUE value) + { + // Locate the service + const char* serviceName = rb_string_value_cstr(&value); + return tuscany::sca::ruby::RubyCompositeContext::locateService(serviceName); + } + + // Initialize the Ruby extension + SCA_RUBYEXTENSION_API void Init_tuscany_sca_ruby() + { + + // Define the Sca::locateService() function + VALUE module = rb_define_module("SCA"); + rb_define_module_function(module, "locateService", (VALUE(*)(ANYARGS))tuscany_sca_ruby_locateService, 1); + + } + + SCA_RUBYEXTENSION_API void Init_libtuscany_sca_ruby() + { + Init_tuscany_sca_ruby(); + } +} diff --git a/cpp/sca/runtime/extensions/ruby/extension/src/extconf.rb b/cpp/sca/runtime/extensions/ruby/extension/src/extconf.rb new file mode 100644 index 0000000000..9c41843d63 --- /dev/null +++ b/cpp/sca/runtime/extensions/ruby/extension/src/extconf.rb @@ -0,0 +1,25 @@ +# +# 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. +# + + require 'mkmf' + CONFIG["CC"] = "g++" + $CPPFLAGS << " -I../../src " + $LIBPATH << "../../src/.libs" + $LIBS << " -ltuscany_sca_ruby_lang " + create_makefile 'tuscany_sca_ruby' diff --git a/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/Ruby.h b/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/Ruby.h new file mode 100644 index 0000000000..a6b8ee8ffa --- /dev/null +++ b/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/Ruby.h @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* $Rev$ $Date$ */ + +#ifndef tuscany_sca_ruby_ruby_h +#define tuscany_sca_ruby_ruby_h + +// Ruby inists on MS VC6 ... we'll see about that! +#if defined(WIN32) || defined (_WINDOWS) +#define _REAL_MSC_VER _MSC_VER +#undef _MSC_VER +#define _MSC_VER 1200 +#endif + +#include <ruby.h> + +#if defined(WIN32) || defined (_WINDOWS) +#undef _MSC_VER +#define _MSC_VER _REAL_MSC_VER +#endif + +#endif // tuscany_sca_ruby_ruby_h diff --git a/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyCompositeContext.cpp b/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyCompositeContext.cpp new file mode 100644 index 0000000000..5554ac6756 --- /dev/null +++ b/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyCompositeContext.cpp @@ -0,0 +1,70 @@ +/* + * 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/core/SCARuntime.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/model/Composite.h" +#include "tuscany/sca/ruby/RubyServiceProxy.h" +#include "tuscany/sca/ruby/RubyCompositeContext.h" + +using namespace std; +using namespace tuscany::sca::model; + + +namespace tuscany +{ + namespace sca + { + namespace ruby + { + + VALUE RubyCompositeContext::locateService(const char* serviceName) + { + // Get the default component + Component* defaultComponent = tuscany::sca::SCARuntime::getCurrentRuntime()->getDefaultComponent(); + Composite* composite = (Composite*)defaultComponent->getType(); + + // Locate the service + Service* service = composite->findComponentService(serviceName); + string msg; + if (!service) + { + string msg = "Service not found: "; + msg = msg + serviceName; + rb_raise(rb_eRuntimeError, msg.c_str()); + } + + // Get a Proxy for this service + tuscany::sca::ruby::RubyServiceProxy* serviceProxy = new tuscany::sca::ruby::RubyServiceProxy(service); + + // Return the Ruby proxy value object + return serviceProxy->getProxyValue(); + } + + + } // End namespace ruby + } // End namespace sca +} // End namespace tuscany diff --git a/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyCompositeContext.h b/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyCompositeContext.h new file mode 100644 index 0000000000..2414b66fb1 --- /dev/null +++ b/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyCompositeContext.h @@ -0,0 +1,50 @@ +/* + * 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_ruby_RubyCompositeContext_h +#define tuscany_sca_ruby_RubyCompositeContext_h + +#include "tuscany/sca/ruby/Ruby.h" +#include "tuscany/sca/ruby/export.h" + + + +namespace tuscany +{ + namespace sca + { + namespace ruby + { + + class RubyCompositeContext + { + public: + SCA_RUBY_API static VALUE locateService(const char* serviceName); + + }; + + + } // End namespace ruby + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_ruby_RubyCompositeContext_h + diff --git a/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyExtension.cpp b/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyExtension.cpp new file mode 100644 index 0000000000..5789517cfd --- /dev/null +++ b/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyExtension.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/ruby/RubyExtension.h" +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/core/SCARuntime.h" +#include "tuscany/sca/ruby/RubyImplementationExtension.h" + +using namespace std; +using namespace commonj::sdo; +using namespace tuscany::sca::model; + +extern "C" +{ +#if defined(WIN32) || defined(_WINDOWS) + __declspec(dllexport) +#endif + void tuscany_sca_ruby_lang_initialize() + { + tuscany::sca::ruby::RubyExtension::initialize(); + } +} + +namespace tuscany +{ + namespace sca + { + namespace ruby + { + // =================================================================== + // Constructor for the RubyExtension class. + // =================================================================== + RubyExtension::RubyExtension() + { + logentry(); + } + + // =================================================================== + // Destructor for the RubyExtension class. + // =================================================================== + RubyExtension::~RubyExtension() + { + logentry(); + } + + void RubyExtension::initialize() + { + logentry(); + SCARuntime::getCurrentRuntime()->registerImplementationExtension(new RubyImplementationExtension()); + } + + } // End namespace ruby + } // End namespace sca +} // End namespace tuscany diff --git a/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyExtension.h b/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyExtension.h new file mode 100644 index 0000000000..232431ca1e --- /dev/null +++ b/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyExtension.h @@ -0,0 +1,58 @@ +/* + * 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_ruby_rubyextension_h +#define tuscany_sca_ruby_rubyextension_h + +namespace tuscany +{ + namespace sca + { + namespace ruby + { + + class RubyExtension + { + public: + /** + * Default constructor + */ + RubyExtension(); + + /** + * Destructor + */ + virtual ~RubyExtension(); + + static void initialize(); + + private: + + }; + + + } // End namespace ruby + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_ruby_rubyextension_h + diff --git a/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyImplementationExtension.cpp b/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyImplementationExtension.cpp new file mode 100644 index 0000000000..aa416f139a --- /dev/null +++ b/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyImplementationExtension.cpp @@ -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$ */ + +#include "tuscany/sca/ruby/RubyImplementationExtension.h" +#include "tuscany/sca/ruby/model/RubyImplementation.h" +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/util/Utils.h" + +using namespace std; +using namespace commonj::sdo; +using namespace tuscany::sca::model; + +namespace tuscany +{ + namespace sca + { + namespace ruby + { + // =================================================================== + // Constructor for the RubyImplementationExtension class. + // =================================================================== + RubyImplementationExtension::RubyImplementationExtension() + { + logentry(); + } + + // =================================================================== + // Destructor for the RubyImplementationExtension class. + // =================================================================== + RubyImplementationExtension::~RubyImplementationExtension() + { + logentry(); + } + + const string RubyImplementationExtension::extensionName("ruby"); + const string RubyImplementationExtension::typeQName("http://www.osoa.org/xmlns/sca/1.0#RubyImplementation"); + + // =================================================================== + // loadModelElement - load the info from implementation.ruby + // =================================================================== + ComponentType* RubyImplementationExtension::getImplementation(Composite *composite, DataObjectPtr scdlImplementation) + { + logentry(); + + string module = scdlImplementation->getCString("module"); + string className = scdlImplementation->getCString("class"); + string script = scdlImplementation->getCString("script"); + + RubyImplementation* rubyImpl = new RubyImplementation(composite, module, className, script); + + return rubyImpl; + } + + } // End namespace ruby + } // End namespace sca +} // End namespace tuscany diff --git a/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyImplementationExtension.h b/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyImplementationExtension.h new file mode 100644 index 0000000000..79d9ed2dbe --- /dev/null +++ b/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyImplementationExtension.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_ruby_rubyimplementationextension_h +#define tuscany_sca_ruby_rubyimplementationextension_h + +#include "tuscany/sca/extension/ImplementationExtension.h" + +namespace tuscany +{ + namespace sca + { + namespace ruby + { + + class RubyImplementationExtension : public ImplementationExtension + { + public: + /** + * Default constructor + */ + RubyImplementationExtension(); + + /** + * Destructor + */ + virtual ~RubyImplementationExtension(); + + /** + * return the name of the extension + */ + virtual const std::string& getExtensionName() {return extensionName;} + + /** + * return the QName of schema elemant for this implementation extension + * (e.g. "http://www.osoa.org/xmlns/sca/1.0#implementation.ruby") + */ + 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 ruby + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_ruby_rubyimplementationextension_h + diff --git a/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceProxy.cpp b/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceProxy.cpp new file mode 100644 index 0000000000..d830cd92de --- /dev/null +++ b/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceProxy.cpp @@ -0,0 +1,384 @@ +/* + * 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 <sstream> + +#include "tuscany/sca/ruby/RubyServiceProxy.h" +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/core/SCARuntime.h" +#include "tuscany/sca/core/Exceptions.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/ruby/model/RubyImplementation.h" +#include "tuscany/sca/ruby/model/RubyReferenceBinding.h" + +using namespace std; +using namespace commonj::sdo; +using namespace tuscany::sca::model; + +extern "C" +{ + + // Initialize a Ruby proxy + SCA_RUBY_API VALUE tuscany_sca_ruby_proxy_initialize(VALUE self, VALUE serviceProxy) + { + rb_iv_set(self, "@cppProxy", serviceProxy); + return self; + } + + // Handle a method_missing message and dispatch to + // our C++ proxy + SCA_RUBY_API VALUE tuscany_sca_ruby_proxy_method_missing(int argc, VALUE* argv, VALUE self) + { + VALUE proxy = rb_iv_get(self, "@cppProxy"); + + // Get the target service wrapper + tuscany::sca::ruby::RubyServiceProxy *serviceProxy; + Data_Get_Struct(proxy, tuscany::sca::ruby::RubyServiceProxy, serviceProxy); + + // Handle the invocation + return serviceProxy->invoke(argc, argv); + + } + +} + +namespace tuscany +{ + namespace sca + { + namespace ruby + { + + VALUE RubyServiceProxy::proxyClass = Qnil; + + // ============================ + // Constructor: Create a proxy + // ============================ + RubyServiceProxy::RubyServiceProxy(Reference* reference) + : ServiceProxy(reference) + { + logentry(); + + // ---------------------- + // Get the component + // ---------------------- + component = reference->getComponent(); + string name = reference->getType()->getName(); + + // Get the service wrapper + RubyReferenceBinding* referenceBinding = (RubyReferenceBinding*)reference->getBinding(); + + serviceWrapper = referenceBinding->getTargetServiceBinding()->getServiceWrapper(); + + // Create the Ruby proxy + createProxy(); + } + + // ============================ + // Constructor: Create a proxy + // ============================ + RubyServiceProxy::RubyServiceProxy(Service* service) + : ServiceProxy(0) + { + logentry(); + + // ---------------------- + // Get the component + // ---------------------- + component = service->getComponent(); + string name = service->getType()->getName(); + + // Get the service wrapper + serviceWrapper = service->getBinding()->getServiceWrapper(); + + // Create the Ruby proxy + createProxy(); + } + + // ========== + // Destructor + // ========== + RubyServiceProxy::~RubyServiceProxy() + { + logentry(); + } + + void RubyServiceProxy::createProxy() + { + logentry(); + + // Create the Ruby proxy class + if (RubyServiceProxy::proxyClass == Qnil) + { + VALUE module = rb_define_module("Tuscany"); + proxyClass = rb_define_class_under(module, "ServiceProxy", rb_cObject); + rb_define_method(proxyClass, "initialize", (VALUE(*)(ANYARGS))tuscany_sca_ruby_proxy_initialize, 1); + rb_define_method(proxyClass, "method_missing", (VALUE(*)(ANYARGS))tuscany_sca_ruby_proxy_method_missing, -1); + } + + // Create the Ruby proxy instance, pass the service wrapper to it + VALUE* args = new VALUE[1]; + args[0] = Data_Wrap_Struct(rb_cObject, NULL, NULL, this); + proxyValue = rb_class_new_instance(1, args, proxyClass); + + // Mark proxyValue busy so that it doesn't get GC'ed by Ruby + rb_gc_register_address(&proxyValue); + } + + + VALUE RubyServiceProxy::invoke(int argc, VALUE* argv) + { + logentry(); + + // Get the method name + char* methodName = rb_id2name(SYM2ID(argv[0])); + + // Get the block passed by the caller + VALUE block =rb_block_given_p() ? rb_block_proc() : Qnil; + + // Create new Operation object + Operation operation(methodName); + + // Convert the Ruby parameters to C++ + for (int i = 1; i < argc; i++) + { + VALUE value = argv[i]; + + int valueType = TYPE(value); + + switch (valueType) + { + case T_FLOAT: + { + float* data = new float; + *data = rb_num2dbl(value); + operation.addParameter(data); + break; + } + case T_STRING: + { + string* data = new string(rb_string_value_cstr(&value)); + const char** cdata = new const char*; + *cdata = data->c_str(); + operation.addParameter(cdata); + break; + } + case T_FIXNUM: + { + long* data = new long; + *data = rb_num2long(value); + operation.addParameter(data); + break; + } + case T_BIGNUM: + { + long double* data = new long double; + *data = rb_num2dbl(value); + operation.addParameter(data); + break; + } + case T_TRUE: + { + bool* data = new bool; + *data = true; + operation.addParameter(data); + break; + } + case T_FALSE: + { + bool* data = new bool; + *data = false; + operation.addParameter(data); + break; + } + case T_OBJECT: + { + VALUE klass = rb_obj_class(value); + if (klass == RubyImplementation::getXMLDocumentClass()) + { + // Convert a REXML::Document to a DataObject + ID to_s = rb_intern("to_s"); + VALUE vstr = rb_funcall(value, to_s, 0); + string str = string(rb_string_value_cstr(&vstr)); + + loginfo("Converting Ruby Rexml document to SDO DataObject: %s", str.c_str()); + + Composite* composite = getReference()->getComponent()->getComposite(); + commonj::sdo::XMLHelperPtr xmlHelper = composite->getXMLHelper(); + commonj::sdo::XMLDocumentPtr xmlDoc = xmlHelper->load(str.c_str()); + + DataObjectPtr dob; + if (xmlDoc != NULL) + { + dob = xmlDoc->getRootDataObject(); + } + if (dob != NULL) + { + DataObjectPtr* dataObjectData = new DataObjectPtr; + *dataObjectData = dob; + operation.addParameter(dataObjectData); + } + else + { + string msg = "Document could not be converted to a DataObject"; + rb_raise(rb_eTypeError, msg.c_str()); + return Qnil; + } + } + else + { + string msg = "Ruby type not supported: " + valueType; + rb_raise(rb_eTypeError, msg.c_str()); + return Qnil; + } + break; + } + default:; + string msg = "Ruby type not supported: " + valueType; + rb_raise(rb_eTypeError, msg.c_str()); + return Qnil; + } + + } + + try + { + // Call into the target service wrapper + serviceWrapper->invoke(operation); + + // Convert the result to a Ruby value + VALUE value; + Operation::ParameterType resultType = operation.getReturnType(); + switch(resultType) + { + case Operation::BOOL: + { + if( *(bool*)operation.getReturnValue()) + { + //boolean true + value = rb_int2inum(1); + } + else + { + value = rb_int2inum(0); + } + break; + } + case Operation::SHORT: + { + value = rb_int2inum(*(short*)operation.getReturnValue()); + break; + } + case Operation::USHORT: + { + value = rb_uint2inum(*(unsigned short*)operation.getReturnValue()); + break; + } + case Operation::LONG: + { + value = rb_int2inum(*(long*)operation.getReturnValue()); + break; + } + case Operation::ULONG: + { + value = rb_uint2inum(*(unsigned long*)operation.getReturnValue()); + break; + } + case Operation::FLOAT: + { + value = rb_float_new(*(float*)operation.getReturnValue()); + break; + } + case Operation::DOUBLE: + { + value = rb_float_new(*(double*)operation.getReturnValue()); + break; + } + case Operation::LONGDOUBLE: + { + value = rb_float_new(*(long double*)operation.getReturnValue()); + break; + } + case Operation::CHARS: + { + value = rb_str_new2(*(char**)operation.getReturnValue()); + break; + } + case Operation::STRING: + { + value = rb_str_new2((*(string*)operation.getReturnValue()).c_str()); + break; + } + case Operation::DATAOBJECT: + { + DataObjectPtr dob = *(DataObjectPtr*)operation.getReturnValue(); + + // Convert a DataObject to a REXML Document object + Composite* composite = component->getComposite(); + commonj::sdo::XMLHelperPtr xmlHelper = composite->getXMLHelper(); + char* str = xmlHelper->save( + dob, + dob->getType().getURI(), + dob->getType().getName()); + + loginfo("Converting SDO DataObject to Ruby Rexml document: %s", str); + + VALUE vstr[1]; + vstr[0] = rb_str_new2(str); + + value = rb_class_new_instance(1, vstr, RubyImplementation::getXMLDocumentClass()); + break; + } + default: + { + value = Qnil; + break; + } + } + + return value; + + } + catch(TuscanyRuntimeException& ex) + { + string msg = "Exception while invoking a service: "; + msg += ex.getEClassName(); + msg += ": "; + msg += ex.getMessageText(); + rb_raise(rb_eRuntimeError, msg.c_str()); + return Qnil; + } + + return Qnil; + } + + } // End namespace ruby + } // End namespace sca +} // End namespace tuscany diff --git a/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceProxy.h b/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceProxy.h new file mode 100644 index 0000000000..e6c37cf1da --- /dev/null +++ b/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceProxy.h @@ -0,0 +1,114 @@ +/* + * 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_ruby_rubyserviceproxy_h +#define tuscany_sca_ruby_rubyserviceproxy_h + +#include "tuscany/sca/ruby/Ruby.h" +#include "tuscany/sca/ruby/export.h" +#include "tuscany/sca/core/ServiceProxy.h" +#include "tuscany/sca/core/ServiceWrapper.h" +#include "tuscany/sca/model/Component.h" +#include "tuscany/sca/model/Reference.h" +#include "tuscany/sca/model/Service.h" + + +namespace tuscany +{ + namespace sca + { + namespace ruby + { + + /** + * 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 RubyServiceProxy : 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. + */ + RubyServiceProxy(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. + */ + RubyServiceProxy(tuscany::sca::model::Service* service); + + /** + * Destructor. + */ + virtual ~RubyServiceProxy(); + + /** + * Returns the Ruby value of the proxy + */ + VALUE getProxyValue() const { return proxyValue; }; + + /** + * Handles the invocation of a Ruby method. + */ + VALUE invoke(int argc, VALUE* argv); + + private: + + /** + * Create the Ruby proxy object + */ + void createProxy(); + + /** + * The target service wrapper + */ + ServiceWrapper* serviceWrapper; + + /** + * The Ruby value of the proxy + */ + VALUE proxyValue; + + /** + * The component owning the proxy + */ + tuscany::sca::model::Component* component; + + /** + * The Ruby proxy class + */ + static VALUE proxyClass; + + }; + + } // End namespace ruby + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_ruby_rubyserviceproxy_h diff --git a/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceWrapper.cpp b/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceWrapper.cpp new file mode 100644 index 0000000000..db6bc07b7e --- /dev/null +++ b/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceWrapper.cpp @@ -0,0 +1,794 @@ +/* + * 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 <sstream> + +#include "commonj/sdo/SDO.h" + +#include "tuscany/sca/ruby/RubyServiceWrapper.h" +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/core/Exceptions.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/model/Reference.h" +#include "tuscany/sca/model/ReferenceType.h" +#include "tuscany/sca/core/SCARuntime.h" +#include "tuscany/sca/ruby/model/RubyImplementation.h" +#include "tuscany/sca/ruby/model/RubyServiceBinding.h" +#include "tuscany/sca/ruby/RubyServiceProxy.h" + +using namespace std; +using namespace commonj::sdo; +using namespace tuscany::sca::model; + +namespace tuscany +{ + namespace sca + { + namespace ruby + { + + class RubyServiceInvocation + { + public: + VALUE instance; + ID method; + int argc; + const VALUE* argv; + }; + } + } +} + +extern "C" +{ + + static VALUE safe_rb_funcall(VALUE value) + { + tuscany::sca::ruby::RubyServiceInvocation* call = (tuscany::sca::ruby::RubyServiceInvocation*)value; + if (call->argc == 0) + { + VALUE result = rb_funcall(call->instance, call->method, 0); + return result; + } + else + { + VALUE result = rb_funcall2(call->instance, call->method, call->argc, call->argv); + return result; + } + } + +} + +namespace tuscany +{ + namespace sca + { + namespace ruby + { + + // =========== + // Constructor + // =========== + RubyServiceWrapper::RubyServiceWrapper(Service* service) + : ServiceWrapper(service) + { + logentry(); + + component = service->getComponent(); + implementation = (RubyImplementation*)component->getType(); + interf = service->getType()->getInterface(); + } + + // ========== + // Destructor + // ========== + RubyServiceWrapper::~RubyServiceWrapper() + { + logentry(); + } + + // ====================================================================== + // invoke: wrapper call to service with setting the component context + // ====================================================================== + void RubyServiceWrapper::invoke(Operation& operation) + { + logentry(); + + SCARuntime* runtime = SCARuntime::getCurrentRuntime(); + runtime->setCurrentComponent(component); + + try + { + + // Create a new instance of the Ruby implementation class + VALUE instance = rb_class_new_instance(0, NULL, implementation->getImplementationClass()); + + // Set all the references + const Component::REFERENCE_MAP& references = component->getReferences(); + Component::REFERENCE_MAP::const_iterator refiter = references.begin(); + for (int ri=0; ri< references.size(); ri++) + { + Reference* reference = refiter->second; + RubyServiceProxy* proxy = (RubyServiceProxy*)reference->getBinding()->getServiceProxy(); + if (proxy != NULL) + { + VALUE proxyValue = proxy->getProxyValue(); + string varName = "@" + refiter->first; + rb_iv_set(instance, varName.c_str(), proxyValue); + } + refiter++; + } + + // Set all the configured properties + DataObjectPtr properties = component->getProperties(); + PropertyList pl = properties->getInstanceProperties(); + for (int i = 0; i < pl.size(); i++) + { + if (properties->isSet(pl[i])) + { + string varName = "@"; + varName += pl[i].getName(); + string cstr = properties->getCString(pl[i]); + VALUE propertyValue; + if (cstr == "true") + { + propertyValue = Qtrue; + } + else if (cstr == "false") + { + propertyValue = Qfalse; + } + else + { + //TODO use one of the rb_str_to_inum() functions + // to convert a numeric value to a Ruby numeric + propertyValue = rb_str_new2(cstr.c_str()); + } + rb_iv_set(instance, varName.c_str(), propertyValue); + } + } + + // Get the ID of the specified method + ID method = rb_intern(operation.getName().c_str()); + + // Convert C++ parameters to Ruby parameters + VALUE *args = NULL; + int n = operation.getNParms(); + if (n != 0) + { + args=new VALUE[n]; + + for(int i = 0; i < operation.getNParms(); i++) + { + VALUE value; + + const Operation::Parameter& parm = operation.getParameter(i); + Operation::ParameterType parmType = parm.getType(); + switch(parmType) + { + case Operation::BOOL: + { + if( *(bool*)parm.getValue()) + { + //boolean true + value = rb_int2inum(1); + } + else + { + value = rb_int2inum(0); + } + break; + } + case Operation::SHORT: + { + value = rb_int2inum(*(short*)parm.getValue()); + break; + } + case Operation::USHORT: + { + value = rb_uint2inum(*(unsigned short*)parm.getValue()); + break; + } + case Operation::LONG: + { + value = rb_int2inum(*(long*)parm.getValue()); + break; + } + case Operation::ULONG: + { + value = rb_uint2inum(*(unsigned long*)parm.getValue()); + break; + } + case Operation::FLOAT: + { + value = rb_float_new(*(float*)parm.getValue()); + break; + } + case Operation::DOUBLE: + { + value = rb_float_new(*(double*)parm.getValue()); + break; + } + case Operation::LONGDOUBLE: + { + value = rb_float_new(*(long double*)parm.getValue()); + break; + } + case Operation::CHARS: + { + value = rb_str_new2(*(char**)parm.getValue()); + break; + } + case Operation::STRING: + { + value = rb_str_new2((*(string*)parm.getValue()).c_str()); + break; + } + case Operation::DATAOBJECT: + { + DataObjectPtr dob = *(DataObjectPtr*)parm.getValue(); + + // Convert a DataObject to a REXML Document object + Composite* composite = component->getComposite(); + commonj::sdo::XMLHelperPtr xmlHelper = composite->getXMLHelper(); + char* str = xmlHelper->save( + dob, + dob->getType().getURI(), + dob->getType().getName()); + + loginfo("Converting SDO DataObject to Ruby Rexml document: %s", str); + + VALUE vstr[1]; + vstr[0] = rb_str_new2(str); + + value = rb_class_new_instance(1, vstr, RubyImplementation::getXMLDocumentClass()); + break; + } + default: + { + ostringstream msg; + msg << "Operation parameter type not supported: " << parmType; + throwException(ServiceDataException, msg.str().c_str()); + } + } + + args[i] = value; + } + } + + + // Invoke the specified method + RubyServiceInvocation call; + call.instance = instance; + call.method = method; + call.argc = n; + call.argv = args; + int error = 0; + VALUE result = rb_protect(safe_rb_funcall, (VALUE)&call, &error); + if (error) + { + // Convert a Ruby error to a C++ exception + VALUE lasterr = rb_gv_get("$!"); + ostringstream msg; + + // class + VALUE klass = rb_class_path(CLASS_OF(lasterr)); + msg << "Ruby Exception " << RSTRING(klass)->ptr << ": "; + + // message + VALUE message = rb_obj_as_string(lasterr); + msg << RSTRING(message)->ptr << endl; + + // backtrace + if(!NIL_P(ruby_errinfo)) { + VALUE ary = rb_funcall(ruby_errinfo, rb_intern("backtrace"), 0); + int c; + for (c=0; c<RARRAY(ary)->len; c++) { + msg << "from " << RSTRING(RARRAY(ary)->ptr[c])->ptr << endl; + } + } + throwException(ServiceInvocationException, msg.str().c_str()); + } + + // Convert the Ruby result value to a C++ result + int resultType = TYPE(result); + char buf[20]; + switch(resultType) + { + case T_FLOAT: + { + float* data = new float; + *data = rb_num2dbl(result); + + // Check if the return type has already been set for typed languages + switch(operation.getReturnType()) + { + case Operation::BOOL: + { + *(bool*)operation.getReturnValue() = (*data != 0.0); + break; + } + case Operation::SHORT: + { + *(short*)operation.getReturnValue() = (short)*data; + break; + } + case Operation::USHORT: + { + *(unsigned short*)operation.getReturnValue() = (unsigned short)*data; + break; + } + case Operation::INT: + { + *(int*)operation.getReturnValue() = (int)*data; + break; + } + case Operation::UINT: + { + *(unsigned int*)operation.getReturnValue() = (unsigned int)*data; + break; + } + case Operation::LONG: + { + *(long*)operation.getReturnValue() = (long)*data; + break; + } + case Operation::ULONG: + { + *(unsigned long*)operation.getReturnValue() = (unsigned long)*data; + break; + } + case Operation::FLOAT: + { + *(float*)operation.getReturnValue() = (float)*data; + break; + } + case Operation::DOUBLE: + { + *(double*)operation.getReturnValue() = (double)*data; + break; + } + case Operation::LONGDOUBLE: + { + *(long double*)operation.getReturnValue() = (long double)*data; + break; + } + case Operation::CHARS: + { + sprintf(buf, "%f", *data); + *(char**)operation.getReturnValue() = buf; + break; + } + case Operation::STRING: + { + sprintf(buf, "%f", *data); + *(string*)operation.getReturnValue() = buf; + break; + } + default: + { + // The type is set as something else or has not been set + operation.setReturnValue(data); + } + } + break; + } + case T_STRING: + { + string* stringdata = new string(rb_string_value_cstr(&result)); + const char** data = new const char*; + *data = stringdata->c_str(); + + // Check if the return type has already been set (for typed languages) + switch(operation.getReturnType()) + { + case Operation::BOOL: + { + // If the string is empty or "0" or "false" set to false, otherwise true + if(strlen(*data) == 0 || strcmp(*data, "0") == 0 || strcmp(*data, "false") == 0) + { + *(bool*)operation.getReturnValue() = false; + } + else + { + *(bool*)operation.getReturnValue() = true; + } + break; + } + case Operation::SHORT: + { + *(short*)operation.getReturnValue() = (short)atoi(*data); + break; + } + case Operation::USHORT: + { + *(unsigned short*)operation.getReturnValue() = (unsigned short)atoi(*data); + break; + } + case Operation::INT: + { + *(int*)operation.getReturnValue() = (int)atoi(*data); + break; + } + case Operation::UINT: + { + *(unsigned int*)operation.getReturnValue() = (unsigned int)atoi(*data); + break; + } + case Operation::LONG: + { + *(long*)operation.getReturnValue() = (long)atol(*data); + break; + } + case Operation::ULONG: + { + *(unsigned long*)operation.getReturnValue() = (unsigned long)atol(*data); + break; + } + case Operation::FLOAT: + { + *(float*)operation.getReturnValue() = (float)atof(*data); + break; + } + case Operation::DOUBLE: + { + *(double*)operation.getReturnValue() = (double)atof(*data); + break; + } + case Operation::LONGDOUBLE: + { + *(long double*)operation.getReturnValue() = (long double)atof(*data); + break; + } + case Operation::CHARS: + { + *(const char**)operation.getReturnValue() = *data; + break; + } + case Operation::STRING: + { + *(string*)operation.getReturnValue() = *data; + break; + } + default: + { + // The type is set as something else or has not been set + operation.setReturnValue(data); + } + } + break; + } + case T_FIXNUM: + { + long* data = new long; + *data = rb_num2long(result); + + // Check if the return type has already been (set for typed languages) + switch(operation.getReturnType()) + { + case Operation::BOOL: + { + *(bool*)operation.getReturnValue() = (*data != 0); + break; + } + case Operation::SHORT: + { + *(short*)operation.getReturnValue() = (short)*data; + break; + } + case Operation::USHORT: + { + *(unsigned short*)operation.getReturnValue() = (unsigned short)*data; + break; + } + case Operation::INT: + { + *(int*)operation.getReturnValue() = (int)*data; + break; + } + case Operation::UINT: + { + *(unsigned int*)operation.getReturnValue() = (unsigned int)*data; + break; + } + case Operation::LONG: + { + *(long*)operation.getReturnValue() = (long)*data; + break; + } + case Operation::ULONG: + { + *(unsigned long*)operation.getReturnValue() = (unsigned long)*data; + break; + } + case Operation::FLOAT: + { + *(float*)operation.getReturnValue() = (float)*data; + break; + } + case Operation::DOUBLE: + { + *(double*)operation.getReturnValue() = (double)*data; + break; + } + case Operation::LONGDOUBLE: + { + *(long double*)operation.getReturnValue() = (long double)*data; + break; + } + case Operation::CHARS: + { + sprintf(buf, "%d", *data); + *(char**)operation.getReturnValue() = buf; + break; + } + case Operation::STRING: + { + sprintf(buf, "%d", *data); + *(string*)operation.getReturnValue() = buf; + break; + } + default: + { + // The type is set as something else or has not been set + operation.setReturnValue(data); + } + } + + break; + } + case T_BIGNUM: + { + long double* data = new long double; + *data = rb_num2dbl(result); + + // Check if the return type has already been set (for typed languages) + switch(operation.getReturnType()) + { + case Operation::BOOL: + { + *(bool*)operation.getReturnValue() = (*data != 0.0); + break; + } + case Operation::SHORT: + { + *(short*)operation.getReturnValue() = (short)*data; + break; + } + case Operation::USHORT: + { + *(unsigned short*)operation.getReturnValue() = (unsigned short)*data; + break; + } + case Operation::INT: + { + *(int*)operation.getReturnValue() = (int)*data; + break; + } + case Operation::UINT: + { + *(unsigned int*)operation.getReturnValue() = (unsigned int)*data; + break; + } + case Operation::LONG: + { + *(long*)operation.getReturnValue() = (long)*data; + break; + } + case Operation::ULONG: + { + *(unsigned long*)operation.getReturnValue() = (unsigned long)*data; + break; + } + case Operation::FLOAT: + { + *(float*)operation.getReturnValue() = (float)*data; + break; + } + case Operation::DOUBLE: + { + *(double*)operation.getReturnValue() = (double)*data; + break; + } + case Operation::LONGDOUBLE: + { + *(long double*)operation.getReturnValue() = (long double)*data; + break; + } + case Operation::CHARS: + { + sprintf(buf, "%f", *data); + *(char**)operation.getReturnValue() = buf; + break; + } + case Operation::STRING: + { + sprintf(buf, "%f", *data); + *(string*)operation.getReturnValue() = buf; + break; + } + default: + { + // The type is set as something else or has not been set + operation.setReturnValue(data); + } + } + break; + } + case T_TRUE: + case T_FALSE: + { + bool* data = new bool; + *data = (resultType == T_TRUE); + // Check if the return type has already been set (for typed languages) + switch(operation.getReturnType()) + { + case Operation::BOOL: + { + *(bool*)operation.getReturnValue() = *data; + break; + } + case Operation::SHORT: + { + *(short*)operation.getReturnValue() = (short)*data; + break; + } + case Operation::USHORT: + { + *(unsigned short*)operation.getReturnValue() = (unsigned short)*data; + break; + } + case Operation::INT: + { + *(int*)operation.getReturnValue() = (int)*data; + break; + } + case Operation::UINT: + { + *(unsigned int*)operation.getReturnValue() = (unsigned int)*data; + break; + } + case Operation::LONG: + { + *(long*)operation.getReturnValue() = (long)*data; + break; + } + case Operation::ULONG: + { + *(unsigned long*)operation.getReturnValue() = (unsigned long)*data; + break; + } + case Operation::FLOAT: + { + *(float*)operation.getReturnValue() = (float)*data; + break; + } + case Operation::DOUBLE: + { + *(double*)operation.getReturnValue() = (double)*data; + break; + } + case Operation::LONGDOUBLE: + { + *(long double*)operation.getReturnValue() = (long double)*data; + break; + } + case Operation::CHARS: + { + if(*data) + { + *(char**)operation.getReturnValue() = "true"; + } + else + { + *(char**)operation.getReturnValue() = "false"; + } + break; + } + case Operation::STRING: + { + if(*data) + { + *(string*)operation.getReturnValue() = "true"; + } + else + { + *(string*)operation.getReturnValue() = "false"; + } + break; + } + default: + { + // The type is set as something else or has not been set + operation.setReturnValue(data); + } + } + + break; + } + case T_OBJECT: + { + VALUE klass = rb_obj_class(result); + if (klass == RubyImplementation::getXMLDocumentClass()) + { + // Convert a REXML::Document to a DataObject + ID to_s = rb_intern("to_s"); + VALUE vstr = rb_funcall(result, to_s, 0); + string str = string(rb_string_value_cstr(&vstr)); + + loginfo("Converting Ruby Rexml document to SDO DataObject: %s", str.c_str()); + + Composite* composite = component->getComposite(); + commonj::sdo::XMLHelperPtr xmlHelper = composite->getXMLHelper(); + commonj::sdo::XMLDocumentPtr xmlDoc = xmlHelper->load(str.c_str()); + + DataObjectPtr* dataObjectData = new DataObjectPtr; + if (xmlDoc != NULL) + { + *dataObjectData = xmlDoc->getRootDataObject(); + } + else + { + *dataObjectData = NULL; + } + if (*dataObjectData != NULL) + { + operation.setReturnValue(dataObjectData); + } + else + { + string msg = "Document could not be converted to a DataObject"; + throwException(ServiceDataException, msg.c_str()); + } + } + else + { + string msg = "Ruby type not supported: " + resultType; + throwException(ServiceDataException, msg.c_str()); + } + break; + } + default: + { + string msg = "Ruby type not supported: " + resultType; + throwException(ServiceDataException, msg.c_str()); + } + } + + } + catch (...) + { + runtime->unsetCurrentComponent(); + throw; + } + + runtime->unsetCurrentComponent(); + } + + } // End namespace ruby + } // End namespace sca +} // End namespace tuscany diff --git a/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceWrapper.h b/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceWrapper.h new file mode 100644 index 0000000000..2526084a72 --- /dev/null +++ b/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceWrapper.h @@ -0,0 +1,94 @@ +/* + * 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_ruby_rubyservicewrapper_h +#define tuscany_sca_ruby_rubyservicewrapper_h + +#include "tuscany/sca/ruby/export.h" +#include "tuscany/sca/ruby/Ruby.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/ruby/model/RubyImplementation.h" + + +namespace tuscany +{ + namespace sca + { + namespace ruby + { + class RubyInterface; + + /** + * 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_RUBY_API RubyServiceWrapper : public ServiceWrapper + { + public: + + /** + * Constructor. + * @param target The component service to which this wrapper refers. + */ + RubyServiceWrapper(tuscany::sca::model::Service* service); + + /** + * Destructor. + */ + virtual ~RubyServiceWrapper(); + + /** + * 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); + + private: + + /** + * 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 Ruby implementation + */ + RubyImplementation* implementation; + + }; + + } // End namespace ruby + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_ruby_rubyservicewrapper_h diff --git a/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/export.h b/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/export.h new file mode 100644 index 0000000000..5db72a1ebe --- /dev/null +++ b/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/export.h @@ -0,0 +1,38 @@ +/* + * 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_ruby_export_h +#define tuscany_sca_ruby_export_h + +#if defined(WIN32) || defined (_WINDOWS) +#pragma warning(disable: 4786) + +#ifdef TUSCANY_SCA_RUBY_LANG_EXPORTS +#define SCA_RUBY_API __declspec(dllexport) +#else +#define SCA_RUBY_API __declspec(dllimport) +#endif + +#else +#define SCA_RUBY_API +#endif + +#endif // tuscany_sca_ruby_export_h diff --git a/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyImplementation.cpp b/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyImplementation.cpp new file mode 100644 index 0000000000..fa30642318 --- /dev/null +++ b/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyImplementation.cpp @@ -0,0 +1,171 @@ +/* + * 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/ruby/model/RubyImplementation.h" +#include "tuscany/sca/ruby/model/RubyServiceBinding.h" +#include "tuscany/sca/ruby/model/RubyReferenceBinding.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/model/Reference.h" +#include "tuscany/sca/model/ReferenceType.h" +#include "tuscany/sca/util/Utils.h" + +using namespace std; +using namespace tuscany::sca::model; + +namespace tuscany +{ + namespace sca + { + + namespace ruby + { + + bool RubyImplementation::initialized = false; + VALUE RubyImplementation::xmlDocumentClass = 0; + + // Constructor + RubyImplementation::RubyImplementation(Composite* composite, const string& module, const string& className, const string& script) + : ComponentType(composite, script.substr(0, script.find_last_of('.'))), + module(module), className(className), script(script) + { + loadClass(); + } + + RubyImplementation::~RubyImplementation() + { + } + + VALUE RubyImplementation::getXMLDocumentClass() + { + logentry(); + + // Initialize the Ruby runtime + if (!initialized) + { + ruby_init(); + ruby_init_loadpath(); + + // Load the Rexml module. Rexml is used to handle XML documents. + //rb_require("rexml/document"); + // Use rb_eval_string for now as it provides better error reporting + rb_eval_string("require(\"rexml/document\")"); + + xmlDocumentClass = rb_path2class("REXML::Document"); + initialized = true; + } + + return xmlDocumentClass; + } + + void RubyImplementation::loadClass() + { + logentry(); + + // Ensure xmlDocumentClass is initialized + getXMLDocumentClass(); + + ID to_s = rb_intern("to_s"); + VALUE xstr = rb_funcall(xmlDocumentClass, to_s, 0); + loginfo("Got Ruby Rexml class: %s", rb_string_value_cstr(&xstr)); + + // Load the specified Ruby script + if (script != "") + { + // Convert any windows slashes \ in the root path to unix slashes / + string rootpath = getComposite()->getRoot(); + int pos = 0; + while((pos = rootpath.find('\\', pos)) != string::npos) + { + rootpath = rootpath.replace(pos, 1, "/"); + } + + // Use rb_eval_string for now as it provides better error reporting + string path = "require(\"" + rootpath + "/" + script +"\")"; + //rb_require((char *)path.c_str()); + rb_eval_string(path.c_str()); + } + + // Load the Ruby implementation class + implementationClass = rb_path2class(className.c_str()); + + // Create a default service + ServiceType* defaultServiceType = new ServiceType(this, "", NULL, NULL); + addServiceType(defaultServiceType); + + // Introspect the Ruby class and create references and properties for + // all public attributes + VALUE methods = rb_class_public_instance_methods(0, NULL, implementationClass); + int n = RARRAY(methods)->len; + for (int i = 0; i<n; i++) + { + VALUE method = rb_ary_entry(methods, i); + string methodName = string(rb_string_value_cstr(&method)); + + // Create a reference type for each setter method + int s = methodName.size(); + if (s > 1 && methodName[s-1] == '=' && methodName[0] != '=') + { + string variableName = methodName.substr(0, s-1); + ReferenceType* referenceType = new ReferenceType( + this, variableName, NULL, NULL, ReferenceType::ONE_ONE); + addReferenceType(referenceType); + + // Create a property type as well + addPropertyType(variableName, "http://www.w3.org/2001/XMLSchema#string", false, NULL); + + } + } + } + + void RubyImplementation::initializeComponent(Component* component) + { + ComponentType::initializeComponent(component); + + // Create Ruby bindings for all the services + const Component::SERVICE_MAP& services = component->getServices(); + Component::SERVICE_MAP::const_iterator iter = services.begin(); + for (int i=0; i< services.size(); i++) + { + Service *service = iter->second; + RubyServiceBinding* binding = new RubyServiceBinding(service); + service->setBinding(binding); + iter++; + } + + // Create Ruby bindings for all the references + const Component::REFERENCE_MAP& references = component->getReferences(); + Component::REFERENCE_MAP::const_iterator refiter = references.begin(); + for (int ri=0; ri< references.size(); ri++) + { + Reference *reference = refiter->second; + RubyReferenceBinding* binding = new RubyReferenceBinding(reference); + reference->setBinding(binding); + refiter++; + } + } + + } // End namespace ruby + } // End namespace sca +} // End namespace tuscany diff --git a/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyImplementation.h b/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyImplementation.h new file mode 100644 index 0000000000..c7bc851635 --- /dev/null +++ b/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyImplementation.h @@ -0,0 +1,136 @@ +/* + * 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_ruby_model_rubyimplementation_h +#define tuscany_sca_ruby_model_rubyimplementation_h + +#include <string> + +#include "tuscany/sca/ruby/Ruby.h" +#include "tuscany/sca/model/ComponentType.h" + +namespace tuscany +{ + namespace sca + { + namespace ruby + { + /** + * Holds information about an SCA implementation written in Ruby + */ + class RubyImplementation : public tuscany::sca::model::ComponentType + { + + public: + /** + * Constructor. + * @param composite The composite containing this implementation. + * @param module Name of the Ruby module. + * @param className Name of the Ruby implementation class. + * @param script Path of the Ruby script. + */ + RubyImplementation(tuscany::sca::model::Composite* composite, + const std::string& module, const std::string& className, const std::string& script); + + /** + * Destructor + */ + virtual ~RubyImplementation(); + + /** + * 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 Ruby module. + * @return The name of the Ruby module. + */ + const std::string& getModule() const { return module; } + + /** + * Returns the name of Ruby class. + * @return Name of the Ruby class. + */ + const std::string& getClass() const { return className; } + + /** + * Returns the path of the Ruby script. + * @return The path of the Ruby script. + */ + const std::string& getScript() const { return script; } + + /** + * Returns the Ruby implementation class + */ + VALUE getImplementationClass() const { return implementationClass; } + + /** + * Returns the Ruby REXML::Document class + */ + static VALUE getXMLDocumentClass(); + + private: + + /** + * Load the Ruby implementation class + */ + void loadClass(); + + /** + * Name of the Ruby module. + */ + std::string module; + + /** + * Name of the Ruby class. + */ + std::string className; + + /** + * Path of the Ruby script. + */ + std::string script; + + /** + * The Ruby implementation class + */ + VALUE implementationClass; + + /** + * True if the Ruby runtime has been initialized + */ + static bool initialized; + + /** + * The Ruby REXML::Document class. + */ + static VALUE xmlDocumentClass; + + }; + + } // End namespace ruby + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_ruby_model_rubyimplementation_h diff --git a/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyReferenceBinding.cpp b/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyReferenceBinding.cpp new file mode 100644 index 0000000000..3187c07973 --- /dev/null +++ b/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyReferenceBinding.cpp @@ -0,0 +1,60 @@ +/* + * 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/ruby/model/RubyReferenceBinding.h" +#include "tuscany/sca/ruby/RubyServiceProxy.h" + +using namespace tuscany::sca::model; + +namespace tuscany +{ + namespace sca + { + namespace ruby + { + + // Constructor + RubyReferenceBinding::RubyReferenceBinding(Reference* reference) + : ReferenceBinding(reference, ""), serviceProxy(NULL) + { + } + + // Destructor + RubyReferenceBinding::~RubyReferenceBinding() + { + } + + ServiceProxy* RubyReferenceBinding::getServiceProxy() + { + return serviceProxy; + } + + void RubyReferenceBinding::configure(ServiceBinding* binding) + { + setTargetServiceBinding(binding); + + serviceProxy = new RubyServiceProxy(getReference()); + } + + } // End namespace ruby + } // End namespace sca +} // End namespace tuscany diff --git a/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyReferenceBinding.h b/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyReferenceBinding.h new file mode 100644 index 0000000000..72d39b5639 --- /dev/null +++ b/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyReferenceBinding.h @@ -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$ */ + + +#ifndef tuscany_sca_ruby_model_rubyreferencebinding_h +#define tuscany_sca_ruby_model_rubyreferencebinding_h + +#include <string> + +#include "tuscany/sca/model/ReferenceBinding.h" + + +namespace tuscany +{ + namespace sca + { + namespace ruby + { + /** + * Information about a Ruby service binding for service or a reference. + */ + class RubyReferenceBinding : public tuscany::sca::model::ReferenceBinding + { + public: + + /** + * Constructor. + */ + RubyReferenceBinding(tuscany::sca::model::Reference* reference); + + /** + * Destructor. + */ + virtual ~RubyReferenceBinding(); + + /** + * Returns the type of binding. + */ + virtual std::string getType() { return "http://www.osoa.org/xmlns/sca/1.0#RubyImplementationBinding"; }; + + /** + * 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); + + private: + + /** + * The proxy representing the reference to the client + * component. + */ + ServiceProxy* serviceProxy; + }; + + } // End namespace ruby + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_ruby_model_rubyreferencebinding_h diff --git a/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyServiceBinding.cpp b/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyServiceBinding.cpp new file mode 100644 index 0000000000..163f8a9d8b --- /dev/null +++ b/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyServiceBinding.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/ruby/model/RubyServiceBinding.h" +#include "tuscany/sca/ruby/RubyServiceWrapper.h" + +using namespace tuscany::sca::model; + +namespace tuscany +{ + namespace sca + { + namespace ruby + { + + // Constructor + RubyServiceBinding::RubyServiceBinding(Service* service) + : ServiceBinding(service, "") + { + serviceWrapper = new RubyServiceWrapper(service); + } + + // Destructor + RubyServiceBinding::~RubyServiceBinding() + { + } + + ServiceWrapper* RubyServiceBinding::getServiceWrapper() + { + return (ServiceWrapper*)serviceWrapper; + } + + } // End namespace ws + } // End namespace sca +} // End namespace tuscany diff --git a/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyServiceBinding.h b/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyServiceBinding.h new file mode 100644 index 0000000000..b772daf712 --- /dev/null +++ b/cpp/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyServiceBinding.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_ruby_model_rubyservicebinding_h +#define tuscany_sca_ruby_model_rubyservicebinding_h + +#include <string> + +#include "tuscany/sca/model/ServiceBinding.h" + +namespace tuscany +{ + namespace sca + { + namespace ruby + { + /** + * Information about a Ruby service binding for service or a reference. + */ + class RubyServiceBinding : public tuscany::sca::model::ServiceBinding + { + public: + + /** + * Constructor. + */ + RubyServiceBinding(tuscany::sca::model::Service* service); + + /** + * Destructor. + */ + virtual ~RubyServiceBinding(); + + /** + * Returns the type of binding. + */ + virtual std::string getType() { return "http://www.osoa.org/xmlns/sca/1.0#RubyImplementationBinding"; }; + + /** + * 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 ruby + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_ruby_model_rubyservicebinding_h diff --git a/cpp/sca/runtime/extensions/ruby/xsd/sca-implementation-ruby.xsd b/cpp/sca/runtime/extensions/ruby/xsd/sca-implementation-ruby.xsd new file mode 100644 index 0000000000..5772019a4f --- /dev/null +++ b/cpp/sca/runtime/extensions/ruby/xsd/sca-implementation-ruby.xsd @@ -0,0 +1,42 @@ +<?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"> + + <include schemaLocation="../../../xsd/sca-core.xsd"/> + + <element name="implementation.ruby" type="sca:RubyImplementation" substitutionGroup="sca:implementation"/> + <complexType name="RubyImplementation"> + <complexContent> + <extension base="sca:Implementation"> + <sequence> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" /> + </sequence> + <attribute name="script" type="NCName" use="optional"/> + <attribute name="module" type="NCName" use="optional"/> + <attribute name="class" type="Name" use="optional"/> + <anyAttribute namespace="##any" processContents="lax"/> + </extension> + </complexContent> + </complexType> +</schema> |