aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ic/examples/c-client
diff options
context:
space:
mode:
authorErlang/OTP <otp@erlang.org>2009-11-20 14:54:40 +0000
committerErlang/OTP <otp@erlang.org>2009-11-20 14:54:40 +0000
commit84adefa331c4159d432d22840663c38f155cd4c1 (patch)
treebff9a9c66adda4df2106dfd0e5c053ab182a12bd /lib/ic/examples/c-client
downloadotp-84adefa331c4159d432d22840663c38f155cd4c1.tar.gz
otp-84adefa331c4159d432d22840663c38f155cd4c1.tar.bz2
otp-84adefa331c4159d432d22840663c38f155cd4c1.zip
The R13B03 release.OTP_R13B03
Diffstat (limited to 'lib/ic/examples/c-client')
-rw-r--r--lib/ic/examples/c-client/Makefile86
-rw-r--r--lib/ic/examples/c-client/ReadMe46
-rw-r--r--lib/ic/examples/c-client/client.c130
-rw-r--r--lib/ic/examples/c-client/random.idl51
-rw-r--r--lib/ic/examples/c-client/rmod_random_impl.erl52
-rw-r--r--lib/ic/examples/c-client/test.erl43
6 files changed, 408 insertions, 0 deletions
diff --git a/lib/ic/examples/c-client/Makefile b/lib/ic/examples/c-client/Makefile
new file mode 100644
index 0000000000..7c57e4f7ed
--- /dev/null
+++ b/lib/ic/examples/c-client/Makefile
@@ -0,0 +1,86 @@
+#
+# %CopyrightBegin%
+#
+# Copyright Ericsson AB 1998-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/daily_build/otp_beam_sunos5_r8a.latest
+
+# Type actual IC Version
+ICVSN=4.1.1
+
+# Type actual Erl Interface Vesrion
+EIVSN=3.3.0
+
+# IDL file(s)
+IDLS=random.idl
+
+# Own C-client files
+CCL=client
+
+# Generated C-server files
+GCCLS=oe_code_seed 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='+{preproc_flags,"-I $(OTPROOT)/usr/include"}' '+{scoped_op_calls,true}'
+
+
+# C compiler
+CC=gcc
+
+# C compiler flags
+CFLAGS=-ggdb -O2 -Wall $(IFLAGS)
+
+
+all: server client
+
+
+server:
+ $(ERLC) $(EFLAGS) '+{be,erl_genserv}' $(IDLS)
+ $(ERLC) *.erl
+
+client:
+ $(ERLC) $(EFLAGS) '+{be,c_client}' $(IDLS)
+ $(CC) $(IFLAGS) -c $(CCL:=.c) $(GCCLS:=.c)
+ $(CC) $(CCL:=.o) $(GCCLS:=.o) -o $@ $(LDFLAGS) $(LDLIBS)
+
+
+
+clean:
+ /bin/rm -f $(GCCLS:=.o) $(GCCLS:=.c) $(CCL:=.o) *.jam *.beam oe* rmod_random.erl *.h *.hrl *~ core client
+
+
+
+
+
+
+
+
+
diff --git a/lib/ic/examples/c-client/ReadMe b/lib/ic/examples/c-client/ReadMe
new file mode 100644
index 0000000000..28372c3be2
--- /dev/null
+++ b/lib/ic/examples/c-client/ReadMe
@@ -0,0 +1,46 @@
+This is a short description on the use of the c-client demo,
+a client that initiates and uses a random number generator
+that lies on an Erlang-genserver.
+
+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 erlang with the options
+ -setcookie <Some Cookie> -sname <SomeNodeName>
+
+ In this example you should use :
+
+ erl -setcookie flash -sname babbis
+
+
+4) On the erlang shell type :
+ --------------------------
+
+ rmod_random:oe_create([],{local,rmod_random_impl}). ( initializes the server )
+
+ or
+
+ test:start().
+
+
+ Then start a new terminal window and type :
+ -------------------------------------------
+
+ client ( calls the client )
+
+
+
+
+
+
+
+
+
diff --git a/lib/ic/examples/c-client/client.c b/lib/ic/examples/c-client/client.c
new file mode 100644
index 0000000000..816477cf15
--- /dev/null
+++ b/lib/ic/examples/c-client/client.c
@@ -0,0 +1,130 @@
+/*
+ * %CopyrightBegin%
+ *
+ * Copyright Ericsson AB 1998-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 the interface function and ei_connect */
+#include "rmod_random.h"
+#include "ei_connect.h"
+
+/* Assign your own node name here */
+#define SNODE "babbis@balin"
+#define SERVER "rmod_random_impl"
+#define COOKIE "flash"
+#define CLNODE "c47@balin"
+#define INBUFSZ 1024
+#define OUTBUFSZ 1024
+
+/* Stopping node */
+void client_exit(CORBA_Environment *env) {
+
+ /* Free env & buffers */
+ CORBA_free(env->_inbuf);
+ CORBA_free(env->_outbuf);
+ CORBA_free(env);
+
+ close(env->_fd);
+ exit(1);
+}
+
+int main()
+{
+ double result=0;
+ int i=0;
+ erlang_pid pid;
+ CORBA_Environment *env;
+ seed idata;
+ ei_cnode ec;
+
+ /* Create and init CORBA_Environment */
+ env = CORBA_Environment_alloc(INBUFSZ,OUTBUFSZ);
+
+ /* Initialize seed */
+ idata.seed1 = 1;
+ idata.seed2 = 2;
+ idata.seed3 = 3;
+
+ /* Initiating the connection */
+ ei_connect_init(&ec, "c47", COOKIE, 0);
+
+ /* Initiating pid*/
+ strcpy(pid.node,CLNODE);
+ pid.num = 99;
+ pid.serial = 0;
+ pid.creation = 0;
+
+ /* Fixing environment variable */
+ env->_fd = ei_connect(&ec, SNODE);
+ strcpy(env->_regname, SERVER);
+ 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, &idata, 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 */
+ close(env->_fd);
+
+ /* Free env & buffers */
+ CORBA_free(env->_inbuf);
+ CORBA_free(env->_outbuf);
+ CORBA_free(env);
+
+ return 0;
+}
+
diff --git a/lib/ic/examples/c-client/random.idl b/lib/ic/examples/c-client/random.idl
new file mode 100644
index 0000000000..cfe38e32d8
--- /dev/null
+++ b/lib/ic/examples/c-client/random.idl
@@ -0,0 +1,51 @@
+// ``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
+
+struct seed {
+ long seed1;
+ long seed2;
+ long seed3;
+};
+
+module rmod {
+
+ interface random {
+
+ double produce();
+
+ oneway void init(in seed idata);
+
+ };
+
+};
+
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/lib/ic/examples/c-client/rmod_random_impl.erl b/lib/ic/examples/c-client/rmod_random_impl.erl
new file mode 100644
index 0000000000..863e3e8c24
--- /dev/null
+++ b/lib/ic/examples/c-client/rmod_random_impl.erl
@@ -0,0 +1,52 @@
+%%
+%% %CopyrightBegin%
+%%
+%% Copyright Ericsson AB 1998-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').
+-include("oe_random.hrl").
+-export([init/1, terminate/2]).
+-export([produce/1,init/2]).
+
+
+init(Env) ->
+ {ok, []}.
+
+terminate(From, Reason) ->
+ ok.
+
+
+produce(_Random) ->
+ case catch random:uniform() of
+ {'EXIT',_} ->
+ true;
+ RUnif ->
+ {reply,RUnif,[]}
+ end.
+
+
+init(_Random,IData) ->
+ S1 = IData#seed.seed1,
+ S2 = IData#seed.seed2,
+ S3 = IData#seed.seed3,
+ case catch random:seed(S1,S2,S3) of
+ {'EXIT',_} ->
+ true;
+ _ ->
+ {noreply,[]}
+ end.
+
diff --git a/lib/ic/examples/c-client/test.erl b/lib/ic/examples/c-client/test.erl
new file mode 100644
index 0000000000..0a05ce2944
--- /dev/null
+++ b/lib/ic/examples/c-client/test.erl
@@ -0,0 +1,43 @@
+%%
+%% %CopyrightBegin%
+%%
+%% Copyright Ericsson AB 1998-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%
+%%
+%%
+% Start Erlang with : erl -sname <your name> -setcookie <your cookie>
+
+-module(test).
+
+-export([start/0,exec/0]).
+
+
+start() ->
+ io:format("Starting server~n"),
+ rmod_random:oe_create([],{local,'rmod_random_impl'}).
+
+exec() ->
+ io:format("Running client~n"),
+ OutPut = os:cmd("client"),
+ io:format("~s",[OutPut]).
+
+
+
+
+
+
+
+
+