DIM
Distributed Information Management
System
4.2 Server examples
Examples
#1
The following example implements a C server. This server provides
two services which contain the same data, but the way of providing the
data differs. The server can also execute one command and on its reception
it updates one of the services.
#include <dis.h>
int buffer[] = { 0,1,2,3,4,5,6,7,8,9 };
int service_id;
void build_service(tag, address, size)
long *tag;
int **address;
int *size;
{
*address = buffer;
*size = sizeof(buffer);
}
void execute_cmnd(tag, cmnd_buffer, size)
long *tag;
char *cmnd_buffer;
int *size;
{
if(*tag == 1)
{
printf("SERV_CMND: Command %s
received\n",cmnd_buffer);
dis_update_service(service_id);
}
}
main()
{
dis_add_service("SERV_BY_BUFFER", "L", buffer, 40, 0,
0);
service_id = dis_add_service("SERV_BY_ROUTINE", "L",
0, 0,
build_service, 0);
dis_add_cmnd("SERV_CMND", 0, execute_cmnd, 1);
dis_start_serving("DIS_TEST");
while(1)
{
sleep(10);
}
}
The following example implements a FORTRAN server. This server provides
one information service and one command service. On command reception it
updates the information service.
program test_server
implicit none
common/test_ser/service_id
integer*4 service_id
integer*4 dis_add_cmnd, dis_add_service
integer*4 dis_start_serving
external do_cmnd
character*80 str
str = 'Server Answer'
service_id = dis_add_service('TEST/INFO','C',%ref(str),80,%val(0),
0)
call dis_add_cmnd('TEST/CMND','C',do_cmnd,
0)
call dis_start_serving('DIS_TEST')
call sys$hiber()
end
subroutine do_cmnd(tag, buf, size)
implicit none
integer*8 tag
integer*4 buf, size
character*80 str
integer*4 dis_convert_str
common/test_ser/service_id
integer*4 service_id
C The routine dis_convert_str converts a C string into a Fortran string
call dis_convert_str(buf, str)
write(6,'(A,A)') ' Server : Received ',str
call dis_update_service(service_id)
end