1 /* 2 * Access a calculation server. 3 * 4 * Copyright (C) 2020 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #include <l4/re/env.h> 23 24 #include <stdio.h> 25 26 #include "calc_client.h" 27 #include "calc_local.h" 28 29 /* A generic function that can invoke local and remote objects. */ 30 31 static void invoke(Calc *obj, int *result) 32 { 33 obj->add(789, 123, result); 34 } 35 36 /* Main program. */ 37 38 int main(void) 39 { 40 l4_cap_idx_t server = l4re_env_get_cap("server"); 41 42 /* Calculator encapsulation. */ 43 44 client_Calc obj(server); 45 46 /* Another calculator. */ 47 48 local_Calc local_obj; 49 50 /* Call the calculator. */ 51 52 int result; 53 54 /* Invoke the operation via the interface. */ 55 56 invoke(&obj, &result); 57 printf("add 789, 123 -> %d\n", result); 58 59 /* Invoke an operation on the local object via the interface. */ 60 61 invoke(&local_obj, &result); 62 printf("add 789, 123 -> %d\n", result); 63 64 return 0; 65 }