aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ic/examples/all-against-all
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/ic/examples/all-against-all
downloadotp-84adefa331c4159d432d22840663c38f155cd4c1.tar.gz
otp-84adefa331c4159d432d22840663c38f155cd4c1.tar.bz2
otp-84adefa331c4159d432d22840663c38f155cd4c1.zip
The R13B03 release.OTP_R13B03
Diffstat (limited to 'lib/ic/examples/all-against-all')
-rw-r--r--lib/ic/examples/all-against-all/Makefile117
-rw-r--r--lib/ic/examples/all-against-all/Makefile.win32138
-rw-r--r--lib/ic/examples/all-against-all/ReadMe122
-rw-r--r--lib/ic/examples/all-against-all/callbacks.c45
-rw-r--r--lib/ic/examples/all-against-all/client.c153
-rw-r--r--lib/ic/examples/all-against-all/client.erl53
-rw-r--r--lib/ic/examples/all-against-all/client.java60
-rw-r--r--lib/ic/examples/all-against-all/random.idl50
-rw-r--r--lib/ic/examples/all-against-all/rmod_random_impl.erl48
-rw-r--r--lib/ic/examples/all-against-all/server.c261
-rw-r--r--lib/ic/examples/all-against-all/server.erl40
-rw-r--r--lib/ic/examples/all-against-all/server.java82
-rw-r--r--lib/ic/examples/all-against-all/serverImpl.java42
13 files changed, 1211 insertions, 0 deletions
diff --git a/lib/ic/examples/all-against-all/Makefile b/lib/ic/examples/all-against-all/Makefile
new file mode 100644
index 0000000000..a71099ef72
--- /dev/null
+++ b/lib/ic/examples/all-against-all/Makefile
@@ -0,0 +1,117 @@
+#
+# %CopyrightBegin%
+#
+# Copyright Ericsson AB 1999-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%
+#
+#
+# Point this at your version of OTP
+OTPROOT=/usr/local/otp/releases/otp_beam_sunos5_r7a
+
+# Type actual IC Version
+ICVSN=4.0.4
+
+# Type actual Erl Interface Vesrion
+EIVSN=3.2.2
+
+# Type actual Erl Interface Vesrion
+JIVSN=1.2
+
+# IDL file(s)
+IDLS=random.idl
+
+# Own C-server files
+CSRV=server callbacks
+
+# Own C-client files
+CCL=client
+
+# Generated C-server files
+GCSRVS=rmod_random__s
+
+# Generated C-server files
+GCCLS=rmod_random
+
+# Includes
+IFLAGS=-I$(OTPROOT)/lib/ic-$(ICVSN)/include \
+ -I$(OTPROOT)/lib/erl_interface-$(EIVSN)/include
+
+LDFLAGS=-L$(OTPROOT)/lib/ic-$(ICVSN)/priv/lib \
+ -L$(OTPROOT)/lib/erl_interface-$(EIVSN)/lib
+
+LDLIBS=-lic -lerl_interface -lei -lnsl -lsocket
+
+
+# Erlang compiler
+ERLC=$(OTPROOT)/bin/erlc
+
+# Erlang compiler flags.
+EFLAGS='+{scoped_op_calls,true}'
+
+# C compiler
+CC=gcc
+
+# C compiler flags
+CFLAGS=-ggdb -O2 -Wall $(IFLAGS)
+
+# Java compiler
+JAVAC=javac
+
+CLASSPATH= "./:$(OTPROOT)/lib/ic-$(ICVSN)/priv/ic.jar:$(OTPROOT)/lib/jinterface-$(JIVSN)/priv/OtpErlang.jar"
+JFLAGS=-classpath $(CLASSPATH) -O
+
+JGENJFILES = \
+ ./rmod/_randomImplBase.java \
+ ./rmod/random.java \
+ ./rmod/randomHolder.java \
+ ./rmod/_randomStub.java \
+ ./rmod/randomHelper.java
+
+
+all: server client eall jall
+
+
+server:
+ $(ERLC) $(EFLAGS) '+{be,c_server}' $(IDLS)
+ $(CC) $(IFLAGS) -c $(CSRV:=.c) $(GCSRVS:=.c)
+ $(CC) $(CSRV:=.o) $(GCSRVS:=.o) -o $@ $(LDFLAGS) $(LDLIBS)
+
+client:
+ $(ERLC) $(EFLAGS) '+{be,c_client}' $(IDLS)
+ $(CC) $(IFLAGS) -c $(CCL:=.c) $(GCCLS:=.c)
+ $(CC) $(CCL:=.o) $(GCCLS:=.o) -o $@ $(LDFLAGS) $(LDLIBS)
+
+eall:
+ $(ERLC) $(EFLAGS) '+{be,erl_genserv}' $(IDLS)
+ $(ERLC) *.erl
+
+jall:
+ $(ERLC) $(EFLAGS) '+{be,java}' $(IDLS)
+ $(JAVAC) $(JFLAGS) */*.java *.java
+
+
+clean:
+ /bin/rm -rf $(GCCLS:=.o) $(GCCLS:=.c) $(GCSRVS:=.o) $(GCSRVS:=.c) $(CCL:=.o) $(CSRV:=.o) rmod.erl rmod_random.erl *.jam *.beam oe* *.h *.hrl *~ core server client *.class
+
+
+
+
+
+
+
+
+
+
+
diff --git a/lib/ic/examples/all-against-all/Makefile.win32 b/lib/ic/examples/all-against-all/Makefile.win32
new file mode 100644
index 0000000000..0085a85aad
--- /dev/null
+++ b/lib/ic/examples/all-against-all/Makefile.win32
@@ -0,0 +1,138 @@
+#
+# %CopyrightBegin%
+#
+# Copyright Ericsson AB 2000-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%
+#
+#
+# Point this at your version of OTP
+OTPROOT=c:\Progra~1\erl5.0.1\
+
+# Type actual IC Version
+ICVSN=4.0.4
+
+# Type actual Erl Interface Vesrion
+EIVSN=3.2.2
+
+# Type actual Erl Interface Vesrion
+JIVSN=1.2
+
+# IDL file(s)
+IDLS=random.idl
+
+# Own C-server files
+CSRV=server.c callbacks.c
+CSRVO=server.obj callbacks.obj
+
+# Own C-client files
+CCL=client.c
+CCLO=client.obj
+
+# Generated C-server files
+GCSRVS=rmod_random__s.c
+GCSRVSO=rmod_random__s.obj
+
+# Generated C-client files
+GCCLS=rmod_random.c
+GCCLSO=rmod_random.obj
+
+# Includes
+IFLAGS=-I"$(OTPROOT)\lib\ic-$(ICVSN)\include" \
+ -I"$(OTPROOT)\lib\erl_interface-$(EIVSN)\include"
+
+LDFLAGS=/LIBPATH:"$(OTPROOT)\lib\ic-$(ICVSN)\priv\lib" \
+ /LIBPATH:"$(OTPROOT)\lib\erl_interface-$(EIVSN)\lib"
+
+LDLIBS=ic.lib erl_interface.lib ei.lib ws2_32.lib
+
+
+# Erlang compiler
+ERLC=$(OTPROOT)\bin\erlc
+
+# Erlang compiler flags.
+EFLAGS="+{scoped_op_calls,true}"
+
+
+# C compiler
+CC=cl
+
+# C compiler flags
+CFLAGS=-MT -D__WIN32__ $(IFLAGS)
+
+
+# Java compiler
+JAVAC=c:\Progra~1\jdk1.3\bin\javac
+
+# Java
+JAVA=c:\Progra~1\jdk1.3\bin\java
+
+
+# Java compiler flags
+CLASSPATH= ".;$(OTPROOT)\lib\ic-$(ICVSN)\priv\ic.jar;$(OTPROOT)\lib\jinterface-$(JIVSN)\priv\OtpErlang.jar"
+JFLAGS=-classpath $(CLASSPATH) -O
+
+
+all: server.exe client.exe client.beam client.class
+
+
+server.exe:
+ $(ERLC) $(EFLAGS) "+{be,c_server}" $(IDLS)
+ $(CC) -c $(CFLAGS) $(CSRV) $(GCSRVS)
+ $(CC) -o server.exe $(CSRVO) $(GCSRVSO) -link $(LDFLAGS) $(LDLIBS)
+
+
+client.exe:
+ $(ERLC) $(EFLAGS) "+{be,c_client}" $(IDLS)
+ $(CC) -c $(CFLAGS) $(CCL) $(GCCLS)
+ $(CC) -o client.exe $(CCLO) $(GCCLSO) -link $(LDFLAGS) $(LDLIBS)
+
+client.beam:
+ $(ERLC) $(EFLAGS) "+{be,erl_genserv}" $(IDLS)
+ $(ERLC) *.erl
+
+client.class:
+ $(ERLC) $(EFLAGS) "+{be,java}" $(IDLS)
+ $(JAVAC) $(JFLAGS) rmod/*.java
+ $(JAVAC) $(JFLAGS) *.java
+
+jclient.run:
+ $(JAVA) -classpath $(CLASSPATH) client
+
+jserver.run:
+ $(JAVA) -classpath $(CLASSPATH) server
+
+
+clean:
+ -@del /f /q rmod
+ -@rmdir rmod
+ -@del *.jam
+ -@del *.beam
+ -@del oe*
+ -@del *.h
+ -@del *.hrl
+ -@del server.exe
+ -@del client.exe
+ -@del *.obj
+ -@del rmod_random*.c
+ -@del *~
+ -@del *class
+ -@del rmod.erl
+ -@del rmod_random.erl
+
+
+
+
+
+
diff --git a/lib/ic/examples/all-against-all/ReadMe b/lib/ic/examples/all-against-all/ReadMe
new file mode 100644
index 0000000000..7503291344
--- /dev/null
+++ b/lib/ic/examples/all-against-all/ReadMe
@@ -0,0 +1,122 @@
+This is a short description on the use of Erlang,C or Java
+client and servers against each other.
+The base is a client that initiates and uses a random number
+generator that lies on an server.
+
+There are two make files, one for Unix and one for Windows,
+the Unix make file is just named "Makefile", while the Windows
+is named "Makefile.win32".
+
+Instructions.
+
+1) On Makefile :
+ * Modify the OTPROOT variable on the Makefile to point
+ to the root for your erlang instalation.
+ * Modify IC and Erl_Interface versions to agree your
+ OTP version.
+
+2) Type "make" to build the example.
+
+
+3) Start the empd deamon by using the command :
+
+ epmd -daemon
+
+
+4) Do this when you want to run :
+
+ * an Erlang server.
+
+ Start erlang with the options
+
+ -setcookie <Some Cookie> -sname <SomeNodeName>
+
+ In this example you should use :
+
+ erl -setcookie flash -sname babbis
+
+ * a C server.
+
+ Just type :
+
+ server
+
+ * a Java server.
+
+ Set and export the CLASSPATH variable to
+ point to the java classes located in java development kit,
+ the Otp's classes and the current directory.
+ Your classpath should look like this :
+
+ .:<OTPROOT>/lib/ic-3.8.1/priv/ic.jar:<OTPROOT>/lib/jinterface_0.9.2/priv/OtpErlang.jar
+
+ where :
+
+ <OTPROOT> is the location there OTP is installed
+
+ Then type :
+
+ java server
+
+
+5) Do this when you want to run :
+
+ * an Erlang client.
+
+ ** If you have no valid named erlang node,
+ start erlang with the options
+
+ -setcookie <Some Cookie> -sname <SomeNodeName>
+
+ In this example you should use :
+
+ erl -setcookie flash -sname client
+
+ On the erlang shell, type
+
+ client:start().
+
+ ** If you have a valid named erlang node, started
+ whith the same "cookie", on the erlang shell, type
+
+ client:start().
+
+
+ * a C client, just type
+
+ client
+
+
+ * a Java client.
+
+
+ Set and export the CLASSPATH variable to
+ point to the java classes located in java development kit,
+ the Otp's classes and the current directory.
+ Your classpath should look like this :
+
+ .:<OTPROOT>/lib/ic-4.0/priv/ic.jar:<OTPROOT>/lib/jinterface_1.1/priv/OtpErlang.jar
+
+ where :
+
+ <OTPROOT> is the location there OTP is installed
+
+ Then type :
+
+ java client
+
+
+
+6) Please note that :
+
+ * you must always have the same cookie in order to eastablish connection
+ between clients and servers.
+
+ * you cannot start two servers with the same name.
+ In this example all servers share the same name in order to test
+ several constallations. Kill a server before starting another one.
+
+
+
+
+
diff --git a/lib/ic/examples/all-against-all/callbacks.c b/lib/ic/examples/all-against-all/callbacks.c
new file mode 100644
index 0000000000..f8642f4d2e
--- /dev/null
+++ b/lib/ic/examples/all-against-all/callbacks.c
@@ -0,0 +1,45 @@
+/*
+ * %CopyrightBegin%
+ *
+ * Copyright Ericsson AB 1999-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 <stdlib.h>
+#include "rmod_random__s.h"
+
+
+rmod_random_produce__rs*
+rmod_random_produce__cb(rmod_random oe_obj, double *rs, CORBA_Environment *oe_env)
+
+{
+ *rs = (double) rand();
+
+ return (rmod_random_produce__rs*) NULL;
+}
+
+
+rmod_random_init__rs*
+rmod_random_init__cb(rmod_random oe_obj, long* seed1, long* seed2, long* seed3, CORBA_Environment *oe_env)
+
+{
+ srand(*seed1 * *seed2 * *seed3);
+
+ return (rmod_random_init__rs*) NULL;
+}
+
+
+
diff --git a/lib/ic/examples/all-against-all/client.c b/lib/ic/examples/all-against-all/client.c
new file mode 100644
index 0000000000..e0a52b142d
--- /dev/null
+++ b/lib/ic/examples/all-against-all/client.c
@@ -0,0 +1,153 @@
+/*
+ * %CopyrightBegin%
+ *
+ * Copyright Ericsson AB 1999-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%
+ *
+ */
+
+/* Just include the interface function */
+#include "rmod_random.h"
+
+
+/* Assign your own node name here */
+#define CLNODENAME "c50"
+#define SNODENAME "babbis"
+#define SREGNAME "rmod_random_impl"
+#define COOKIE "flash"
+#define INBUFSZ 1024
+#define OUTBUFSZ 1024
+#define HOSTNAMESZ 256
+
+
+
+/* Stopping node */
+void client_exit(CORBA_Environment *env) {
+
+ /* Free env & buffers */
+ CORBA_free(env->_inbuf);
+ CORBA_free(env->_outbuf);
+ CORBA_free(env);
+
+ erl_close_connection(env->_fd);
+ exit(1);
+}
+
+
+int main(){
+
+ double result=0;
+ int i=0;
+ int error = 0;
+ erlang_pid pid;
+ char host[HOSTNAMESZ];
+ char server_node[HOSTNAMESZ];
+ char client_node[HOSTNAMESZ];
+ CORBA_Environment *env;
+
+ /* Initiate names */
+#ifdef __WIN32__
+ WORD wVersionRequested;
+ WSADATA wsaData;
+
+ wVersionRequested = MAKEWORD(1, 1);
+ if ((error = WSAStartup(wVersionRequested, &wsaData))) {
+ fprintf(stderr,"Can't initialize windows sockets: %d",error);
+ return 0;
+ }
+#endif
+ error = gethostname(host,HOSTNAMESZ);
+ if (error) {
+#ifdef __WIN32__
+ fprintf(stderr,"can't find own hostname (error = %ld) !\n",WSAGetLastError());
+#else /* not __WIN32__ */
+ fprintf(stderr,"can't find own hostname !\n");
+#endif
+ }
+ sprintf(client_node,"%s@%s",CLNODENAME,host);
+ sprintf(server_node,"%s@%s",SNODENAME,host);
+
+ /* Create and init CORBA_Environment */
+ env = CORBA_Environment_alloc(INBUFSZ,OUTBUFSZ);
+
+ /* Initiating the connection */
+ erl_init(NULL,0);
+ erl_connect_init(50,COOKIE,0);
+
+ /* Initiating pid*/
+ strcpy(pid.node,client_node);
+ pid.num = 99;
+ pid.serial = 0;
+ pid.creation = 0;
+
+ /* Fixing environment variable */
+ env->_fd=erl_connect(server_node);
+ strcpy(env->_regname,SREGNAME);
+ env->_to_pid = NULL;
+ env->_from_pid = &pid;
+
+ if (env->_fd < 0) {
+ fprintf(stderr,"Error : Cannot connect to Server\n");
+
+ /* Free env & buffers */
+ CORBA_free(env->_inbuf);
+ CORBA_free(env->_outbuf);
+ CORBA_free(env);
+ exit(1);
+ }
+
+ /* Calling the init function */
+ rmod_random_init(NULL, 1, 2, 3, env);
+
+ switch(env->_major) {
+ case CORBA_NO_EXCEPTION: /* Success */
+ printf("Init complete !\n");
+ break;
+ case CORBA_SYSTEM_EXCEPTION: /* System exception */
+ printf("Init call failure, reason : %s\n",(char *) CORBA_exception_value(env));
+ CORBA_exception_free(env);
+ client_exit(env);
+ default: /* Should not come here */
+ client_exit(env);
+ }
+
+ /* Calling the produce function */
+ for(i=1; i<=10; i++) {
+ result = rmod_random_produce(NULL, env);
+
+ switch(env->_major) {
+ case CORBA_NO_EXCEPTION: /* Success */
+ break;
+ case CORBA_SYSTEM_EXCEPTION: /* System exception */
+ printf("Init call failure, reason : %s\n",(char *) CORBA_exception_value(env));
+ CORBA_exception_free(env);
+ client_exit(env);
+ default: /* Should not come here */
+ client_exit(env);
+ }
+
+ printf("the random number nr%d is %f\n",i,result);
+ }
+
+ /* Closing the connection */
+ erl_close_connection(env->_fd);
+
+ /* Free env & buffers */
+ CORBA_free(env->_inbuf);
+ CORBA_free(env->_outbuf);
+ CORBA_free(env);
+
+ return 0;
+}
diff --git a/lib/ic/examples/all-against-all/client.erl b/lib/ic/examples/all-against-all/client.erl
new file mode 100644
index 0000000000..921c2c91ea
--- /dev/null
+++ b/lib/ic/examples/all-against-all/client.erl
@@ -0,0 +1,53 @@
+%%
+%% %CopyrightBegin%
+%%
+%% Copyright Ericsson AB 1999-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%
+%%
+%%
+%%----------------------------------------------------------------------
+%% File : client.erl
+%% Purpose :
+%%----------------------------------------------------------------------
+
+-module(client).
+
+-export([produce/0,init/3,call/0]).
+
+-define(SERVER,{rmod_random_impl,
+ list_to_atom("babbis@"++hd(tl(string:tokens(atom_to_list(node()),"@"))))}).
+-define(CLIENTMOD,'rmod_random').
+
+produce() ->
+ ?CLIENTMOD:produce(?SERVER).
+
+
+init(Seed1, Seed2, Seed3) ->
+ io:format("Init..."),
+ ?CLIENTMOD:init(?SERVER,Seed1, Seed2, Seed3),
+ io:format("ok\n").
+
+
+call() ->
+ init(1,2,3),
+ produce(0).
+
+
+produce(10) ->
+ ok;
+produce(Ctr) ->
+ N = produce(),
+ io:format("Random~p = ~p\n",[Ctr,N]),
+ produce(Ctr+1).
diff --git a/lib/ic/examples/all-against-all/client.java b/lib/ic/examples/all-against-all/client.java
new file mode 100644
index 0000000000..4dc88cffbb
--- /dev/null
+++ b/lib/ic/examples/all-against-all/client.java
@@ -0,0 +1,60 @@
+/*
+ * %CopyrightBegin%
+ *
+ * Copyright Ericsson AB 1999-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%
+ *
+ */
+public class client {
+
+ private static java.lang.String SNode = "client";
+ private static java.lang.String PNode = "babbis";
+ private static java.lang.String Cookie = "flash";
+ private static java.lang.String Server = "rmod_random_impl";
+
+ private static rmod._randomStub stub;
+
+ public static void main(String[] args) {
+
+ try {
+
+ stub = new rmod._randomStub(SNode,PNode,Cookie,Server);
+ int seed1 = 1;
+ int seed2 = 2;
+ int seed3 = 3;
+ double random = 0;
+
+ System.out.print("\nClient initialization....");
+ stub.init(seed1,seed2,seed3);
+ System.out.println("ok\n");
+
+
+ for (int i = 0; i < 10; i++) {
+ random = stub.produce();
+ System.out.println("Random" + i + " = " + random);
+ }
+ System.out.println("\nClient terminated.\n");
+
+ stub.__disconnect();
+
+ } catch( Exception e) {
+ System.out.println("Exception :");
+ e.printStackTrace();
+ }
+
+ }
+
+}
+
diff --git a/lib/ic/examples/all-against-all/random.idl b/lib/ic/examples/all-against-all/random.idl
new file mode 100644
index 0000000000..b44f7379f6
--- /dev/null
+++ b/lib/ic/examples/all-against-all/random.idl
@@ -0,0 +1,50 @@
+// ``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 via the world wide web 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 Utvecklings AB.
+// Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings
+// AB. All Rights Reserved.''
+//
+// $Id$
+//
+
+#ifndef _RANDOM_IDL
+#define _RANDOM_IDL
+
+module rmod {
+
+ interface random {
+
+ double produce();
+
+ oneway void init(in long seed1, in long seed2, in long seed3);
+
+ };
+
+};
+
+
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/lib/ic/examples/all-against-all/rmod_random_impl.erl b/lib/ic/examples/all-against-all/rmod_random_impl.erl
new file mode 100644
index 0000000000..8113cfb768
--- /dev/null
+++ b/lib/ic/examples/all-against-all/rmod_random_impl.erl
@@ -0,0 +1,48 @@
+%%
+%% %CopyrightBegin%
+%%
+%% Copyright Ericsson AB 2000-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%
+%%
+%%
+-module(rmod_random_impl).
+-export([init/1, terminate/2]).
+-export([produce/1,init/4]).
+
+
+init(Env) ->
+ {ok, []}.
+
+terminate(From, Reason) ->
+ ok.
+
+
+produce(_Random) ->
+ case catch random:uniform() of
+ {'EXIT',_} ->
+ true;
+ RUnif ->
+ {reply,RUnif,[]}
+ end.
+
+
+init(_Random,S1,S2,S3) ->
+ case catch random:seed(S1,S2,S3) of
+ {'EXIT',_} ->
+ true;
+ _ ->
+ {noreply,[]}
+ end.
+
diff --git a/lib/ic/examples/all-against-all/server.c b/lib/ic/examples/all-against-all/server.c
new file mode 100644
index 0000000000..be4953e9b9
--- /dev/null
+++ b/lib/ic/examples/all-against-all/server.c
@@ -0,0 +1,261 @@
+/*
+ * %CopyrightBegin%
+ *
+ * Copyright Ericsson AB 1999-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 <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <string.h>
+#ifdef __WIN32__
+#include <winsock2.h>
+#include <direct.h>
+#include <windows.h>
+#include <winbase.h>
+#else /* not __WIN32__ */
+#include <errno.h>
+#include <unistd.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#endif
+#include "rmod_random__s.h"
+
+/* Used functions */
+static int getport(int sockd);
+static int getlisten(int port);
+static int init(int *sd, int *portnr, int *epmd_fd);
+void terminate(int *fd, int *sd, int *epmd_fd);
+static void server_loop(int fd, int sd);
+
+/* change these, or even better, make command-line args to program... */
+#define COOKIE "flash"
+#define SERVER "babbis"
+#define NODENAMESZ 512
+#define HOSTNAMESZ 256
+#define INBUFSZ 1024
+#define OUTBUFSZ 1024
+
+
+int main(int argc, char **argv)
+{
+ int sd;
+ int portnr;
+ int epmd_fd;
+
+ /* crate file descriptors */
+ if (init(&sd, &portnr, &epmd_fd) < 0)
+ return -1;
+
+ /* start server loop */
+ server_loop(sd,epmd_fd);
+
+ return 0;
+}
+
+
+
+static void server_loop(int sd, int epmd_fd)
+{
+ ErlConnect conn;
+ erlang_msg msg;
+ int status=1;
+ CORBA_Environment *env;
+
+ /* Create and init CORBA_Environment */
+ env = CORBA_Environment_alloc(INBUFSZ,OUTBUFSZ);
+
+ while (status >= 0) {
+
+ status = 1;
+
+ if ((env->_fd = erl_accept(sd,&conn)) < 0) {
+ /* error */
+ fprintf(stderr,"Accept failed: %s\n",strerror(errno));
+ }
+ else {
+ /* connection */
+ fprintf(stderr,"Accepted connection from %s\n",conn.nodename);
+
+ while (status >= 0) {
+
+ /* write message to buffer */
+ status = ei_receive_encoded(env->_fd, &env->_inbuf, &env->_inbufsz, &msg, &env->_iin);
+ switch(status) {
+ case ERL_SEND:
+ case ERL_REG_SEND :
+ /* do transaction with fd */
+ rmod_random__switch(NULL,env);
+
+ switch(env->_major) {
+ case CORBA_NO_EXCEPTION: /* Success */
+ break;
+ case CORBA_SYSTEM_EXCEPTION: /* System exception */
+ printf("Request failure, reason : %s\n",(char *) CORBA_exception_value(env));
+ CORBA_exception_free(env);
+ break;
+ default: /* Should not come here */
+ CORBA_exception_free(env);
+ break;
+ }
+
+ /* send outdata */
+ if (env->_iout > 0)
+ ei_send_encoded(env->_fd,&env->_caller,env->_outbuf,env->_iout);
+ break;
+
+ case ERL_TICK :
+ break;
+ default : /* < 0 */
+ printf("Connection terminated\n");
+ break;
+ }
+ }
+ }
+ status=0; /* restart */
+ }
+
+ /* close file descriptors */
+ terminate(&env->_fd, &sd, &epmd_fd);
+
+ /* Free env & buffers */
+ CORBA_free(env->_inbuf);
+ CORBA_free(env->_outbuf);
+ CORBA_free(env);
+}
+
+
+
+static int init(int *sd, int *portnr, int *epmd_fd)
+{
+ char host[HOSTNAMESZ];
+ char servernode[NODENAMESZ];
+ struct hostent *h;
+ int error = 0;
+
+#ifdef __WIN32__
+ WORD wVersionRequested;
+ WSADATA wsaData;
+
+ wVersionRequested = MAKEWORD(1, 1);
+ if ((error = WSAStartup(wVersionRequested, &wsaData))) {
+ fprintf(stderr,"Can't initialize windows sockets: %d",error);
+ }
+#endif
+ /* get the host name */
+ error = gethostname(host,HOSTNAMESZ);
+ if (error) {
+#ifdef __WIN32__
+ fprintf(stderr,"can't find own hostname (error = %ld) !\n",WSAGetLastError());
+#else /* not __WIN32__ */
+ fprintf(stderr,"can't find own hostname !\n");
+#endif
+ }
+ else {
+ /* identify host */
+ if (!(h = erl_gethostbyname(host)))
+ fprintf(stdout,"can't find own ip address\n");
+ else {
+
+ /* get a listen port. 0 means let system choose port number */
+ *sd = getlisten(0);
+
+ /* what port did we get? */
+ /* this call not necessary if we specified port in call to getlisten() */
+ *portnr = getport(*sd);
+
+ /* make the nodename server@host */
+ sprintf(servernode,"%s@%s",SERVER,host);
+
+ /* initiate */
+ erl_init(NULL,0);
+
+ /* host, alive, alive@host, addr, cookie, creation */
+ erl_connect_xinit(host,SERVER,servernode,(Erl_IpAddr)(h->h_addr_list[0]),COOKIE,0);
+
+ /* let epmd know we are here */
+ *epmd_fd = erl_publish(*portnr);
+
+ return 0;
+ }
+ }
+ return -1;
+}
+
+
+void terminate(int *fd, int *sd, int *epmd_fd) {
+
+ close(*fd);
+
+ /* remove info from epnd */
+ close(*epmd_fd);
+
+ /* return socket */
+ close(*sd);
+
+}
+
+
+
+/* tells you what port you are using on given socket */
+static int getport(int sockd)
+{
+ struct sockaddr_in addr;
+ int namelen = sizeof(addr);
+ int i;
+
+ memset(&addr,0,sizeof(addr));
+
+ if ((i = getsockname(sockd,(struct sockaddr *)&addr,&namelen))<0)
+ return i;
+
+ return ntohs(addr.sin_port);
+}
+
+
+
+/* return a listen socket, bound to given port */
+/* specify port = 0 to let system assign port */
+static int getlisten(int port)
+{
+ int sockd;
+ struct sockaddr_in inaddr;
+ int opt = 1;
+ int i;
+
+ /* get listen socket */
+ if ((sockd = socket(AF_INET,SOCK_STREAM,0)) < 0) return sockd;
+
+ if ((i=setsockopt(sockd,SOL_SOCKET,SO_REUSEADDR,(void *)&opt,sizeof(opt)))<0)
+ return i;
+
+ /* bind to requested port */
+ memset(&inaddr,0,sizeof(inaddr));
+ inaddr.sin_family = AF_INET;
+ inaddr.sin_addr.s_addr = htonl(INADDR_ANY);
+ inaddr.sin_port = htons(port);
+
+ if ((i = bind(sockd,(struct sockaddr*) &inaddr, sizeof(inaddr))) < 0)
+ return i;
+
+ listen(sockd,5);
+
+ return sockd;
+}
+
diff --git a/lib/ic/examples/all-against-all/server.erl b/lib/ic/examples/all-against-all/server.erl
new file mode 100644
index 0000000000..24ace2e598
--- /dev/null
+++ b/lib/ic/examples/all-against-all/server.erl
@@ -0,0 +1,40 @@
+%%
+%% %CopyrightBegin%
+%%
+%% Copyright Ericsson AB 1999-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%
+%%
+%%
+-module(server).
+-export([start/0]).
+
+
+
+%% This starts up the random number server
+start() ->
+ %% Start the gen server
+ {ok,Pid} = rmod_random:oe_create([],{local,'rmod_random_impl'}),
+ true.
+
+
+
+
+
+
+
+
+
+
+
diff --git a/lib/ic/examples/all-against-all/server.java b/lib/ic/examples/all-against-all/server.java
new file mode 100644
index 0000000000..6b5fe8fcfd
--- /dev/null
+++ b/lib/ic/examples/all-against-all/server.java
@@ -0,0 +1,82 @@
+/*
+ * %CopyrightBegin%
+ *
+ * Copyright Ericsson AB 1999-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%
+ *
+ */
+public class server {
+
+ private static java.lang.String SNode = "babbis";
+ private static java.lang.String Cookie = "flash";
+ private static java.lang.String RegName = "rmod_random_impl";
+
+ public static void main(String[] args) {
+
+
+ System.out.println("\nServer running.\n");
+ boolean serverState = true;
+ boolean recState = true;
+
+ try {
+
+ com.ericsson.otp.erlang.OtpServer self = new com.ericsson.otp.erlang.OtpServer(SNode, Cookie);
+ self.publishPort();
+
+ /* Server loop */
+ while(serverState == true) {
+
+ com.ericsson.otp.erlang.OtpConnection connection = self.accept();
+ serverImpl srv = new serverImpl();
+ com.ericsson.otp.erlang.OtpInputStream request;
+ com.ericsson.otp.erlang.OtpOutputStream reply;
+ com.ericsson.otp.erlang.OtpErlangPid client;
+
+ /* Server loop */
+ while(recState == true) {
+
+ if (connection.isConnected() == true)
+ try {
+
+ request = connection.receiveBuf();
+
+ reply = srv.invoke(request);
+
+ if (reply != null) {
+ client = srv.__getCallerPid();
+
+ connection.sendBuf(client,reply);
+ }
+
+ } catch( Exception e) {
+ System.out.println("Server terminated.\n\n");
+ recState = false;
+ serverState = false;
+ }
+ }
+
+ connection.close();
+ }
+
+ } catch( Exception e) {
+ System.out.println("Initialization exception :");
+ e.printStackTrace();
+ }
+ }
+}
+
+
+
+
diff --git a/lib/ic/examples/all-against-all/serverImpl.java b/lib/ic/examples/all-against-all/serverImpl.java
new file mode 100644
index 0000000000..d5fb66e96b
--- /dev/null
+++ b/lib/ic/examples/all-against-all/serverImpl.java
@@ -0,0 +1,42 @@
+/*
+ * %CopyrightBegin%
+ *
+ * Copyright Ericsson AB 1999-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%
+ *
+ */
+public class serverImpl extends rmod._randomImplBase {
+
+ java.util.Random random = null;
+
+
+ public void init(int seed1, int seed2, int seed3) throws java.lang.Exception {
+
+ random = new java.util.Random(seed1+seed2+seed3);
+ };
+
+
+ public double produce() throws java.lang.Exception {
+
+ return random.nextDouble();
+ }
+
+}
+
+
+
+
+
+