1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/pkg/idl4re-examples/Control Sat Apr 25 15:44:16 2020 +0200
1.3 @@ -0,0 +1,3 @@
1.4 +requires: libc libipc
1.5 +provides: calc calc++
1.6 +maintainer: paul@boddie.org.uk
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/pkg/idl4re-examples/Makefile Sat Apr 25 15:44:16 2020 +0200
2.3 @@ -0,0 +1,6 @@
2.4 +PKGDIR ?= .
2.5 +L4DIR ?= $(PKGDIR)/../..
2.6 +
2.7 +TARGET = $(wildcard [a-z]*)
2.8 +
2.9 +include $(L4DIR)/mk/subdir.mk
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/pkg/idl4re-examples/calc++/Control Sat Apr 25 15:44:16 2020 +0200
3.3 @@ -0,0 +1,3 @@
3.4 +requires: libc libipc
3.5 +provides: calc++
3.6 +maintainer: paul@boddie.org.uk
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/pkg/idl4re-examples/calc++/Makefile Sat Apr 25 15:44:16 2020 +0200
4.3 @@ -0,0 +1,49 @@
4.4 +PKGDIR ?= ..
4.5 +L4DIR ?= $(PKGDIR)/../..
4.6 +
4.7 +TARGET = calc_client++ calc_server++ calc_counter_client++ calc_counter_server++
4.8 +MODE = shared
4.9 +
4.10 +# Locations for interface input and generated output.
4.11 +
4.12 +IDL_DIR = $(PKGDIR)/idl
4.13 +IDL_MK_DIR = $(L4DIR)/idl4re/mk
4.14 +IDL_BUILD_DIR = .
4.15 +IDL_EXPORT_DIR = .
4.16 +
4.17 +include $(IDL_MK_DIR)/idl.mk
4.18 +
4.19 +calc_counter_NAME = CalcCounter
4.20 +calc_counter_INTERFACES = calc counter
4.21 +
4.22 +COMP_INTERFACES_CC = calc_counter
4.23 +
4.24 +# Individual interfaces.
4.25 +
4.26 +CLIENT_INTERFACES_CC = calc counter
4.27 +SERVER_INTERFACES_CC = calc counter
4.28 +
4.29 +SRC_CC_calc_client++ = \
4.30 + $(call interfaces_to_client_cc,$(CLIENT_INTERFACES_CC)) \
4.31 + client.cc \
4.32 + calc_local.cc \
4.33 +
4.34 +SRC_CC_calc_server++ = \
4.35 + $(call interfaces_to_server_cc,$(SERVER_INTERFACES_CC)) \
4.36 + server.cc \
4.37 +
4.38 +SRC_CC_calc_counter_client++ = \
4.39 + $(call interfaces_to_client_cc,$(CLIENT_INTERFACES_CC)) \
4.40 + client_compound.cc \
4.41 +
4.42 +SRC_CC_calc_counter_server++ = \
4.43 + $(call interfaces_to_server_cc,$(SERVER_INTERFACES_CC)) \
4.44 + $(call interfaces_to_server_cc,$(COMP_INTERFACES_CC)) \
4.45 + server_compound.cc \
4.46 +
4.47 +REQUIRES_LIBS = l4re_c-util libipc
4.48 +
4.49 +PRIVATE_INCDIR = $(IDL_BUILD_DIR) $(IDL_EXPORT_DIR)
4.50 +
4.51 +include $(L4DIR)/mk/prog.mk
4.52 +include $(IDL_MK_DIR)/interface_rules.mk
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/pkg/idl4re-examples/calc++/calc_local.cc Sat Apr 25 15:44:16 2020 +0200
5.3 @@ -0,0 +1,60 @@
5.4 +/*
5.5 + * Provide a calculation object for local use.
5.6 + *
5.7 + * Copyright (C) 2020 Paul Boddie <paul@boddie.org.uk>
5.8 + *
5.9 + * This program is free software; you can redistribute it and/or
5.10 + * modify it under the terms of the GNU General Public License as
5.11 + * published by the Free Software Foundation; either version 2 of
5.12 + * the License, or (at your option) any later version.
5.13 + *
5.14 + * This program is distributed in the hope that it will be useful,
5.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5.17 + * GNU General Public License for more details.
5.18 + *
5.19 + * You should have received a copy of the GNU General Public License
5.20 + * along with this program; if not, write to the Free Software
5.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
5.22 + * Boston, MA 02110-1301, USA
5.23 + */
5.24 +
5.25 +#include <l4/sys/types.h>
5.26 +
5.27 +#include <math.h>
5.28 +
5.29 +#include "calc_local.h"
5.30 +
5.31 +
5.32 +
5.33 +/* Component methods. */
5.34 +
5.35 +long local_Calc::add(int left, int right, int *result)
5.36 +{
5.37 + *result = left + right;
5.38 + return L4_EOK;
5.39 +}
5.40 +
5.41 +long local_Calc::subtract(int left, int right, int *result)
5.42 +{
5.43 + *result = left - right;
5.44 + return L4_EOK;
5.45 +}
5.46 +
5.47 +long local_Calc::multiply(int left, int right, int *result)
5.48 +{
5.49 + *result = left * right;
5.50 + return L4_EOK;
5.51 +}
5.52 +
5.53 +long local_Calc::divide(int numerator, int denominator, int *result)
5.54 +{
5.55 + *result = numerator / denominator;
5.56 + return L4_EOK;
5.57 +}
5.58 +
5.59 +long local_Calc::pow(double base, double exponent, double *result)
5.60 +{
5.61 + *result = powf(base, exponent);
5.62 + return L4_EOK;
5.63 +}
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/pkg/idl4re-examples/calc++/calc_local.h Sat Apr 25 15:44:16 2020 +0200
6.3 @@ -0,0 +1,36 @@
6.4 +/*
6.5 + * Provide a calculation object for local use.
6.6 + *
6.7 + * Copyright (C) 2020 Paul Boddie <paul@boddie.org.uk>
6.8 + *
6.9 + * This program is free software; you can redistribute it and/or
6.10 + * modify it under the terms of the GNU General Public License as
6.11 + * published by the Free Software Foundation; either version 2 of
6.12 + * the License, or (at your option) any later version.
6.13 + *
6.14 + * This program is distributed in the hope that it will be useful,
6.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6.17 + * GNU General Public License for more details.
6.18 + *
6.19 + * You should have received a copy of the GNU General Public License
6.20 + * along with this program; if not, write to the Free Software
6.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
6.22 + * Boston, MA 02110-1301, USA
6.23 + */
6.24 +
6.25 +#pragma once
6.26 +
6.27 +#include "calc_interface.h"
6.28 +
6.29 +/* Interface for a local component. */
6.30 +
6.31 +class local_Calc : public Calc
6.32 +{
6.33 +public:
6.34 + long add(int left, int right, int *result);
6.35 + long subtract(int left, int right, int *result);
6.36 + long multiply(int left, int right, int *result);
6.37 + long divide(int numerator, int denominator, int *result);
6.38 + long pow(double base, double exponent, double *result);
6.39 +};
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/pkg/idl4re-examples/calc++/client.cc Sat Apr 25 15:44:16 2020 +0200
7.3 @@ -0,0 +1,65 @@
7.4 +/*
7.5 + * Access a calculation server.
7.6 + *
7.7 + * Copyright (C) 2020 Paul Boddie <paul@boddie.org.uk>
7.8 + *
7.9 + * This program is free software; you can redistribute it and/or
7.10 + * modify it under the terms of the GNU General Public License as
7.11 + * published by the Free Software Foundation; either version 2 of
7.12 + * the License, or (at your option) any later version.
7.13 + *
7.14 + * This program is distributed in the hope that it will be useful,
7.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7.17 + * GNU General Public License for more details.
7.18 + *
7.19 + * You should have received a copy of the GNU General Public License
7.20 + * along with this program; if not, write to the Free Software
7.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
7.22 + * Boston, MA 02110-1301, USA
7.23 + */
7.24 +
7.25 +#include <l4/re/env.h>
7.26 +
7.27 +#include <stdio.h>
7.28 +
7.29 +#include "calc_client.h"
7.30 +#include "calc_local.h"
7.31 +
7.32 +/* A generic function that can invoke local and remote objects. */
7.33 +
7.34 +static void invoke(Calc *obj, int *result)
7.35 +{
7.36 + obj->add(789, 123, result);
7.37 +}
7.38 +
7.39 +/* Main program. */
7.40 +
7.41 +int main(void)
7.42 +{
7.43 + l4_cap_idx_t server = l4re_env_get_cap("server");
7.44 +
7.45 + /* Calculator encapsulation. */
7.46 +
7.47 + client_Calc obj(server);
7.48 +
7.49 + /* Another calculator. */
7.50 +
7.51 + local_Calc local_obj;
7.52 +
7.53 + /* Call the calculator. */
7.54 +
7.55 + int result;
7.56 +
7.57 + /* Invoke the operation via the interface. */
7.58 +
7.59 + invoke(&obj, &result);
7.60 + printf("add 789, 123 -> %d\n", result);
7.61 +
7.62 + /* Invoke an operation on the local object via the interface. */
7.63 +
7.64 + invoke(&local_obj, &result);
7.65 + printf("add 789, 123 -> %d\n", result);
7.66 +
7.67 + return 0;
7.68 +}
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/pkg/idl4re-examples/calc++/client_compound.cc Sat Apr 25 15:44:16 2020 +0200
8.3 @@ -0,0 +1,58 @@
8.4 +/*
8.5 + * Access a server offering a compound interface.
8.6 + *
8.7 + * Copyright (C) 2020 Paul Boddie <paul@boddie.org.uk>
8.8 + *
8.9 + * This program is free software; you can redistribute it and/or
8.10 + * modify it under the terms of the GNU General Public License as
8.11 + * published by the Free Software Foundation; either version 2 of
8.12 + * the License, or (at your option) any later version.
8.13 + *
8.14 + * This program is distributed in the hope that it will be useful,
8.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8.17 + * GNU General Public License for more details.
8.18 + *
8.19 + * You should have received a copy of the GNU General Public License
8.20 + * along with this program; if not, write to the Free Software
8.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
8.22 + * Boston, MA 02110-1301, USA
8.23 + */
8.24 +
8.25 +#include <l4/re/env.h>
8.26 +
8.27 +#include <stdio.h>
8.28 +
8.29 +#include "calc_client.h"
8.30 +#include "counter_client.h"
8.31 +
8.32 +int main(void)
8.33 +{
8.34 + l4_cap_idx_t server = l4re_env_get_cap("server");
8.35 +
8.36 + /* Calculator encapsulation. */
8.37 +
8.38 + client_Calc calc_obj(server);
8.39 +
8.40 + /* Counter encapsulation. */
8.41 +
8.42 + client_Counter counter_obj(server);
8.43 +
8.44 + /* Call the calculator. */
8.45 +
8.46 + int result;
8.47 +
8.48 + /* Invoke the operation via the interface. */
8.49 +
8.50 + calc_obj.add(789, 123, &result);
8.51 + printf("add 789, 123 -> %d\n", result);
8.52 +
8.53 + /* Call the counter. */
8.54 +
8.55 + /* Invoke the operation via the interface. */
8.56 +
8.57 + counter_obj.increment(&result);
8.58 + printf("increment -> %d\n", result);
8.59 +
8.60 + return 0;
8.61 +}
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
9.2 +++ b/pkg/idl4re-examples/calc++/conf/calc++.cfg Sat Apr 25 15:44:16 2020 +0200
9.3 @@ -0,0 +1,23 @@
9.4 +-- vim:set ft=lua:
9.5 +
9.6 +local L4 = require("L4");
9.7 +
9.8 +local l = L4.default_loader;
9.9 +
9.10 +local ipc = l:new_channel();
9.11 +
9.12 +l:start({
9.13 + caps = {
9.14 + server = ipc:svr(),
9.15 + },
9.16 + log = { "calc_server++", "y" },
9.17 + },
9.18 + "rom/calc_server++");
9.19 +
9.20 +l:start({
9.21 + caps = {
9.22 + server = ipc,
9.23 + },
9.24 + log = { "calc_client++", "g" },
9.25 + },
9.26 + "rom/calc_client++");
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
10.2 +++ b/pkg/idl4re-examples/calc++/conf/calc++.list Sat Apr 25 15:44:16 2020 +0200
10.3 @@ -0,0 +1,24 @@
10.4 +entry calc++
10.5 +roottask moe rom/calc++.cfg
10.6 +module calc++.cfg
10.7 +module l4re
10.8 +module ned
10.9 +module calc_client++
10.10 +module calc_server++
10.11 +module lib4re-c.so
10.12 +module lib4re-c-util.so
10.13 +module lib4re.so
10.14 +module lib4re-util.so
10.15 +module libc_be_l4refile.so
10.16 +module libc_be_l4re.so
10.17 +module libc_be_socket_noop.so
10.18 +module libc_support_misc.so
10.19 +module libdl.so
10.20 +module libipc.so
10.21 +module libl4sys-direct.so
10.22 +module libl4sys.so
10.23 +module libl4util.so
10.24 +module libld-l4.so
10.25 +module libpthread.so
10.26 +module libsupc++.so
10.27 +module libuc_c.so
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
11.2 +++ b/pkg/idl4re-examples/calc++/conf/calc_counter++.cfg Sat Apr 25 15:44:16 2020 +0200
11.3 @@ -0,0 +1,23 @@
11.4 +-- vim:set ft=lua:
11.5 +
11.6 +local L4 = require("L4");
11.7 +
11.8 +local l = L4.default_loader;
11.9 +
11.10 +local ipc = l:new_channel();
11.11 +
11.12 +l:start({
11.13 + caps = {
11.14 + server = ipc:svr(),
11.15 + },
11.16 + log = { "calc_counter_server++", "y" },
11.17 + },
11.18 + "rom/calc_counter_server++");
11.19 +
11.20 +l:start({
11.21 + caps = {
11.22 + server = ipc,
11.23 + },
11.24 + log = { "calc_counter_client++", "g" },
11.25 + },
11.26 + "rom/calc_counter_client++");
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
12.2 +++ b/pkg/idl4re-examples/calc++/conf/calc_counter++.list Sat Apr 25 15:44:16 2020 +0200
12.3 @@ -0,0 +1,24 @@
12.4 +entry calc_counter++
12.5 +roottask moe rom/calc_counter++.cfg
12.6 +module calc_counter++.cfg
12.7 +module l4re
12.8 +module ned
12.9 +module calc_counter_client++
12.10 +module calc_counter_server++
12.11 +module lib4re-c.so
12.12 +module lib4re-c-util.so
12.13 +module lib4re.so
12.14 +module lib4re-util.so
12.15 +module libc_be_l4refile.so
12.16 +module libc_be_l4re.so
12.17 +module libc_be_socket_noop.so
12.18 +module libc_support_misc.so
12.19 +module libdl.so
12.20 +module libipc.so
12.21 +module libl4sys-direct.so
12.22 +module libl4sys.so
12.23 +module libl4util.so
12.24 +module libld-l4.so
12.25 +module libpthread.so
12.26 +module libsupc++.so
12.27 +module libuc_c.so
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
13.2 +++ b/pkg/idl4re-examples/calc++/server.cc Sat Apr 25 15:44:16 2020 +0200
13.3 @@ -0,0 +1,116 @@
13.4 +/*
13.5 + * Provide a calculation server.
13.6 + *
13.7 + * Copyright (C) 2020 Paul Boddie <paul@boddie.org.uk>
13.8 + *
13.9 + * This program is free software; you can redistribute it and/or
13.10 + * modify it under the terms of the GNU General Public License as
13.11 + * published by the Free Software Foundation; either version 2 of
13.12 + * the License, or (at your option) any later version.
13.13 + *
13.14 + * This program is distributed in the hope that it will be useful,
13.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13.17 + * GNU General Public License for more details.
13.18 + *
13.19 + * You should have received a copy of the GNU General Public License
13.20 + * along with this program; if not, write to the Free Software
13.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
13.22 + * Boston, MA 02110-1301, USA
13.23 + */
13.24 +
13.25 +#include <l4/re/env.h>
13.26 +#include <l4/sys/err.h>
13.27 +
13.28 +#include <math.h>
13.29 +#include <stdio.h>
13.30 +
13.31 +#include <ipc/server.h>
13.32 +
13.33 +#include "calc_server.h"
13.34 +
13.35 +
13.36 +
13.37 +/* Component interface. */
13.38 +
13.39 +class server_Calc : public Calc
13.40 +{
13.41 +public:
13.42 + long add(int left, int right, int *result)
13.43 + {
13.44 + *result = left + right;
13.45 + return L4_EOK;
13.46 + }
13.47 +
13.48 + long subtract(int left, int right, int *result)
13.49 + {
13.50 + *result = left - right;
13.51 + return L4_EOK;
13.52 + }
13.53 +
13.54 + long multiply(int left, int right, int *result)
13.55 + {
13.56 + *result = left * right;
13.57 + return L4_EOK;
13.58 + }
13.59 +
13.60 + long divide(int numerator, int denominator, int *result)
13.61 + {
13.62 + *result = numerator / denominator;
13.63 + return L4_EOK;
13.64 + }
13.65 +
13.66 + long pow(double base, double exponent, double *result)
13.67 + {
13.68 + *result = powf(base, exponent);
13.69 + return L4_EOK;
13.70 + }
13.71 +};
13.72 +
13.73 +
13.74 +
13.75 +int main(void)
13.76 +{
13.77 + /* Calculator encapsulation. */
13.78 +
13.79 + server_Calc obj;
13.80 +
13.81 + /* Server capability, incoming message and label. */
13.82 +
13.83 + l4_cap_idx_t server;
13.84 + ipc_message_t msg;
13.85 + l4_umword_t label;
13.86 + Calc *target;
13.87 +
13.88 + /* Register a server associating it with the given object. */
13.89 +
13.90 + long err = ipc_server_bind("server", (l4_umword_t) &obj, &server);
13.91 +
13.92 + if (err)
13.93 + {
13.94 + printf("Could not bind server: %s\n", l4sys_errtostr(err));
13.95 + return 1;
13.96 + }
13.97 +
13.98 + /* Wait for messages, dispatching to the handler. */
13.99 +
13.100 + while (1)
13.101 + {
13.102 + ipc_message_wait(&msg, &label);
13.103 +
13.104 + /* Ignore erroneous messages. */
13.105 +
13.106 + if (l4_ipc_error(msg.tag, l4_utcb()))
13.107 + continue;
13.108 +
13.109 + /* Handle messages for different server objects. */
13.110 +
13.111 + target = (Calc *) (label & ~3UL);
13.112 +
13.113 + /* Dispatch to the object. */
13.114 +
13.115 + handle_Calc(&msg, target);
13.116 + }
13.117 +
13.118 + return 0;
13.119 +}
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
14.2 +++ b/pkg/idl4re-examples/calc++/server_compound.cc Sat Apr 25 15:44:16 2020 +0200
14.3 @@ -0,0 +1,127 @@
14.4 +/*
14.5 + * Provide a server offering a compound interface.
14.6 + *
14.7 + * Copyright (C) 2020 Paul Boddie <paul@boddie.org.uk>
14.8 + *
14.9 + * This program is free software; you can redistribute it and/or
14.10 + * modify it under the terms of the GNU General Public License as
14.11 + * published by the Free Software Foundation; either version 2 of
14.12 + * the License, or (at your option) any later version.
14.13 + *
14.14 + * This program is distributed in the hope that it will be useful,
14.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14.17 + * GNU General Public License for more details.
14.18 + *
14.19 + * You should have received a copy of the GNU General Public License
14.20 + * along with this program; if not, write to the Free Software
14.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
14.22 + * Boston, MA 02110-1301, USA
14.23 + */
14.24 +
14.25 +#include <l4/re/env.h>
14.26 +#include <l4/sys/err.h>
14.27 +
14.28 +#include <math.h>
14.29 +#include <stdio.h>
14.30 +
14.31 +#include <ipc/server.h>
14.32 +
14.33 +#include "calc_counter_server.h"
14.34 +
14.35 +
14.36 +
14.37 +/* Component interface. */
14.38 +
14.39 +class server_CalcCounter : public CalcCounter
14.40 +{
14.41 + /* Component state . */
14.42 +
14.43 + int counter = 0;
14.44 +
14.45 +public:
14.46 + long add(int left, int right, int *result)
14.47 + {
14.48 + *result = left + right;
14.49 + return L4_EOK;
14.50 + }
14.51 +
14.52 + long subtract(int left, int right, int *result)
14.53 + {
14.54 + *result = left - right;
14.55 + return L4_EOK;
14.56 + }
14.57 +
14.58 + long multiply(int left, int right, int *result)
14.59 + {
14.60 + *result = left * right;
14.61 + return L4_EOK;
14.62 + }
14.63 +
14.64 + long divide(int numerator, int denominator, int *result)
14.65 + {
14.66 + *result = numerator / denominator;
14.67 + return L4_EOK;
14.68 + }
14.69 +
14.70 + long pow(double base, double exponent, double *result)
14.71 + {
14.72 + *result = powf(base, exponent);
14.73 + return L4_EOK;
14.74 + }
14.75 +
14.76 + long increment(int *result)
14.77 + {
14.78 + counter = counter + 1;
14.79 + *result = counter;
14.80 + return L4_EOK;
14.81 + }
14.82 +};
14.83 +
14.84 +
14.85 +
14.86 +int main(void)
14.87 +{
14.88 + /* An encapsulation. */
14.89 +
14.90 + server_CalcCounter obj;
14.91 +
14.92 + /* Server capability, incoming message and label. */
14.93 +
14.94 + l4_cap_idx_t server;
14.95 + ipc_message_t msg;
14.96 + l4_umword_t label;
14.97 + CalcCounter *target;
14.98 +
14.99 + /* Register a server associating it with the given object. */
14.100 +
14.101 + long err = ipc_server_bind("server", (l4_umword_t) &obj, &server);
14.102 +
14.103 + if (err)
14.104 + {
14.105 + printf("Could not bind server: %s\n", l4sys_errtostr(err));
14.106 + return 1;
14.107 + }
14.108 +
14.109 + /* Wait for messages, dispatching to the handler. */
14.110 +
14.111 + while (1)
14.112 + {
14.113 + ipc_message_wait(&msg, &label);
14.114 +
14.115 + /* Ignore erroneous messages. */
14.116 +
14.117 + if (l4_ipc_error(msg.tag, l4_utcb()))
14.118 + continue;
14.119 +
14.120 + /* Handle messages for different server objects. */
14.121 +
14.122 + target = (CalcCounter *) (label & ~3UL);
14.123 +
14.124 + /* Dispatch to the object. */
14.125 +
14.126 + handle_CalcCounter(&msg, target);
14.127 + }
14.128 +
14.129 + return 0;
14.130 +}
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
15.2 +++ b/pkg/idl4re-examples/calc/Control Sat Apr 25 15:44:16 2020 +0200
15.3 @@ -0,0 +1,3 @@
15.4 +requires: libc libipc
15.5 +provides: calc
15.6 +maintainer: paul@boddie.org.uk
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
16.2 +++ b/pkg/idl4re-examples/calc/Makefile Sat Apr 25 15:44:16 2020 +0200
16.3 @@ -0,0 +1,49 @@
16.4 +PKGDIR ?= ..
16.5 +L4DIR ?= $(PKGDIR)/../..
16.6 +
16.7 +TARGET = calc_client calc_server calc_counter_client calc_counter_server
16.8 +MODE = shared
16.9 +
16.10 +# Locations for interface input and generated output.
16.11 +
16.12 +IDL_DIR = $(PKGDIR)/idl
16.13 +IDL_MK_DIR = $(L4DIR)/idl4re/mk
16.14 +IDL_BUILD_DIR = .
16.15 +IDL_EXPORT_DIR = .
16.16 +
16.17 +include $(IDL_MK_DIR)/idl.mk
16.18 +
16.19 +calc_counter_NAME = CalcCounter
16.20 +calc_counter_INTERFACES = calc counter
16.21 +
16.22 +COMP_INTERFACES_C = calc_counter
16.23 +
16.24 +# Individual interfaces.
16.25 +
16.26 +CLIENT_INTERFACES_C = calc counter
16.27 +SERVER_INTERFACES_C = calc counter
16.28 +
16.29 +SRC_C_calc_client = \
16.30 + $(call interfaces_to_client_c,$(CLIENT_INTERFACES_C)) \
16.31 + client.c \
16.32 + calc_local.c \
16.33 +
16.34 +SRC_C_calc_server = \
16.35 + $(call interfaces_to_server_c,$(SERVER_INTERFACES_C)) \
16.36 + server.c \
16.37 +
16.38 +SRC_C_calc_counter_client = \
16.39 + $(call interfaces_to_client_c,$(CLIENT_INTERFACES_C)) \
16.40 + client_compound.c \
16.41 +
16.42 +SRC_C_calc_counter_server = \
16.43 + $(call interfaces_to_server_c,$(SERVER_INTERFACES_C)) \
16.44 + $(call interfaces_to_server_c,$(COMP_INTERFACES_C)) \
16.45 + server_compound.c \
16.46 +
16.47 +REQUIRES_LIBS = l4re_c-util libipc
16.48 +
16.49 +PRIVATE_INCDIR = $(IDL_BUILD_DIR) $(IDL_EXPORT_DIR)
16.50 +
16.51 +include $(L4DIR)/mk/prog.mk
16.52 +include $(IDL_MK_DIR)/interface_rules.mk
17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
17.2 +++ b/pkg/idl4re-examples/calc/calc_local.c Sat Apr 25 15:44:16 2020 +0200
17.3 @@ -0,0 +1,77 @@
17.4 +/*
17.5 + * Provide a calculation object for local use.
17.6 + *
17.7 + * Copyright (C) 2020 Paul Boddie <paul@boddie.org.uk>
17.8 + *
17.9 + * This program is free software; you can redistribute it and/or
17.10 + * modify it under the terms of the GNU General Public License as
17.11 + * published by the Free Software Foundation; either version 2 of
17.12 + * the License, or (at your option) any later version.
17.13 + *
17.14 + * This program is distributed in the hope that it will be useful,
17.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17.17 + * GNU General Public License for more details.
17.18 + *
17.19 + * You should have received a copy of the GNU General Public License
17.20 + * along with this program; if not, write to the Free Software
17.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17.22 + * Boston, MA 02110-1301, USA
17.23 + */
17.24 +
17.25 +#include <l4/sys/types.h>
17.26 +
17.27 +#include <math.h>
17.28 +
17.29 +#include "calc_interface.h"
17.30 +
17.31 +
17.32 +
17.33 +/* Component methods. */
17.34 +
17.35 +static long calc_add(ref_Calc _self, int left, int right, int *result)
17.36 +{
17.37 + (void) _self;
17.38 + *result = left + right;
17.39 + return L4_EOK;
17.40 +}
17.41 +
17.42 +static long calc_subtract(ref_Calc _self, int left, int right, int *result)
17.43 +{
17.44 + (void) _self;
17.45 + *result = left - right;
17.46 + return L4_EOK;
17.47 +}
17.48 +
17.49 +static long calc_multiply(ref_Calc _self, int left, int right, int *result)
17.50 +{
17.51 + (void) _self;
17.52 + *result = left * right;
17.53 + return L4_EOK;
17.54 +}
17.55 +
17.56 +static long calc_divide(ref_Calc _self, int numerator, int denominator, int *result)
17.57 +{
17.58 + (void) _self;
17.59 + *result = numerator / denominator;
17.60 + return L4_EOK;
17.61 +}
17.62 +
17.63 +static long calc_pow(ref_Calc _self, double base, double exponent, double *result)
17.64 +{
17.65 + (void) _self;
17.66 + *result = powf(base, exponent);
17.67 + return L4_EOK;
17.68 +}
17.69 +
17.70 +
17.71 +
17.72 +/* Interface for this component. */
17.73 +
17.74 +iface_Calc local_iface_Calc = {
17.75 + .add=calc_add,
17.76 + .subtract=calc_subtract,
17.77 + .multiply=calc_multiply,
17.78 + .divide=calc_divide,
17.79 + .pow=calc_pow
17.80 + };
18.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
18.2 +++ b/pkg/idl4re-examples/calc/calc_local.h Sat Apr 25 15:44:16 2020 +0200
18.3 @@ -0,0 +1,28 @@
18.4 +/*
18.5 + * Provide a calculation object for local use.
18.6 + *
18.7 + * Copyright (C) 2020 Paul Boddie <paul@boddie.org.uk>
18.8 + *
18.9 + * This program is free software; you can redistribute it and/or
18.10 + * modify it under the terms of the GNU General Public License as
18.11 + * published by the Free Software Foundation; either version 2 of
18.12 + * the License, or (at your option) any later version.
18.13 + *
18.14 + * This program is distributed in the hope that it will be useful,
18.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18.17 + * GNU General Public License for more details.
18.18 + *
18.19 + * You should have received a copy of the GNU General Public License
18.20 + * along with this program; if not, write to the Free Software
18.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
18.22 + * Boston, MA 02110-1301, USA
18.23 + */
18.24 +
18.25 +#pragma once
18.26 +
18.27 +#include "calc_interface.h"
18.28 +
18.29 +/* Interface for a local component. */
18.30 +
18.31 +extern iface_Calc local_iface_Calc;
19.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
19.2 +++ b/pkg/idl4re-examples/calc/client.c Sat Apr 25 15:44:16 2020 +0200
19.3 @@ -0,0 +1,63 @@
19.4 +/*
19.5 + * Access a calculation server.
19.6 + *
19.7 + * Copyright (C) 2020 Paul Boddie <paul@boddie.org.uk>
19.8 + *
19.9 + * This program is free software; you can redistribute it and/or
19.10 + * modify it under the terms of the GNU General Public License as
19.11 + * published by the Free Software Foundation; either version 2 of
19.12 + * the License, or (at your option) any later version.
19.13 + *
19.14 + * This program is distributed in the hope that it will be useful,
19.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19.17 + * GNU General Public License for more details.
19.18 + *
19.19 + * You should have received a copy of the GNU General Public License
19.20 + * along with this program; if not, write to the Free Software
19.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
19.22 + * Boston, MA 02110-1301, USA
19.23 + */
19.24 +
19.25 +#include <l4/re/env.h>
19.26 +
19.27 +#include <stdio.h>
19.28 +
19.29 +#include "calc_client.h"
19.30 +#include "calc_local.h"
19.31 +
19.32 +int main(void)
19.33 +{
19.34 + l4_cap_idx_t server = l4re_env_get_cap("server");
19.35 +
19.36 + /* Reference to a calculator and encapsulation. */
19.37 +
19.38 + ref_Calc ref = {.cap=server};
19.39 + Calc obj = {.ref=ref, .iface=&client_iface_Calc};
19.40 +
19.41 + /* Reference to another calculator. */
19.42 +
19.43 + ref_Calc local_ref = {.ptr=0};
19.44 + Calc local_obj = {.ref=local_ref, .iface=&local_iface_Calc};
19.45 +
19.46 + /* Call the calculator. */
19.47 +
19.48 + int result;
19.49 +
19.50 + /* Invoke the operation function directly. */
19.51 +
19.52 + Calc_add(ref, 123, 456, &result);
19.53 + printf("add 123, 456 -> %d\n", result);
19.54 +
19.55 + /* Invoke the operation via the interface. */
19.56 +
19.57 + obj.iface->add(obj.ref, 789, 123, &result);
19.58 + printf("add 789, 123 -> %d\n", result);
19.59 +
19.60 + /* Invoke an operation on the local object via the interface. */
19.61 +
19.62 + local_obj.iface->add(local_obj.ref, 789, 123, &result);
19.63 + printf("add 789, 123 -> %d\n", result);
19.64 +
19.65 + return 0;
19.66 +}
20.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
20.2 +++ b/pkg/idl4re-examples/calc/client_compound.c Sat Apr 25 15:44:16 2020 +0200
20.3 @@ -0,0 +1,70 @@
20.4 +/*
20.5 + * Access a server offering a compound interface.
20.6 + *
20.7 + * Copyright (C) 2020 Paul Boddie <paul@boddie.org.uk>
20.8 + *
20.9 + * This program is free software; you can redistribute it and/or
20.10 + * modify it under the terms of the GNU General Public License as
20.11 + * published by the Free Software Foundation; either version 2 of
20.12 + * the License, or (at your option) any later version.
20.13 + *
20.14 + * This program is distributed in the hope that it will be useful,
20.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20.17 + * GNU General Public License for more details.
20.18 + *
20.19 + * You should have received a copy of the GNU General Public License
20.20 + * along with this program; if not, write to the Free Software
20.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
20.22 + * Boston, MA 02110-1301, USA
20.23 + */
20.24 +
20.25 +#include <l4/re/env.h>
20.26 +
20.27 +#include <stdio.h>
20.28 +
20.29 +#include "calc_client.h"
20.30 +#include "counter_client.h"
20.31 +
20.32 +int main(void)
20.33 +{
20.34 + l4_cap_idx_t server = l4re_env_get_cap("server");
20.35 +
20.36 + /* Reference to a calculator and encapsulation. */
20.37 +
20.38 + ref_Calc calc_ref = {.cap=server};
20.39 + Calc calc_obj = {.ref=calc_ref, .iface=&client_iface_Calc};
20.40 +
20.41 + /* Reference to a counter and encapsulation. */
20.42 +
20.43 + ref_Counter counter_ref = {.cap=server};
20.44 + Counter counter_obj = {.ref=counter_ref, .iface=&client_iface_Counter};
20.45 +
20.46 + /* Call the calculator. */
20.47 +
20.48 + int result;
20.49 +
20.50 + /* Invoke the operation function directly. */
20.51 +
20.52 + Calc_add(calc_ref, 123, 456, &result);
20.53 + printf("add 123, 456 -> %d\n", result);
20.54 +
20.55 + /* Invoke the operation via the interface. */
20.56 +
20.57 + calc_obj.iface->add(calc_obj.ref, 789, 123, &result);
20.58 + printf("add 789, 123 -> %d\n", result);
20.59 +
20.60 + /* Call the counter. */
20.61 +
20.62 + /* Invoke the operation function directly. */
20.63 +
20.64 + Counter_increment(counter_ref, &result);
20.65 + printf("increment -> %d\n", result);
20.66 +
20.67 + /* Invoke the operation via the interface. */
20.68 +
20.69 + counter_obj.iface->increment(counter_obj.ref, &result);
20.70 + printf("increment -> %d\n", result);
20.71 +
20.72 + return 0;
20.73 +}
21.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
21.2 +++ b/pkg/idl4re-examples/calc/conf/calc.cfg Sat Apr 25 15:44:16 2020 +0200
21.3 @@ -0,0 +1,23 @@
21.4 +-- vim:set ft=lua:
21.5 +
21.6 +local L4 = require("L4");
21.7 +
21.8 +local l = L4.default_loader;
21.9 +
21.10 +local ipc = l:new_channel();
21.11 +
21.12 +l:start({
21.13 + caps = {
21.14 + server = ipc:svr(),
21.15 + },
21.16 + log = { "calc_server", "y" },
21.17 + },
21.18 + "rom/calc_server");
21.19 +
21.20 +l:start({
21.21 + caps = {
21.22 + server = ipc,
21.23 + },
21.24 + log = { "calc_client", "g" },
21.25 + },
21.26 + "rom/calc_client");
22.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
22.2 +++ b/pkg/idl4re-examples/calc/conf/calc.list Sat Apr 25 15:44:16 2020 +0200
22.3 @@ -0,0 +1,24 @@
22.4 +entry calc
22.5 +roottask moe rom/calc.cfg
22.6 +module calc.cfg
22.7 +module l4re
22.8 +module ned
22.9 +module calc_client
22.10 +module calc_server
22.11 +module lib4re-c.so
22.12 +module lib4re-c-util.so
22.13 +module lib4re.so
22.14 +module lib4re-util.so
22.15 +module libc_be_l4refile.so
22.16 +module libc_be_l4re.so
22.17 +module libc_be_socket_noop.so
22.18 +module libc_support_misc.so
22.19 +module libdl.so
22.20 +module libipc.so
22.21 +module libl4sys-direct.so
22.22 +module libl4sys.so
22.23 +module libl4util.so
22.24 +module libld-l4.so
22.25 +module libpthread.so
22.26 +module libsupc++.so
22.27 +module libuc_c.so
23.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
23.2 +++ b/pkg/idl4re-examples/calc/conf/calc_counter.cfg Sat Apr 25 15:44:16 2020 +0200
23.3 @@ -0,0 +1,23 @@
23.4 +-- vim:set ft=lua:
23.5 +
23.6 +local L4 = require("L4");
23.7 +
23.8 +local l = L4.default_loader;
23.9 +
23.10 +local ipc = l:new_channel();
23.11 +
23.12 +l:start({
23.13 + caps = {
23.14 + server = ipc:svr(),
23.15 + },
23.16 + log = { "calc_counter_server", "y" },
23.17 + },
23.18 + "rom/calc_counter_server");
23.19 +
23.20 +l:start({
23.21 + caps = {
23.22 + server = ipc,
23.23 + },
23.24 + log = { "calc_counter_client", "g" },
23.25 + },
23.26 + "rom/calc_counter_client");
24.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
24.2 +++ b/pkg/idl4re-examples/calc/conf/calc_counter.list Sat Apr 25 15:44:16 2020 +0200
24.3 @@ -0,0 +1,24 @@
24.4 +entry calc_counter
24.5 +roottask moe rom/calc_counter.cfg
24.6 +module calc_counter.cfg
24.7 +module l4re
24.8 +module ned
24.9 +module calc_counter_client
24.10 +module calc_counter_server
24.11 +module lib4re-c.so
24.12 +module lib4re-c-util.so
24.13 +module lib4re.so
24.14 +module lib4re-util.so
24.15 +module libc_be_l4refile.so
24.16 +module libc_be_l4re.so
24.17 +module libc_be_socket_noop.so
24.18 +module libc_support_misc.so
24.19 +module libdl.so
24.20 +module libipc.so
24.21 +module libl4sys-direct.so
24.22 +module libl4sys.so
24.23 +module libl4util.so
24.24 +module libld-l4.so
24.25 +module libpthread.so
24.26 +module libsupc++.so
24.27 +module libuc_c.so
25.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
25.2 +++ b/pkg/idl4re-examples/calc/server.c Sat Apr 25 15:44:16 2020 +0200
25.3 @@ -0,0 +1,130 @@
25.4 +/*
25.5 + * Provide a calculation server.
25.6 + *
25.7 + * Copyright (C) 2020 Paul Boddie <paul@boddie.org.uk>
25.8 + *
25.9 + * This program is free software; you can redistribute it and/or
25.10 + * modify it under the terms of the GNU General Public License as
25.11 + * published by the Free Software Foundation; either version 2 of
25.12 + * the License, or (at your option) any later version.
25.13 + *
25.14 + * This program is distributed in the hope that it will be useful,
25.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25.17 + * GNU General Public License for more details.
25.18 + *
25.19 + * You should have received a copy of the GNU General Public License
25.20 + * along with this program; if not, write to the Free Software
25.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
25.22 + * Boston, MA 02110-1301, USA
25.23 + */
25.24 +
25.25 +#include <l4/re/env.h>
25.26 +#include <l4/sys/err.h>
25.27 +
25.28 +#include <math.h>
25.29 +#include <stdio.h>
25.30 +
25.31 +#include <ipc/server.h>
25.32 +
25.33 +#include "calc_server.h"
25.34 +
25.35 +
25.36 +
25.37 +/* Component methods. */
25.38 +
25.39 +static long calc_add(ref_Calc _self, int left, int right, int *result)
25.40 +{
25.41 + (void) _self;
25.42 + *result = left + right;
25.43 + return L4_EOK;
25.44 +}
25.45 +
25.46 +static long calc_subtract(ref_Calc _self, int left, int right, int *result)
25.47 +{
25.48 + (void) _self;
25.49 + *result = left - right;
25.50 + return L4_EOK;
25.51 +}
25.52 +
25.53 +static long calc_multiply(ref_Calc _self, int left, int right, int *result)
25.54 +{
25.55 + (void) _self;
25.56 + *result = left * right;
25.57 + return L4_EOK;
25.58 +}
25.59 +
25.60 +static long calc_divide(ref_Calc _self, int numerator, int denominator, int *result)
25.61 +{
25.62 + (void) _self;
25.63 + *result = numerator / denominator;
25.64 + return L4_EOK;
25.65 +}
25.66 +
25.67 +static long calc_pow(ref_Calc _self, double base, double exponent, double *result)
25.68 +{
25.69 + (void) _self;
25.70 + *result = powf(base, exponent);
25.71 + return L4_EOK;
25.72 +}
25.73 +
25.74 +
25.75 +
25.76 +/* Interface for this component. */
25.77 +
25.78 +iface_Calc server_iface_Calc = {
25.79 + .add=calc_add,
25.80 + .subtract=calc_subtract,
25.81 + .multiply=calc_multiply,
25.82 + .divide=calc_divide,
25.83 + .pow=calc_pow
25.84 + };
25.85 +
25.86 +
25.87 +
25.88 +int main(void)
25.89 +{
25.90 + /* Reference to a calculator and encapsulation. */
25.91 +
25.92 + ref_Calc ref = {.ptr=0};
25.93 + Calc obj = {.ref=ref, .iface=&server_iface_Calc};
25.94 +
25.95 + /* Server capability, incoming message and label. */
25.96 +
25.97 + l4_cap_idx_t server;
25.98 + ipc_message_t msg;
25.99 + l4_umword_t label;
25.100 + Calc *target;
25.101 +
25.102 + /* Register a server associating it with the given object. */
25.103 +
25.104 + long err = ipc_server_bind("server", (l4_umword_t) &obj, &server);
25.105 +
25.106 + if (err)
25.107 + {
25.108 + printf("Could not bind server: %s\n", l4sys_errtostr(err));
25.109 + return 1;
25.110 + }
25.111 +
25.112 + /* Wait for messages, dispatching to the handler. */
25.113 +
25.114 + while (1)
25.115 + {
25.116 + ipc_message_wait(&msg, &label);
25.117 +
25.118 + /* Ignore erroneous messages. */
25.119 +
25.120 + if (l4_ipc_error(msg.tag, l4_utcb()))
25.121 + continue;
25.122 +
25.123 + /* Handle messages for different server objects. */
25.124 +
25.125 + target = (Calc *) (label & ~3UL);
25.126 +
25.127 + /* Dispatch to the object. */
25.128 +
25.129 + handle_Calc(&msg, target);
25.130 + }
25.131 +
25.132 + return 0;
25.133 +}
26.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
26.2 +++ b/pkg/idl4re-examples/calc/server_compound.c Sat Apr 25 15:44:16 2020 +0200
26.3 @@ -0,0 +1,156 @@
26.4 +/*
26.5 + * Provide a server offering a compound interface.
26.6 + *
26.7 + * Copyright (C) 2020 Paul Boddie <paul@boddie.org.uk>
26.8 + *
26.9 + * This program is free software; you can redistribute it and/or
26.10 + * modify it under the terms of the GNU General Public License as
26.11 + * published by the Free Software Foundation; either version 2 of
26.12 + * the License, or (at your option) any later version.
26.13 + *
26.14 + * This program is distributed in the hope that it will be useful,
26.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26.17 + * GNU General Public License for more details.
26.18 + *
26.19 + * You should have received a copy of the GNU General Public License
26.20 + * along with this program; if not, write to the Free Software
26.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
26.22 + * Boston, MA 02110-1301, USA
26.23 + */
26.24 +
26.25 +#include <l4/re/env.h>
26.26 +#include <l4/sys/err.h>
26.27 +
26.28 +#include <math.h>
26.29 +#include <stdio.h>
26.30 +
26.31 +#include <ipc/server.h>
26.32 +
26.33 +#include "calc_counter_server.h"
26.34 +
26.35 +
26.36 +
26.37 +/* Component methods. */
26.38 +
26.39 +static long calc_add(ref_Calc _self, int left, int right, int *result)
26.40 +{
26.41 + (void) _self;
26.42 + *result = left + right;
26.43 + return L4_EOK;
26.44 +}
26.45 +
26.46 +static long calc_subtract(ref_Calc _self, int left, int right, int *result)
26.47 +{
26.48 + (void) _self;
26.49 + *result = left - right;
26.50 + return L4_EOK;
26.51 +}
26.52 +
26.53 +static long calc_multiply(ref_Calc _self, int left, int right, int *result)
26.54 +{
26.55 + (void) _self;
26.56 + *result = left * right;
26.57 + return L4_EOK;
26.58 +}
26.59 +
26.60 +static long calc_divide(ref_Calc _self, int numerator, int denominator, int *result)
26.61 +{
26.62 + (void) _self;
26.63 + *result = numerator / denominator;
26.64 + return L4_EOK;
26.65 +}
26.66 +
26.67 +static long calc_pow(ref_Calc _self, double base, double exponent, double *result)
26.68 +{
26.69 + (void) _self;
26.70 + *result = powf(base, exponent);
26.71 + return L4_EOK;
26.72 +}
26.73 +
26.74 +
26.75 +
26.76 +/* Component state and methods. */
26.77 +
26.78 +static int counter = 0;
26.79 +
26.80 +static long counter_increment(ref_Counter _self, int *result)
26.81 +{
26.82 + int *counter = (int *) (_self.ptr);
26.83 +
26.84 + *counter = *counter + 1;
26.85 + *result = *counter;
26.86 + return L4_EOK;
26.87 +}
26.88 +
26.89 +
26.90 +
26.91 +/* Interfaces for this component. */
26.92 +
26.93 +iface_Calc server_iface_Calc = {
26.94 + .add=calc_add,
26.95 + .subtract=calc_subtract,
26.96 + .multiply=calc_multiply,
26.97 + .divide=calc_divide,
26.98 + .pow=calc_pow
26.99 + };
26.100 +
26.101 +iface_Counter server_iface_Counter = {
26.102 + .increment=counter_increment
26.103 + };
26.104 +
26.105 +/* The compound interface referencing the individual interfaces. */
26.106 +
26.107 +iface_CalcCounter server_iface_CalcCounter = {
26.108 + .to_Calc=&server_iface_Calc,
26.109 + .to_Counter=&server_iface_Counter
26.110 + };
26.111 +
26.112 +
26.113 +
26.114 +int main(void)
26.115 +{
26.116 + /* Reference to state information and an encapsulation. */
26.117 +
26.118 + ref_CalcCounter ref = {.ptr=&counter};
26.119 + CalcCounter obj = {.ref=ref, .iface=&server_iface_CalcCounter};
26.120 +
26.121 + /* Server capability, incoming message and label. */
26.122 +
26.123 + l4_cap_idx_t server;
26.124 + ipc_message_t msg;
26.125 + l4_umword_t label;
26.126 + CalcCounter *target;
26.127 +
26.128 + /* Register a server associating it with the given object. */
26.129 +
26.130 + long err = ipc_server_bind("server", (l4_umword_t) &obj, &server);
26.131 +
26.132 + if (err)
26.133 + {
26.134 + printf("Could not bind server: %s\n", l4sys_errtostr(err));
26.135 + return 1;
26.136 + }
26.137 +
26.138 + /* Wait for messages, dispatching to the handler. */
26.139 +
26.140 + while (1)
26.141 + {
26.142 + ipc_message_wait(&msg, &label);
26.143 +
26.144 + /* Ignore erroneous messages. */
26.145 +
26.146 + if (l4_ipc_error(msg.tag, l4_utcb()))
26.147 + continue;
26.148 +
26.149 + /* Handle messages for different server objects. */
26.150 +
26.151 + target = (CalcCounter *) (label & ~3UL);
26.152 +
26.153 + /* Dispatch to the object. */
26.154 +
26.155 + handle_CalcCounter(&msg, target);
26.156 + }
26.157 +
26.158 + return 0;
26.159 +}
27.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
27.2 +++ b/pkg/idl4re-examples/idl/calc.idl Sat Apr 25 15:44:16 2020 +0200
27.3 @@ -0,0 +1,9 @@
27.4 +[protocol(0x1d1e)]
27.5 +interface Calc
27.6 +{
27.7 + void add(in int left, in int right, out int result);
27.8 + void subtract(in int left, in int right, out int result);
27.9 + void multiply(in int left, in int right, out int result);
27.10 + void divide(in int numerator, in int denominator, out int result);
27.11 + void pow(in double base, in double exponent, out double result);
27.12 +};
28.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
28.2 +++ b/pkg/idl4re-examples/idl/counter.idl Sat Apr 25 15:44:16 2020 +0200
28.3 @@ -0,0 +1,5 @@
28.4 +[protocol(0x1d1f)]
28.5 +interface Counter
28.6 +{
28.7 + void increment(out int result);
28.8 +};