4.2 Server side

Next we implement the server-side functionality. Copy the generated skeleton file into the already known server/src/ directory.

~/build/pkg/hiworld/idl/OBJ-x86_586-l4v2> cp hiworld-template.c \
    ~/src/l4/pkg/hiworld/server/src/server.c

Modify the functions so they do what we want, write code that registers at the DROPS name server and calls the main server loop:

hiworld/server/src/server.c
#include <stdio.h>
#include <l4/names/libnames.h>
#include "hiworld-server.h"

char LOG_tag[9]="hiserver";
static int count;

void
hi_print_component(CORBA_Object _dice_corba_obj,
                   CORBA_Environment *_dice_corba_env){
    printf("Hi world\n");
    count++;
}

int
hi_count_component(CORBA_Object _dice_corba_obj,
                   CORBA_Environment *_dice_corba_env){
    return count;
}

int main(void){
    if(names_register("hiworld")==0){
      printf("Error registering at nameserver\n");
      return 1;
    }
    hi_server_loop(0);
}

We still have to tell BID that we want to compile another binary, containing the IDL server code and our implementation. Modify the makefile the following way:

hiworld/server/src/Makefile
PKGDIR          ?= ../..
L4DIR           ?= $(PKGDIR)/../..

TARGET          = hiserver
DEFAULT_RELOC   = 0x01800000

SRC_C           = server.c
SERVERIDL       = hiworld.idl

include $(L4DIR)/mk/prog.mk

You are ready to compile the server. BID knows where to find the files generated by the IDL compiler and arranges the include paths and additional object files for you.

~/src/l4/pkg/hiworld/server/src> make O=/path/to/build

If there are any problems, they are likely caused by typos, as your installation has already been proved correct in the previous steps.



L4 Checker 2012-04-11