Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleNetsync.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003, 2004 (see file CONTACTS for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 /** @example ExampleNetSync.cpp
25  @relates netsync
26  @ingroup g_examples
27  @brief this is an example for netsync
28  @author MIP
29 */
30 
31 #include <sys/time.h>
32 #include <stdlib.h>
33 #include <sched.h>
34 #include <unistd.h>
35 #include <stdio.h>
36 #include <string.h>
37 #include <iostream>
38 #include "../netsync.h"
39 
40 #define MYSLEEP 20000
41 
42 
43 using namespace std;
44 
45 
46 int main (int argc, char* argv[]) {
47  struct timeval tv;
48  struct timezone tz;
49  char name[256];
50  long starttime, endtime;
51 
52 
53  int i,n;
54  long int res;
55 
56 
57  char buffer[100];
58  int bufflen;
59 
60  char **hostlist;
61 
62  n = gettimeofday (&tv, &tz);
63  srand (tv.tv_usec);
64  i=gethostname (name,80);
65  if (i!=0) printf ("Failed to get host name.\n");
66 
67  if (argc <3) {
68  printf("not enough hosts\n");
69  exit(1);
70  }
71  /* hosts for the sync-tree */
72  hostlist = (char**)malloc(sizeof(char *) * argc -2);
73  for (i=1; i<argc; i++)
74  hostlist[i-1] = argv[i];
75 
76 // netsync_init_withcontroller(argc-1 , hostlist);
77  netsync_init(argc-1 , hostlist);
78 
79  for (i=0; i<5; i++) {
80  n = gettimeofday (&tv, &tz);
81  starttime=(tv.tv_sec%1000)*1000 + (tv.tv_usec/1000);
82  /* usleep (rand()/RAND_MAX*MYSLEEP/10+ MYSLEEP); */
83  /* if ((argc>1) && (i==50)) */
84  /* res=netsync_sync(netsync_exit); */
85  /* else */
86 
87  char magic[]="Hallo Welt";
88  if (netsync_amiroot() ) {
89  sprintf(buffer,magic);
90 
91  }
92  bufflen = strlen(magic)+1;
93 
94  res=netsync_sync(netsync_finished, buffer, &bufflen);
95  printf("Sync returned: %s\n",buffer);
96  if (res==-1) {
97  printf ("Netsync aborted \n");
98  exit(0);
99  }
100  n = gettimeofday (&tv, &tz);
101  endtime=(tv.tv_sec%1000)*1000 + (tv.tv_usec/1000);
102  fprintf (stdout,"%03d %14s duration: %4i ms %i ms\n",
103  i,name,endtime-starttime,endtime);
104  /* fprintf (fd,"%03d %14s %4i %i\n", */
105  /* i,name,endtime-starttime-(MYSLEEP/1000),endtime); */
106  }
107 
108  netsync_cleanup();
109  return 0;
110 }
111 
112 
113 
114 
115 
116 
117