aboutsummaryrefslogtreecommitdiffstats
path: root/lib/orber/examples
diff options
context:
space:
mode:
authorErlang/OTP <[email protected]>2009-11-20 14:54:40 +0000
committerErlang/OTP <[email protected]>2009-11-20 14:54:40 +0000
commit84adefa331c4159d432d22840663c38f155cd4c1 (patch)
treebff9a9c66adda4df2106dfd0e5c053ab182a12bd /lib/orber/examples
downloadotp-84adefa331c4159d432d22840663c38f155cd4c1.tar.gz
otp-84adefa331c4159d432d22840663c38f155cd4c1.tar.bz2
otp-84adefa331c4159d432d22840663c38f155cd4c1.zip
The R13B03 release.OTP_R13B03
Diffstat (limited to 'lib/orber/examples')
-rw-r--r--lib/orber/examples/Makefile41
-rw-r--r--lib/orber/examples/Stack/InitialReferences.idl12
-rw-r--r--lib/orber/examples/Stack/Makefile121
-rw-r--r--lib/orber/examples/Stack/StackClient.cc96
-rw-r--r--lib/orber/examples/Stack/StackClient.java72
-rw-r--r--lib/orber/examples/Stack/StackModule_StackFactory_impl.erl40
-rw-r--r--lib/orber/examples/Stack/StackModule_Stack_impl.erl46
-rw-r--r--lib/orber/examples/Stack/stack.idl27
-rw-r--r--lib/orber/examples/Stack/stack_client.erl55
-rw-r--r--lib/orber/examples/Stack/stack_factory.erl37
10 files changed, 547 insertions, 0 deletions
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 <ObjectId> 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 @@
+/**
+ * <copyright>
+ * <year>2000-2007</year>
+ * <holder>Ericsson AB, All Rights Reserved</holder>
+ *</copyright>
+ *<legalnotice>
+ * 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.
+ *</legalnotice>
+ */
+/**
+ * This module gives an example how it is possible to setup a connection
+ * Orbix3.0.1 and Orber3.0.2
+ */
+
+
+#define USE_IIOP
+
+#include <iostream.h>
+#include <stdio.h>
+#include <fstream.h>
+#include <stdlib.h>
+
+#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] << " <hostname>" << " <srvport>" << 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).
+