From 84adefa331c4159d432d22840663c38f155cd4c1 Mon Sep 17 00:00:00 2001 From: Erlang/OTP Date: Fri, 20 Nov 2009 14:54:40 +0000 Subject: The R13B03 release. --- lib/orber/examples/Makefile | 41 +++++++ lib/orber/examples/Stack/InitialReferences.idl | 12 ++ lib/orber/examples/Stack/Makefile | 121 +++++++++++++++++++++ lib/orber/examples/Stack/StackClient.cc | 96 ++++++++++++++++ lib/orber/examples/Stack/StackClient.java | 72 ++++++++++++ .../Stack/StackModule_StackFactory_impl.erl | 40 +++++++ .../examples/Stack/StackModule_Stack_impl.erl | 46 ++++++++ lib/orber/examples/Stack/stack.idl | 27 +++++ lib/orber/examples/Stack/stack_client.erl | 55 ++++++++++ lib/orber/examples/Stack/stack_factory.erl | 37 +++++++ 10 files changed, 547 insertions(+) create mode 100644 lib/orber/examples/Makefile create mode 100644 lib/orber/examples/Stack/InitialReferences.idl create mode 100644 lib/orber/examples/Stack/Makefile create mode 100644 lib/orber/examples/Stack/StackClient.cc create mode 100644 lib/orber/examples/Stack/StackClient.java create mode 100644 lib/orber/examples/Stack/StackModule_StackFactory_impl.erl create mode 100644 lib/orber/examples/Stack/StackModule_Stack_impl.erl create mode 100644 lib/orber/examples/Stack/stack.idl create mode 100644 lib/orber/examples/Stack/stack_client.erl create mode 100644 lib/orber/examples/Stack/stack_factory.erl (limited to 'lib/orber/examples') diff --git a/lib/orber/examples/Makefile b/lib/orber/examples/Makefile new file mode 100644 index 0000000000..5b8e06bd37 --- /dev/null +++ b/lib/orber/examples/Makefile @@ -0,0 +1,41 @@ +# +# %CopyrightBegin% +# +# Copyright Ericsson AB 1997-2009. All Rights Reserved. +# +# The contents of this file are subject to the Erlang Public License, +# Version 1.1, (the "License"); you may not use this file except in +# compliance with the License. You should have received a copy of the +# Erlang Public License along with this software. If not, it can be +# retrieved online at http://www.erlang.org/. +# +# Software distributed under the License is distributed on an "AS IS" +# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +# the License for the specific language governing rights and limitations +# under the License. +# +# %CopyrightEnd% +# +# +include $(ERL_TOP)/make/target.mk +include $(ERL_TOP)/make/$(TARGET)/otp.mk + +# ---------------------------------------------------- +# Application version +# ---------------------------------------------------- +include ../vsn.mk +VSN=$(ORBER_VSN) + +# ---------------------------------------------------- +# Common Macros +# ---------------------------------------------------- + +SUB_DIRECTORIES = Stack + +SPECIAL_TARGETS = + +# ---------------------------------------------------- +# Default Subdir Targets +# ---------------------------------------------------- +include $(ERL_TOP)/make/otp_subdir.mk + diff --git a/lib/orber/examples/Stack/InitialReferences.idl b/lib/orber/examples/Stack/InitialReferences.idl new file mode 100644 index 0000000000..7c1dddc7c4 --- /dev/null +++ b/lib/orber/examples/Stack/InitialReferences.idl @@ -0,0 +1,12 @@ +typedef string ObjectId; +typedef sequence ObjectIdList; + +module Orber { +interface InitialReferences { + + Object get(in ObjectId id); + + ObjectIdList list(); + +}; +}; diff --git a/lib/orber/examples/Stack/Makefile b/lib/orber/examples/Stack/Makefile new file mode 100644 index 0000000000..6e7f292a04 --- /dev/null +++ b/lib/orber/examples/Stack/Makefile @@ -0,0 +1,121 @@ +# +# %CopyrightBegin% +# +# Copyright Ericsson AB 1997-2009. All Rights Reserved. +# +# The contents of this file are subject to the Erlang Public License, +# Version 1.1, (the "License"); you may not use this file except in +# compliance with the License. You should have received a copy of the +# Erlang Public License along with this software. If not, it can be +# retrieved online at http://www.erlang.org/. +# +# Software distributed under the License is distributed on an "AS IS" +# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +# the License for the specific language governing rights and limitations +# under the License. +# +# %CopyrightEnd% +# +# +include $(ERL_TOP)/make/target.mk + +EBIN= ../../ebin + +include $(ERL_TOP)/make/$(TARGET)/otp.mk + +# ---------------------------------------------------- +# Application version +# ---------------------------------------------------- +include ../../vsn.mk +VSN=$(ORBER_VSN) + +# ---------------------------------------------------- +# Release directory specification +# ---------------------------------------------------- +RELSYSDIR = $(RELEASE_PATH)/lib/orber-$(VSN) + +# ---------------------------------------------------- +# Target Specs +# ---------------------------------------------------- + +IDL_FILES = \ + stack.idl \ + InitialReferences.idl + +GEN_ERL_MODULES = \ + oe_stack \ + StackModule_Stack \ + StackModule_StackFactory \ + StackModule_EmptyStack + +MODULES= \ + StackModule_Stack_impl \ + StackModule_StackFactory_impl \ + stack_factory \ + stack_client + +GEN_HRL_FILES = \ + oe_stack.hrl \ + StackModule.hrl \ + StackModule_Stack.hrl \ + StackModule_StackFactory.hrl + +HRL_FILES= + +ERL_FILES= $(MODULES:%=%.erl) + +JAVA_CLASSES = \ + StackClient + +JAVA_FILES= $(JAVA_CLASSES:%=%.java) +CLASS_FILES= $(JAVA_CLASSES:%=%.class) + +TARGET_FILES = \ + $(GEN_ERL_MODULES:%=$(EBIN)/%.$(EMULATOR)) \ + $(MODULES:%=$(EBIN)/%.$(EMULATOR)) + +TEST_TARGET_FILES = + +CPP_FILES = StackClient.cc + +# ---------------------------------------------------- +# FLAGS +# ---------------------------------------------------- +ERL_IDL_FLAGS += -pa $(ERL_TOP)/lib/orber/ebin -pa $(ERL_TOP)/lib/ic/ebin +# The -pa option is just used temporary until erlc can handle +# includes from other directories than ../include . +ERL_COMPILE_FLAGS += \ + $(ERL_IDL_FLAGS) \ + -pa $(ERL_TOP)/lib/orber -I$(ERL_TOP)/lib/orber + +# ---------------------------------------------------- +# Targets +# ---------------------------------------------------- +debug opt: $(TARGET_FILES) + +clean: + rm -f $(TARGET_FILES) $(GEN_ERL_MODULES:%=%.erl) $(GEN_HRL_FILES) $(CLASS_FILES) + rm -f errs core *~ + +docs: + +test: $(TEST_TARGET_FILES) + + +$(GEN_ERL_MODULES:%=%.erl) $(GEN_HRL_FILES): stack.idl + erlc $(ERL_IDL_FLAGS) stack.idl + +# ---------------------------------------------------- +# Release Target +# ---------------------------------------------------- +include $(ERL_TOP)/make/otp_release_targets.mk + + +release_spec: opt + $(INSTALL_DIR) $(RELSYSDIR)/examples/Stack + $(INSTALL_DATA) $(ERL_FILES) $(JAVA_FILES) $(CPP_FILES) $(IDL_FILES) $(RELSYSDIR)/examples/Stack + + +release_docs_spec: + + diff --git a/lib/orber/examples/Stack/StackClient.cc b/lib/orber/examples/Stack/StackClient.cc new file mode 100644 index 0000000000..30ed85fa58 --- /dev/null +++ b/lib/orber/examples/Stack/StackClient.cc @@ -0,0 +1,96 @@ +/** + * + * 2000-2007 + * Ericsson AB, All Rights Reserved + * + * + * The contents of this file are subject to the Erlang Public License, + * Version 1.1, (the "License"); you may not use this file except in + * compliance with the License. You should have received a copy of the + * Erlang Public License along with this software. If not, it can be + * retrieved online at http://www.erlang.org/. + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Initial Developer of the Original Code is Ericsson AB. + * + */ +/** + * This module gives an example how it is possible to setup a connection + * Orbix3.0.1 and Orber3.0.2 + */ + + +#define USE_IIOP + +#include +#include +#include +#include + +#include "NamingService.hh" +#include "InitialReference.hh" +#include "InitialReferences.hh" +#include "stack.hh" + + +int main(int argc, char** argv) { + + CORBA::Object_ptr nsRef, initRef, objRef; + InitialReference init; + Orber::InitialReferences_var initp; + CosNaming::NamingContext_var Ns; + CosNaming::NameComponent nc; + CosNaming::Name_var name; + StackModule::StackFactory_var stackFac; + StackModule::Stack_var stack; + + if (argc < 3) { + cout << "usage: " << argv[0] << " " << " " << endl; + exit (-1); + } + + string srvHost = argv[1]; + long srvPort = atoi(argv[2]); + + cout << "Using host: " << srvHost << " Port: " << srvPort << endl; + + try + { + // Create Initial reference (objectkey "INIT"). + const string s = init.stringified_ior(srvHost, srvPort); + initRef = CORBA::Orbix.string_to_object(s); + initp = Orber::InitialReferences::_narrow(initRef); + nsRef = initp->get("NameService"); + Ns = CosNaming::NamingContext::_narrow(nsRef); + + // Create a name component. + name = new CosNaming::Name(1); + name->length(1); + name[0].id = CORBA::string_dup("StackFactory"); + name[0].kind = CORBA::string_dup(""); + + // Look up the Object in the NamingService. + objRef = Ns->resolve(name); + stackFac = StackModule::StackFactory::_narrow(objRef); + stack = stackFac->create_stack(); + + // push & pop + stack->push(8); + stack->push(7); + stack->push(6); + cout << "Stack: " << stack->pop() + << " " << stack->pop() + << " " << stack->pop() << endl; + + } catch(...) { + cerr << "call failed" << endl; + cerr << "Unexpected exception " << endl; + exit(1); + } + cout << "Completed successfully" << endl; + return 0; +} diff --git a/lib/orber/examples/Stack/StackClient.java b/lib/orber/examples/Stack/StackClient.java new file mode 100644 index 0000000000..4e8c0176a8 --- /dev/null +++ b/lib/orber/examples/Stack/StackClient.java @@ -0,0 +1,72 @@ +/* + * %CopyrightBegin% + * + * Copyright Ericsson AB 1997-2009. All Rights Reserved. + * + * The contents of this file are subject to the Erlang Public License, + * Version 1.1, (the "License"); you may not use this file except in + * compliance with the License. You should have received a copy of the + * Erlang Public License along with this software. If not, it can be + * retrieved online at http://www.erlang.org/. + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * %CopyrightEnd% + * + */ +/* + * Stack example. + */ + +package StackModule; +import org.omg.CORBA.*; +import org.omg.CORBA.SystemException; +import org.omg.CORBA.ORB.*; + +public class StackClient +{ + public static void main(String args[]) + { + org.omg.CORBA.Object objRef; + StackFactory sfRef = null; + Stack sRef = null; + // The argument can look like + // "corbaname::host:4001/#StackFactory" + String corbaName = new String(args[0]); + try{ + ORB orb = ORB.init(args, null); + + objRef = orb.string_to_object(corbaName); + sfRef = StackFactoryHelper.narrow(objRef); + sRef = sfRef.create_stack(); + + sRef.push(4); + sRef.push(7); + sRef.push(1); + sRef.push(1); + + try{ + System.out.println(sRef.pop()); + System.out.println(sRef.pop()); + System.out.println(sRef.pop()); + System.out.println(sRef.pop()); + // The following operation shall + // return an EmptyStack exception + System.out.println(sRef.pop()); + } + catch(EmptyStack es) { + System.out.println("Empty stack"); + }; + + sfRef.destroy_stack(sRef); + } + catch(SystemException se) + { + System.out.println("Unexpected exception: " + se.toString()); + return; + } + } +} diff --git a/lib/orber/examples/Stack/StackModule_StackFactory_impl.erl b/lib/orber/examples/Stack/StackModule_StackFactory_impl.erl new file mode 100644 index 0000000000..e283b6f765 --- /dev/null +++ b/lib/orber/examples/Stack/StackModule_StackFactory_impl.erl @@ -0,0 +1,40 @@ +%%-------------------------------------------------------------------- +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 1997-2009. All Rights Reserved. +%% +%% The contents of this file are subject to the Erlang Public License, +%% Version 1.1, (the "License"); you may not use this file except in +%% compliance with the License. You should have received a copy of the +%% Erlang Public License along with this software. If not, it can be +%% retrieved online at http://www.erlang.org/. +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and limitations +%% under the License. +%% +%% %CopyrightEnd% +%% +%% +%%----------------------------------------------------------------- +%% StackModule_StackFactory_impl example file. + +-module('StackModule_StackFactory_impl'). +-include_lib("orber/include/corba.hrl"). +-export([create_stack/1, destroy_stack/2, init/1, terminate/2]). + + +init(_Env) -> + {ok, []}. + +terminate(_From, _Reason) -> + ok. + +create_stack(State) -> + %% Just a create we don't want a link. + {reply, 'StackModule_Stack':oe_create(), State}. + +destroy_stack(State, Stack) -> + {reply, corba:dispose(Stack), State}. diff --git a/lib/orber/examples/Stack/StackModule_Stack_impl.erl b/lib/orber/examples/Stack/StackModule_Stack_impl.erl new file mode 100644 index 0000000000..87b5e8a275 --- /dev/null +++ b/lib/orber/examples/Stack/StackModule_Stack_impl.erl @@ -0,0 +1,46 @@ +%%-------------------------------------------------------------------- +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 1997-2009. All Rights Reserved. +%% +%% The contents of this file are subject to the Erlang Public License, +%% Version 1.1, (the "License"); you may not use this file except in +%% compliance with the License. You should have received a copy of the +%% Erlang Public License along with this software. If not, it can be +%% retrieved online at http://www.erlang.org/. +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and limitations +%% under the License. +%% +%% %CopyrightEnd% +%% +%% +%%----------------------------------------------------------------- +%% StackModule_Stack_impl example file. + +-module('StackModule_Stack_impl'). +-include_lib("orber/include/corba.hrl"). +-include("StackModule.hrl"). +-export([pop/1, push/2, empty/1, init/1, terminate/2]). + + +init(_Env) -> + {ok, []}. + +terminate(_From, _Reason) -> + ok. + +push(Stack, Val) -> + {reply, ok, [Val | Stack]}. + +pop([Val | Stack]) -> + {reply, Val, Stack}; +pop([]) -> + corba:raise(#'StackModule_EmptyStack'{}). + +empty(_) -> + {reply, ok, []}. + diff --git a/lib/orber/examples/Stack/stack.idl b/lib/orber/examples/Stack/stack.idl new file mode 100644 index 0000000000..f21f93917b --- /dev/null +++ b/lib/orber/examples/Stack/stack.idl @@ -0,0 +1,27 @@ +#ifndef _STACK_IDL +#define _STACK_IDL + +module StackModule { + + exception EmptyStack {}; + + interface Stack { + + long pop() raises(StackModule::EmptyStack); + + void push(in long value); + + void empty(); + + }; + + interface StackFactory { + + StackModule::Stack create_stack(); + void destroy_stack(in StackModule::Stack s); + + }; + +}; + +#endif diff --git a/lib/orber/examples/Stack/stack_client.erl b/lib/orber/examples/Stack/stack_client.erl new file mode 100644 index 0000000000..c90af33ff8 --- /dev/null +++ b/lib/orber/examples/Stack/stack_client.erl @@ -0,0 +1,55 @@ +%%-------------------------------------------------------------------- +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 1997-2009. All Rights Reserved. +%% +%% The contents of this file are subject to the Erlang Public License, +%% Version 1.1, (the "License"); you may not use this file except in +%% compliance with the License. You should have received a copy of the +%% Erlang Public License along with this software. If not, it can be +%% retrieved online at http://www.erlang.org/. +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and limitations +%% under the License. +%% +%% %CopyrightEnd% +%% +%% +%%----------------------------------------------------------------- +%% stack_client example file. + +-module('stack_client'). + +-export([run/0]). + + +run() -> + case catch corba:string_to_object("corbaname:rir:/NameService#StackFactory") of + {'EXCEPTION', _E} -> + io:format("The stack factory server is not registered~n",[]); + SF -> + %% Create the stack + SS = 'StackModule_StackFactory':create_stack(SF), + + 'StackModule_Stack':push(SS, 4), + 'StackModule_Stack':push(SS, 7), + 'StackModule_Stack':push(SS, 1), + 'StackModule_Stack':push(SS, 1), + Res = 'StackModule_Stack':pop(SS), + io:format("~w~n", [Res]), + Res1 = 'StackModule_Stack':pop(SS), + io:format("~w~n", [Res1]), + Res2 = 'StackModule_Stack':pop(SS), + io:format("~w~n", [Res2]), + Res3 = 'StackModule_Stack':pop(SS), + io:format("~w~n", [Res3]), + + %% Remove the stack + 'StackModule_StackFactory':destroy_stack(SF, SS) + + end. + + diff --git a/lib/orber/examples/Stack/stack_factory.erl b/lib/orber/examples/Stack/stack_factory.erl new file mode 100644 index 0000000000..2f09b18fc4 --- /dev/null +++ b/lib/orber/examples/Stack/stack_factory.erl @@ -0,0 +1,37 @@ +%%-------------------------------------------------------------------- +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 1997-2009. All Rights Reserved. +%% +%% The contents of this file are subject to the Erlang Public License, +%% Version 1.1, (the "License"); you may not use this file except in +%% compliance with the License. You should have received a copy of the +%% Erlang Public License along with this software. If not, it can be +%% retrieved online at http://www.erlang.org/. +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and limitations +%% under the License. +%% +%% %CopyrightEnd% +%% +%% +%%----------------------------------------------------------------- +%% stack_factory example file. + +-module('stack_factory'). +-include_lib("orber/include/corba.hrl"). +-include_lib("orber/COSS/CosNaming/CosNaming.hrl"). +-include_lib("orber/COSS/CosNaming/lname.hrl"). + +-export([start/0]). + +start() -> + SFok = 'StackModule_StackFactory':oe_create(), + NS = corba:resolve_initial_references("NameService"), + NC = lname_component:set_id(lname_component:create(), "StackFactory"), + N = lname:insert_component(lname:create(), 1, NC), + 'CosNaming_NamingContext':bind(NS, N, SFok). + -- cgit v1.2.3