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/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src |
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/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src')
20 files changed, 2433 insertions, 0 deletions
diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/Makefile.am b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/Makefile.am new file mode 100644 index 0000000000..d73ac1f90c --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/Makefile.am @@ -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. + +libdir=$(prefix)/extensions/ruby/lib +lib_LTLIBRARIES = libtuscany_sca_ruby.la + +install-exec-hook: + cd $(libdir); \ + ln -s -f libtuscany_sca_ruby.so tuscany_sca_ruby.so; \ + for i in libtuscany_sca_ruby.*; do mv $$i $$i.disabled; done + +rootdir=$(prefix)/extensions/ruby +root_SCRIPTS = deploy.sh + +noinst_HEADERS = \ +tuscany/sca/ruby/*.h \ +tuscany/sca/ruby/model/*.h + +EXTRA_DIST = deploy.sh + +libtuscany_sca_ruby_la_SOURCES = \ +tuscany/sca/ruby/RubyExtension.cpp \ +tuscany/sca/ruby/RubyImplementationExtension.cpp \ +tuscany/sca/ruby/RubyServiceProxy.cpp \ +tuscany/sca/ruby/RubyServiceWrapper.cpp \ +tuscany/sca/ruby/model/RubyImplementation.cpp \ +tuscany/sca/ruby/model/RubyReferenceBinding.cpp \ +tuscany/sca/ruby/model/RubyServiceBinding.cpp \ +tuscany/sca/ruby/RubyCompositeContext.cpp + +libtuscany_sca_ruby_la_LIBADD = -L${TUSCANY_SDOCPP}/lib -ltuscany_sdo \ + -L$(top_builddir)/runtime/core/src -ltuscany_sca \ + -L${RUBY_LIB} -lruby + +INCLUDES = -Imodel -I$(top_builddir)/runtime/core/src \ + -I${TUSCANY_SDOCPP}/include \ + -I${RUBY_INCLUDE} + +AM_CPPFLAGS = $(CPPFLAGS) -D_DEBUG +
\ No newline at end of file diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/deploy.cmd b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/deploy.cmd new file mode 100644 index 0000000000..5baf8289e3 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/deploy.cmd @@ -0,0 +1,28 @@ +@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
+set currentPath=%~d0%~p0
+
+echo Enabling the Tuscany Ruby extension
+rename %currentPath%\bin\tuscany_sca_ruby.dll.disabled tuscany_sca_ruby.dll
+
+:end
+echo Done
+endlocal
diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/deploy.sh b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/deploy.sh new file mode 100755 index 0000000000..492b1b09d1 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/deploy.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +# 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. + +APFULLDIR=`pwd` + +echo "Enabling the Tuscany Ruby extension" + +for i in lib/*.disabled; do x=${i%.disabled}; mv $i $x; done + +echo "Done" diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/Ruby.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/Ruby.h new file mode 100644 index 0000000000..a6b8ee8ffa --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/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/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyCompositeContext.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyCompositeContext.cpp new file mode 100644 index 0000000000..148bccc025 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyCompositeContext.cpp @@ -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$ */ + + +#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" + +using namespace tuscany::sca::ruby; + +extern "C" +{ + + // Implement the Sca::locateService module function + SCA_RUBY_API VALUE tuscany_sca_ruby_locateService(VALUE module, VALUE value) + { + + // Get the default component + Component* defaultComponent = tuscany::sca::SCARuntime::getInstance()->getDefaultComponent(); + Composite* composite = (Composite*)defaultComponent->getType(); + + // Locate the service + const char* serviceName = rb_string_value_cstr(&value); + 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 + RubyServiceProxy* serviceProxy = new RubyServiceProxy(service); + + // Return the Ruby proxy value object + return serviceProxy->getProxyValue(); + } + + // Initialize the Ruby extension + SCA_RUBY_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_RUBY_API void Init_libtuscany_sca_ruby() + { + Init_tuscany_sca_ruby(); + } +} diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyExtension.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyExtension.cpp new file mode 100644 index 0000000000..7153ef4fb1 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/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" + + +extern "C" +{ + #if defined(WIN32) || defined(_WINDOWS) + __declspec(dllexport) + #endif + void tuscany_sca_extension_initialize() + { + tuscany::sca::ruby::RubyExtension::initialize(); + } +} + +namespace tuscany +{ + namespace sca + { + namespace ruby + { + // =================================================================== + // Constructor for the RubyExtension class. + // =================================================================== + RubyExtension::RubyExtension() + { + LOGENTRY(1, "RubyExtension::constructor"); + LOGEXIT(1, "RubyExtension::constructor"); + } + + // =================================================================== + // Destructor for the RubyExtension class. + // =================================================================== + RubyExtension::~RubyExtension() + { + LOGENTRY(1, "RubyExtension::destructor");; + LOGEXIT(1, "RubyExtension::destructor"); + } + + void RubyExtension::initialize() + { + LOGENTRY(1, "RubyExtension::initialize");; + SCARuntime::getInstance()->registerImplementationExtension(new RubyImplementationExtension()); + LOGEXIT(1, "RubyExtension::initialize");; + } + + } // End namespace ruby + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyExtension.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyExtension.h new file mode 100644 index 0000000000..232431ca1e --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/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/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyImplementationExtension.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyImplementationExtension.cpp new file mode 100644 index 0000000000..2bc5f9d0d9 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyImplementationExtension.cpp @@ -0,0 +1,79 @@ +/* + * 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" + + +namespace tuscany +{ + namespace sca + { + namespace ruby + { + // =================================================================== + // Constructor for the RubyImplementationExtension class. + // =================================================================== + RubyImplementationExtension::RubyImplementationExtension() + { + LOGENTRY(1, "RubyImplementationExtension::constructor"); + LOGEXIT(1, "RubyImplementationExtension::constructor"); + } + + // =================================================================== + // Destructor for the RubyImplementationExtension class. + // =================================================================== + RubyImplementationExtension::~RubyImplementationExtension() + { + LOGENTRY(1, "RubyImplementationExtension::destructor");; + LOGEXIT(1, "RubyImplementationExtension::destructor"); + } + + 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) + { + string implType = scdlImplementation->getType().getName(); + if (implType == "RubyImplementation") + { + 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; + } + else + { + return NULL; + } + } + + } // End namespace ruby + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyImplementationExtension.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyImplementationExtension.h new file mode 100644 index 0000000000..a1c5f26a3e --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyImplementationExtension.h @@ -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$ */ + +#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 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 string& getExtensionTypeQName() {return typeQName;} + + virtual ComponentType* getImplementation(Composite* composite, DataObjectPtr scdlImplementation); + + private: + static const string extensionName; + static const string typeQName; + + }; + + + } // End namespace ruby + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_ruby_rubyimplementationextension_h + diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceProxy.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceProxy.cpp new file mode 100644 index 0000000000..228f1f8940 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceProxy.cpp @@ -0,0 +1,374 @@ +/* + * 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/RubyServiceProxy.h" +#include "tuscany/sca/util/Logging.h" +#include "tuscany/sca/core/SCARuntime.h" +#include "tuscany/sca/util/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" + +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(1,"RubyServiceProxy::constructor"); + + // ---------------------- + // 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(); + + LOGEXIT(1,"RubyServiceProxy::constructor"); + } + + // ============================ + // Constructor: Create a proxy + // ============================ + RubyServiceProxy::RubyServiceProxy(Service* service) + : ServiceProxy(0) + { + LOGENTRY(1,"RubyServiceProxy::constructor"); + + // ---------------------- + // Get the component + // ---------------------- + component = service->getComponent(); + string name = service->getType()->getName(); + + // Get the service wrapper + serviceWrapper = service->getBinding()->getServiceWrapper(); + + // Create the Ruby proxy + createProxy(); + + LOGEXIT(1,"RubyServiceProxy::constructor"); + } + + // ========== + // Destructor + // ========== + RubyServiceProxy::~RubyServiceProxy() + { + LOGENTRY(1,"RubyServiceProxy::destructor"); + LOGEXIT(1,"RubyServiceProxy::destructor"); + } + + void RubyServiceProxy::createProxy() + { + // 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) + { + // 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)); + + Composite* composite = getReference()->getComponent()->getComposite(); + commonj::sdo::XMLHelper* xmlHelper = composite->getXMLHelper(); + commonj::sdo::XMLDocumentPtr xmlDoc = xmlHelper->load(str.c_str()); + + DataObjectPtr dob; + if (xmlDoc != NULL) + { + dob = xmlDoc->getRootDataObject(); + } + if (dob != NULL) + { + operation.addParameter(&dob); + } + 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::XMLHelper* xmlHelper = composite->getXMLHelper(); + char* str = xmlHelper->save( + dob, + dob->getType().getURI(), + dob->getType().getName()); + VALUE vstr[1]; + vstr[0] = rb_str_new2(str); + + value = rb_class_new_instance(1, vstr, RubyImplementation::getXMLDocumentClass()); + break; + } + default: + { + //throw new ComponentInvocationException("Operation parameter type not supported"); + string msg = "Operation parameter type not supported" + resultType; + rb_raise(rb_eRuntimeError, msg.c_str()); + return Qnil; + } + } + + 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/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceProxy.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceProxy.h new file mode 100644 index 0000000000..f4692733f1 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceProxy.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_ruby_rubyserviceproxy_h +#define tuscany_sca_ruby_rubyserviceproxy_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" + +using namespace tuscany::sca::model; + +#include "tuscany/sca/ruby/Ruby.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(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(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 + */ + 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/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceWrapper.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceWrapper.cpp new file mode 100644 index 0000000000..a0eb97142d --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceWrapper.cpp @@ -0,0 +1,724 @@ +/* + * 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/RubyServiceWrapper.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/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" +#include "commonj/sdo/SDO.h" + +using commonj::sdo::PropertyList; + +namespace tuscany +{ + namespace sca + { + namespace ruby + { + + // =========== + // Constructor + // =========== + RubyServiceWrapper::RubyServiceWrapper(Service* service) + : ServiceWrapper(service) + { + LOGENTRY(1,"RubyServiceWrapper::constructor"); + + component = service->getComponent(); + implementation = (RubyImplementation*)component->getType(); + interf = service->getType()->getInterface(); + + LOGEXIT(1,"RubyServiceWrapper::constructor"); + + } + + // ========== + // Destructor + // ========== + RubyServiceWrapper::~RubyServiceWrapper() + { + LOGENTRY(1,"RubyServiceWrapper::destructor"); + LOGEXIT(1,"RubyServiceWrapper::destructor"); + } + + // ====================================================================== + // invoke: wrapper call to service with setting the component context + // ====================================================================== + void RubyServiceWrapper::invoke(Operation& operation) + { + LOGENTRY(1,"RubyServiceWrapper::invoke"); + + SCARuntime* runtime = SCARuntime::getInstance(); + 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::XMLHelper* xmlHelper = composite->getXMLHelper(); + char* str = xmlHelper->save( + dob, + dob->getType().getURI(), + dob->getType().getName()); + VALUE vstr[1]; + vstr[0] = rb_str_new2(str); + + value = rb_class_new_instance(1, vstr, RubyImplementation::getXMLDocumentClass()); + break; + } + default: + { + //throw new ComponentInvocationException("Operation parameter type not supported"); + string msg = "Operation parameter type not supported" + parmType; + throw msg.c_str(); + } + } + + args[i] = value; + } + } + + + // Invoke the specified method + VALUE result; + if (n == 0) + { + result = rb_funcall(instance, method, 0); + } + else + { + result = rb_funcall2(instance, method, n, args); + } + + // 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)); + + Composite* composite = component->getComposite(); + commonj::sdo::XMLHelper* xmlHelper = composite->getXMLHelper(); + commonj::sdo::XMLDocumentPtr xmlDoc = xmlHelper->load(str.c_str()); + + DataObjectPtr dob; + if (xmlDoc != NULL) + { + dob = xmlDoc->getRootDataObject(); + } + if (dob != NULL) + { + operation.setReturnValue(&dob); + } + else + { + string msg = "Document could not be converted to a DataObject"; + throw msg.c_str(); + } + } + else + { + string msg = "Ruby type not supported: " + resultType; + throw msg.c_str(); + } + break; + } + default: + { + string msg = "Ruby type not supported: " + resultType; + throw msg.c_str(); + } + } + + } + catch (...) + { + runtime->unsetCurrentComponent(); + throw; + } + runtime->unsetCurrentComponent(); + LOGEXIT(1,"RubyServiceWrapper::invoke"); + + } + + } // End namespace ruby + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceWrapper.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceWrapper.h new file mode 100644 index 0000000000..849bbdd33e --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/RubyServiceWrapper.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_ruby_rubyservicewrapper_h +#define tuscany_sca_ruby_rubyservicewrapper_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" +#include "tuscany/sca/ruby/export.h" + +#include "tuscany/sca/ruby/Ruby.h" + +using namespace tuscany::sca::model; + +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(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. + */ + Component* component; + + /** + * A pointer to the interface which the service exposes. + */ + 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/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/export.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/export.h new file mode 100644 index 0000000000..21f09dddfc --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/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_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/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyImplementation.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyImplementation.cpp new file mode 100644 index 0000000000..877b98e7b4 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyImplementation.cpp @@ -0,0 +1,154 @@ +/* + * 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" + +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() + { + } + + void RubyImplementation::loadClass() + { + // 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; + } + + // Load the specified Ruby script + if (script != "") + { + // Convert any windows slashes \ in the root path to unix slashes / + // otherwise the ruby interpreter throws an error + 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/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyImplementation.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyImplementation.h new file mode 100644 index 0000000000..32b5801f42 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyImplementation.h @@ -0,0 +1,140 @@ +/* + * 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 "tuscany/sca/model/ComponentType.h" + +#include <map> +using std::map; +#include <string> +using std::string; + +#include "tuscany/sca/ruby/Ruby.h" + +using namespace tuscany::sca::model; + +namespace tuscany +{ + namespace sca + { + namespace ruby + { + /** + * Holds information about an SCA implementation written in Ruby + */ + class RubyImplementation : public 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(Composite* composite, const string& module, const string& className, const string& script); + + /** + * Destructor + */ + virtual ~RubyImplementation(); + + /** + * Initialize a component of this type. + * @param component The component to initialize. + */ + virtual void initializeComponent(Component* component); + + /** + * Returns the name of the Ruby module. + * @return The name of the Ruby module. + */ + const string& getModule() const { return module; } + + /** + * Returns the name of Ruby class. + * @return Name of the Ruby class. + */ + const string& getClass() const { return className; } + + /** + * Returns the path of the Ruby script. + * @return The path of the Ruby script. + */ + const string& getScript() const { return script; } + + /** + * Returns the Ruby implementation class + */ + VALUE getImplementationClass() const { return implementationClass; } + + /** + * Returns the Ruby REXML::Document class + */ + static VALUE getXMLDocumentClass() { return xmlDocumentClass; } + + private: + + /** + * Load the Ruby implementation class + */ + void loadClass(); + + /** + * Name of the Ruby module. + */ + string module; + + /** + * Name of the Ruby class. + */ + string className; + + /** + * Path of the Ruby script. + */ + 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/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyReferenceBinding.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyReferenceBinding.cpp new file mode 100644 index 0000000000..0e813983f2 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyReferenceBinding.cpp @@ -0,0 +1,59 @@ +/* + * 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" + + +namespace tuscany +{ + namespace sca + { + namespace ruby + { + + // Constructor + RubyReferenceBinding::RubyReferenceBinding(Reference* reference) + : ReferenceBinding(reference, ""), serviceProxy(NULL), targetServiceBinding(NULL) + { + } + + // Destructor + RubyReferenceBinding::~RubyReferenceBinding() + { + } + + ServiceProxy* RubyReferenceBinding::getServiceProxy() + { + return serviceProxy; + } + + void RubyReferenceBinding::configure(ServiceBinding* binding) + { + targetServiceBinding = binding; + + serviceProxy = new RubyServiceProxy(getReference()); + } + + } // End namespace ruby + } // End namespace sca +} // End namespace tuscany diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyReferenceBinding.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyReferenceBinding.h new file mode 100644 index 0000000000..cab1c22c48 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyReferenceBinding.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_ruby_model_rubyreferencebinding_h +#define tuscany_sca_ruby_model_rubyreferencebinding_h + +#include "tuscany/sca/model/ReferenceBinding.h" + + +#include <string> +using std::string; + +using namespace tuscany::sca::model; + +namespace tuscany +{ + namespace sca + { + namespace ruby + { + /** + * Information about a Ruby service binding for service or a reference. + */ + class RubyReferenceBinding : public ReferenceBinding + { + public: + + /** + * Constructor. + */ + RubyReferenceBinding(Reference* reference); + + /** + * Destructor. + */ + virtual ~RubyReferenceBinding(); + + /** + * Returns the type of binding. + */ + virtual 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(ServiceBinding* serviceBinding); + + /** + * Returns the target service binding. + */ + ServiceBinding* getTargetServiceBinding() const { return targetServiceBinding; }; + + private: + + /** + * The proxy representing the reference to the client + * component. + */ + ServiceProxy* serviceProxy; + + /** + * The service binding of the target + */ + ServiceBinding* targetServiceBinding; + }; + + } // End namespace ruby + } // End namespace sca +} // End namespace tuscany + +#endif // tuscany_sca_ruby_model_rubyreferencebinding_h diff --git a/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyServiceBinding.cpp b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyServiceBinding.cpp new file mode 100644 index 0000000000..376a4db0f7 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyServiceBinding.cpp @@ -0,0 +1,52 @@ +/* + * 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" + +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/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyServiceBinding.h b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyServiceBinding.h new file mode 100644 index 0000000000..24c0275bb9 --- /dev/null +++ b/tags/cpp-1.0-incubating-M2-RC3/sca/runtime/extensions/ruby/src/tuscany/sca/ruby/model/RubyServiceBinding.h @@ -0,0 +1,78 @@ +/* + * 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 "tuscany/sca/model/ServiceBinding.h" +using namespace tuscany::sca::model; +#include <string> +using std::string; + +namespace tuscany +{ + namespace sca + { + namespace ruby + { + /** + * Information about a Ruby service binding for service or a reference. + */ + class RubyServiceBinding : public ServiceBinding + { + public: + + /** + * Constructor. + */ + RubyServiceBinding(Service* service); + + /** + * Destructor. + */ + virtual ~RubyServiceBinding(); + + /** + * Returns the type of binding. + */ + virtual 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 |