示例#1
0
int main() {
    key_t key = ftok("./mark", (int)'a');
    int shmid = shmget(key, 100, IPC_CREAT | 0600);
    void* buf = (void*)shmat(shmid, NULL, 0);
    if ( (int)buf == -1 ) {
        shmctl(shmid, IPC_RMID, NULL);
        exit(1);
    }

    sprintf(buf, "hello, world\n");
    mysleep(5);
    sprintf(buf, "bye, world\n");
    mysleep(5);

    if ( -1 == shmdt(buf) ) {
        fprintf(stderr, "%s\n", strerror(errno));
        shmctl(shmid, IPC_RMID, NULL);
        exit(1);
    }

    if ( -1 == shmctl(shmid, IPC_RMID, NULL) )
    {
        fprintf(stderr, "%s\n", strerror(errno));
        exit(1);
    }

    printf("producer exited normally\n");
    return 0;
}
示例#2
0
static void lcd_strobe(int fd, uint8_t data)
{
      i2c_write_cmd(fd, data | En | LCD_BACKLIGHT);
      mysleep(1); //.0005);
      i2c_write_cmd(fd, ((data & ~En) | LCD_BACKLIGHT));
      mysleep(1); //.0001);
}
示例#3
0
void*
snapWorker(void* arg) {
    /* WARNING void* arg (workerArgs) is on the stack of the function below and
     * doesn't exist forever. */
    WorkerArgs *workerArgs = (WorkerArgs*) arg;
    SnapArgs *snapArgs = workerArgs->snapArgs;
    tcp_stat_agent* agent = workerArgs->agent;
    CwndPeaks* peaks = workerArgs->peaks;
    int writeSnap = workerArgs->writeSnap;

    // snap log written into every "delay" milliseconds
    double delay = ((double) snapArgs->delay) / 1000.0;

    while (1) {
        pthread_mutex_lock(&mainmutex);
        if (workerLoop) {
            pthread_cond_broadcast(&maincond);
            pthread_mutex_unlock(&mainmutex);
            break;
        }
        pthread_mutex_unlock(&mainmutex);
        mysleep(0.01);
    }

    // Find Congestion window peaks from a web_100 snapshot, if enabled
    // Write snap log , if enabled, all in a synchronous manner.
    while (1) {
        pthread_mutex_lock(&mainmutex);
        if (!workerLoop) {
            pthread_mutex_unlock(&mainmutex);
            break;
        }
#if USE_WEB100
        web100_snap(snapArgs->snap);
        if (peaks) {
            findCwndPeaks(agent, peaks, snapArgs->snap);
        }
        if (writeSnap) {
            web100_log_write(snapArgs->log, snapArgs->snap);
        }
#elif USE_WEB10G
        estats_read_vars(snapArgs->snap, snapArgs->conn, agent);
        if (peaks) {
            findCwndPeaks(agent, peaks, snapArgs->snap);
        }
        if (writeSnap) {
            estats_record_write_data(snapArgs->log, snapArgs->snap);
        }
#endif
        pthread_mutex_unlock(&mainmutex);
        mysleep(delay);
    }

    return NULL;
}
void draw_adjTable( unsigned int cs_size,double **cs,unsigned int* atArr,unsigned int **at,double connectRad,long int delay){
	int i,j;
	if(h==0){
		h = gnuplot_init();
		gnuplot_cmd(h, "clear");
		gnuplot_cmd(h,"reset");
	//	gnuplot_cmd(h,"set terminal gif small animate delay 1 optimize");
	//	gnuplot_cmd(h,"set output \"animate.gif\"");
//		gnuplot_cmd(h,"set terminal postscript eps enhanced color font 'Helvetica,10'");
//		gnuplot_cmd(h,"set output \"plot1.eps\"");
		gnuplot_cmd(h,"set terminal epslatex size 3.5,2.62 color colortext");
		gnuplot_cmd(h,"set output 'introduction.tex'");
		
//		gnuplot_cmd(h, "set xrange [-4:4]");
//		gnuplot_cmd(h, "set yrange [-4:4]");
//		gnuplot_cmd(h, "set zrange [-4:4]");
//		gnuplot_cmd(h, "set xlabel \"theta_1\" ");
//		gnuplot_cmd(h, "set ylabel \"theta_2\" ");
//		gnuplot_cmd(h, "set zlabel \"theta_3\" ");
		gnuplot_cmd(h, "set isosample 40" );
	}
	gnuplot_resetplot(h);	
	gnuplot_cmd(h,"set multiplot");

	double tol=connectRad ;
	gnuplot_cmd(h,"splot [-3.2:3.2][-3.2:3.2][-3.2:3.2] \"-\" using 1:2:3 with points pointtype 26 ps 0.6 notitle ");
	for(i=0;i<cs_size;i++){
			gnuplot_cmd(h,"%f %f %f", cs[i][0], cs[i][1], cs[i][2]);	
	}
	gnuplot_cmd(h,"e");

	gnuplot_cmd(h, "set xlabel \"theta_1\" ")	;
	gnuplot_cmd(h, "set ylabel \"theta_2\" ")	;
	gnuplot_cmd(h, "set zlabel \"theta_3\" ")	;
	gnuplot_cmd(h, "set style arrow 1 nohead")	;
	
	int temp;
	for(i=0;i<cs_size;i++){
		for(j=0;j<atArr[i];j++){
			temp=at[i][j];
			if( fabs(cs[i][0]-cs[temp][0])>tol ||fabs(cs[i][1]-cs[temp][1])>tol ||fabs(cs[i][2]-cs[temp][2])>tol){							
							// do nothing
			}else{
				gnuplot_cmd(h, "set arrow from %f,%f,%f to %f,%f,%f as 1",cs[i][0],cs[i][1], cs[i][2],cs[temp][0],cs[temp][1], cs[temp][2]);   
				mysleep(delay);
				gnuplot_cmd(h,"splot[-3.2:3.2][-3.2:3.2][-3.2:3.2] NaN notitle");
			}	
		}
	}
	mysleep(delay);
//	gnuplot_cmd(h,"unset multiplot");
}
void splash(void)
{
  int x;

  attrset(COLOR_PAIR(COLOR_RED) | A_BOLD);
  gplot("htext", 20, 1, 1);

  attrset(COLOR_PAIR(COLOR_GREEN));
  gplot("tdesc", 42, 9, 1);

  attrset(COLOR_PAIR(COLOR_RED));
  mvprintw(4, MAP_XSIZE - strlen(VERSION), "%s", VERSION);

  attrset(COLOR_PAIR(COLOR_CYAN));
  for(x = 0; x < MAP_XSIZE; x++) {
    mvaddch(MAP_YSIZE - 1, x, ':');
    mvaddch(0, x, ':');
  }

  attrset(COLOR_PAIR(COLOR_MAGENTA));

  mvprintw(MAP_YSIZE, 0, "CAVEZ of PHEAR Copyright 2003-2007 Tom Rune Flo <*****@*****.**>");
  mvprintw(MAP_YSIZE + 1, 0, "Distributed under the terms of the GPL license");

  refresh();

  attrset(COLOR_PAIR(COLOR_WHITE) | A_NORMAL);

  mysleep(100000);

  for(x = -40; x < 0; x++) {
    gplot("spgraf", x, 1, 0);
    refresh();
    mysleep(7000);
  }

  attrset(COLOR_PAIR(COLOR_YELLOW));
  mvprintw(15, 42, "PRESS ANY KEY TO START!");

  attrset(A_NORMAL);

  refresh();

  flushinp();
  getch(); 

  return;
}
示例#6
0
int my_clock_gettime(clockid_t clk_id, struct timespec *tp)
{	
	static int flag = 0;
	
	if(NULL == tp) {
		fprintf(std_err, "invalid argument.");
		return -1;
	}
	
#ifdef CONFIG_LOW_VERSION_LIBC
	tp->tv_sec = get_uptime();
	tp->tv_nsec = 0;
#else
	int ret = 0;
	int retry_count = 0;
	if (!flag) {
		while(((ret = clock_gettime(clk_id, tp)) < 0 ) && (retry_count ++ < 3)) {
			mysleep(0, 100);
		}

		if(ret < 0) {
			flag = 1;
			fprintf(std_err, "clock_gettime error[%s]", strerror(errno));
		}
	}
	
	if(flag) {
		tp->tv_sec = get_uptime();
		tp->tv_nsec = 0;
		flag = 1;
	}
#endif

	return 0;
}
示例#7
0
文件: mypthread.c 项目: yomei-o/mario
int main()
{
	my_pthread_create(subthread, NULL);

	mysleep(2);
	printf("main thread end\n");
}
void draw_polygons(struct polygon* polygons, int number_of_polygons,int delay){
	if(h==0){
		h = gnuplot_init();
		gnuplot_cmd(h, "clear");
		gnuplot_cmd(h,"reset");
		//gnuplot_cmd(h,"set terminal gif animate ");
		//gnuplot_cmd(h,"set output \"animate.gif\"");
		gnuplot_cmd(h,"set terminal gif small animate delay 7");
		gnuplot_cmd(h,"set output \"animate.gif\"");
		gnuplot_cmd(h, "set isosample 40" );
		gnuplot_cmd(h, "set xrange [-5:5]");
		gnuplot_cmd(h, "set yrange [-5:5]");
		puts("Initiating polygon drawing\n");
	}	
	int i,j;
	gnuplot_cmd(h,"unset arrow");
	gnuplot_cmd(h, "set style arrow 1 nohead")	;
	for(j=0;j<number_of_polygons;j++){
		for(i=0;i<polygons[j].numberOfVertices-1;i++){	
			gnuplot_resetplot(h);
			gnuplot_cmd(h, "set arrow from %f,%f to %f,%f as 1",polygons[j].x_list[i], polygons[j].y_list[i],polygons[j].x_list[i+1], 
					polygons[j].y_list[i+1]);
		}
	}
	gnuplot_cmd(h, "plot[-5:5][-5:5] NaN notitle");
	gnuplot_cmd(h,"set size square");
	mysleep(delay);
}
void draw_polys_configSpace(unsigned int cs_size, double **configSpace,int number_of_polygons, struct polygon *polygons,unsigned int delay){
	int i,j,k;
	if(h==0){
		h = gnuplot_init();
		gnuplot_cmd(h, "clear");
		gnuplot_cmd(h,"reset");
		gnuplot_cmd(h,"set terminal gif small animate delay 2 optimize");
		gnuplot_cmd(h,"set output \"animate.gif\"");
//		gnuplot_cmd(h,"set terminal postscript color");
//		gnuplot_cmd(h,"set output \"plot1.ps\"");
		gnuplot_cmd(h, "set isosample 40" );
		gnuplot_cmd(h, "set xrange [-4:4]");
		gnuplot_cmd(h, "set yrange [-4:4]");
	}	
	gnuplot_cmd(h,"set multiplot layout 1, 2;");
	// plot polygon
	gnuplot_cmd(h, "set style arrow 1 nohead")	;
	for(j=0;j<number_of_polygons;j++){
		for(i=0;i<polygons[j].numberOfVertices-1;i++){	
			gnuplot_cmd(h, "set arrow from %2.4f,%2.4f to %2.4f,%2.4f as 1",polygons[j].x_list[i], polygons[j].y_list[i],polygons[j].x_list[i+1], 
					polygons[j].y_list[i+1]);
		}
	}
	gnuplot_cmd(h,"set size square");
	gnuplot_cmd(h, "plot [-4:4][-4:4] NaN title \"Work Space\"");
	gnuplot_cmd(h,"unset arrow");
	// plot configSpace
	gnuplot_cmd(h,"splot [-3.1:3.1][-3.1:3.1][-3.1:3.1] \"-\" using 1:2:3 with points pointtype 26 ps 0.3 title \"Configuration Space\" ");
	for(i=0;i<cs_size;i++){
			gnuplot_cmd(h,"%f %f %f", configSpace[i][0], configSpace[i][1], configSpace[i][2]);	
	}
	gnuplot_cmd(h,"e");
	gnuplot_cmd(h,"unset multiplot");	
	mysleep(delay);
}
示例#10
0
文件: main.c 项目: camilo1729/distem
void* thread_fn(void* arg) {
	lli slee, start, end;
	lli loops_ps = loops_per_sec;
	double lratio = 1.0 - ratio;
	double wratio = lratio / (1. - lratio);
	lli loops, i;
	int syncl = sync_barrier;
	int local_finish;
	long long int interval = *((long long int*)arg);
	while(1)
	{
		r_lock();  /* begin reading */
		if (syncl) {
			pthread_barrier_wait(&barrier); // this can't fail according to docs
		}
		local_finish = finished;
		r_unlock();

		if (local_finish) {
			break;
		}

		start = GET_TIME();
		mysleep(interval);
		end = GET_TIME();
		slee = end - start;
		loops = (lli)(loops_ps * slee * wratio / 1000000.0);
		for (i=0; i < loops; i++) {
			LOOP();
		}
	}
	return 0;
}
示例#11
0
文件: sleep.c 项目: walker-zheng/code
int main(void)
{
    while(1){
        mysleep(2);
        printf("Two seconds passed\n");
    }
    return 0;
}
void think(int i)
{
  int milliseconds = random() % 1000;

  printf("philosopher %d is thinking for %d milliseconds...\n", i,
	 milliseconds);

  mysleep(milliseconds);
}
void eat(int i)
{
  int milliseconds = random() % 1000;

  eatcount[i]++;

  printf("\tphilosopher %d is eating for %d milliseconds...\n", i,
	 milliseconds);

  mysleep(milliseconds);
}
示例#14
0
int main()
{
	int i;
	for (i = 1; i <= 100; ++i)
	{
		progressBar(i);
		mysleep(1);
	}
	printf("/n");
	return 0;
}
示例#15
0
int main()
{
	int i;

	for(i = 0; i < 100; i++) {
		mysleep(1);
		printf("This is i=[%d]\n", i);
	}

	return 0;
}
示例#16
0
文件: mypthread.c 项目: yomei-o/mario
/* サブスレッド */
void subthread(void* vp)
{
	int i;

	printf("sub thread start\n");

	for(i=0; i<5; i++){
		printf("-\n");
		mysleep(1);
	}
	
	printf("sub thread end\n");	
}
示例#17
0
void lcd_init(int fd)
{
    lcd_write(fd, 0x03, 0);
    lcd_write(fd, 0x03, 0);
    lcd_write(fd, 0x03, 0);
    lcd_write(fd, 0x02, 0);

    lcd_write(fd, LCD_FUNCTIONSET | LCD_2LINE | LCD_5x8DOTS | LCD_4BITMODE, 0);
//   lcd_write(fd, LCD_FUNCTIONSET | LCD_2LINE | LCD_5x8DOTS | LCD_8BITMODE, 0);
    lcd_write(fd, LCD_DISPLAYCONTROL | LCD_DISPLAYON, 0);
    lcd_write(fd, LCD_CLEARDISPLAY, 0);
    lcd_write(fd, LCD_ENTRYMODESET | LCD_ENTRYLEFT, 0);
    mysleep(200);
}
示例#18
0
void
logout_all(void)
{
  register int i;

  printf("Are you are you want to logout all users on the BBS? (Y/N) -> ");
  if (yesno(-1))
  {
    printf("\nLogging off all users...");
    fflush(stdout);
    for (i = 0; i < MAXUSERS; i++)
      if (bigbtmp->btmp[i].pid != pid)
        logout_user(NULL, &bigbtmp->btmp[i], 0);
    mysleep(10);
    printf("\n\nForcing off any stragglers...");
    fflush(stdout);
    for (i = 0; i < MAXUSERS; i++)
      if (bigbtmp->btmp[i].pid != pid)
        logout_user(NULL, &bigbtmp->btmp[i], 1);
    mysleep(5);
    putchar('\n');
  }
}
void NetWorkTest::checkSite(QString url) {
  QUrl qrl(url);
  manager = new QNetworkAccessManager(this);
  loop = new QEventLoop();

  connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));

  status = -1;

  while(status != 0){
    mysleep(5000);
    manager->get(QNetworkRequest(qrl));
    loop->exec();
  }

}
示例#20
0
void
server_sig_int(int signo)
{
  int i, j;
  unsigned char buff[5];
  ServerRealm** scRealmsTable;
  
#ifdef HAVE_LIBPTHREAD
  if (!is_this_a_mainthread()) {
    return;
  }
#endif

  for (j = 0; j < ServerConfiguration_get_realmsNumber(config); ++j) {
    scRealmsTable = ServerConfiguration_get_realmsTable(config);
    buff[0] = AF_S_CLOSING; /* closing */
    for (i = 0; i < ServerRealm_get_clientsLimit(scRealmsTable[j]); ++i) {
      if (ConnectClient_get_state(ServerRealm_get_clientsTable(scRealmsTable[j])[i]) ==
          CONNECTCLIENT_STATE_ACCEPTED) {
        SslFd_send_message(ServerRealm_get_realmType(scRealmsTable[j]),
            ConnectClient_get_sslFd(
              ServerRealm_get_clientsTable(scRealmsTable[j])[i]),
            buff, 5);
        close(SslFd_get_fd(ConnectClient_get_sslFd(
                ServerRealm_get_clientsTable(scRealmsTable[j])[i])));
      }
    }
    for (i = 0; i < ServerRealm_get_raClientsLimit(scRealmsTable[j]); ++i) {
      if (ConnectClient_get_state(ServerRealm_get_raClientsTable(scRealmsTable[j])[i]) ==
          CONNECTCLIENT_STATE_ACCEPTED) {
        SslFd_send_message(ServerRealm_get_realmType(scRealmsTable[j]) | TYPE_SSL,
            ConnectClient_get_sslFd(
              ServerRealm_get_raClientsTable(scRealmsTable[j])[i]),
            buff, 5);
        close(SslFd_get_fd(ConnectClient_get_sslFd(ServerRealm_get_raClientsTable(scRealmsTable[j])[i])));
      }
    }

  }

  /* FIXME: give a time to close all connections */
  mysleep(0.1);

  aflog(LOG_T_MAIN, LOG_I_NOTICE,
      "SERVER CLOSED cg: %ld bytes", getcg());
  exit(0);
}
示例#21
0
// function we are going to run as a thread
void *write_thread(void *arg)
{
    unsigned long delay = (unsigned long)arg;
    long count = 0;
    char buff[100];

    while (++count)
    {
        sprintf(buff, "%ld Counting up: %ld\n", delay, count);
        mysleep(delay);
        myprints(buff);
    }

    myprints("Write thread is exiting!\n");

    return NULL;
}
示例#22
0
#else

            mkdir(rpath,0777);

#endif

		}

	}

}





CKSLog::CKSLog()

{

   Init();

}



CKSLog::~CKSLog()

{

	CloseFile();

}



bool CKSLog::SetFileMode(char *pszFilePath, char *pszFileHead, char *pszFileExt, unsigned int dwFileOpt)

{

	m_dwFileOpt =  dwFileOpt;

	if(strlen(pszFilePath) >= sizeof(m_szFilePath) 
int main(int argc, char **argv)
{
  int i;
  pthread_t thread[N];        // each of the N philosophers

  done = 0;
  pthread_mutex_init(&mutex, NULL);
  for (i = 0; i < N; i++) {
    pthread_cond_init(&s[i], NULL);
    eatcount[i] = 0;
  }

  for (i = 0; i < N; i++) {   // create N philosopher threads
    if (pthread_create(&thread[i], NULL, (void *) philosopher, (void *) i)
	!= 0) {
      perror("pthread_create");
      return 1;
    }
  }

  mysleep(DURATION*100);     // sleep for DURATION seconds

  done = 1;                   // have everybody stop

  for (i = 0; i < N; i++) {   // wait for each philosopher to to finish
    if (pthread_join(thread[i], NULL) != 0) {  // NOTE:  in order 0..N-1
      perror("pthread_join");
      return 2;
    }
  }

  // destroy all mutex
  pthread_mutex_destroy(&mutex);
  for (i = 0; i < N; i++) {
    pthread_cond_destroy(&s[i]);
  }

  printf("\n");
  for (i = 0; i < N; i++) {
    printf("Philosopher %d got to eat %d times\n", i, eatcount[i]);
  }

  return 0;
}
示例#24
0
void CRASHREPORTER_init(void){
  running_time.start();
  
#if defined(FOR_WINDOWS)
  CRASHREPORTER_windows_init();

#elif defined(FOR_LINUX)
      
  CRASHREPORTER_posix_init();

#elif defined(FOR_MACOSX)

#else
# error "Unknown machine"

#endif

  mysleep(1000);
}
void draw_configSpace(unsigned int cs_size,double **configSpace, int delay){
	int i,j;
	if(h==0){
		h = gnuplot_init();
		gnuplot_cmd(h, "clear");
		gnuplot_cmd(h,"reset");
		gnuplot_cmd(h,"set terminal gif animate animate delay 1 ");
		gnuplot_cmd(h,"set output \"animate.gif\"");
		gnuplot_cmd(h, "set xrange [-4:4]");
		gnuplot_cmd(h, "set yrange [-4:4]");
		gnuplot_cmd(h, "set zrange [-4:4]");
		printf("initializing draw cs \n");
	}
	gnuplot_cmd(h,"splot \"-\" using 1:2:3 with points pointtype 26 ps 0.3 lt palette");
	for(i=0;i<cs_size;i++){
		gnuplot_cmd(h,"%f %f %f", configSpace[i][0], configSpace[i][1], configSpace[i][2]);	
	}
	gnuplot_cmd(h,"e");
	mysleep(delay);
}
示例#26
0
int main(int argc, char **argv)
{
#if 0
	int ret = -1;
	struct sigaction act = {0};
	act.sa_handler = signal_func;
	
	ret = sigaction(SIGALRM, &act, NULL);
	
	ret = alarm(5);
	printf("1st, ret = %d.\n", ret);	// 1st, ret = 0.
	sleep(3);
	
	ret = alarm(5);		
	printf("2st, ret = %d.\n", ret);	// 2st, ret = 2.
	sleep(1);
	
	ret = alarm(5);
	printf("3st, ret = %d.\n", ret);	// 3st, ret = 4.

#if 0
	while (1);
#endif

#if 1
	pause();
#endif
#endif

#if 1
	// 使用alarm和pause来模拟sleep
	printf("before mysleep.\n");
	mysleep(3);
	printf("after mysleep.\n");
#endif
	
	return 0;
}
int main(int argc, char **argv)
{
  int i;
  pthread_t thread[N];        // each of the N philosophers

  done = 0;
  mutex = 1;                  // normal initialization of mutex
  for (i = 0; i < N; i++) {
    s[i] = 0;                 // initially all philosopher sems will block
    eatcount[i] = 0;
  }

  for (i = 0; i < N; i++) {   // create N philosopher threads
    if (pthread_create(&thread[i], NULL, (void *) philosopher, (void *) i)
	!= 0) {
      perror("pthread_create");
      return 1;
    }
  }

  mysleep(DURATION*1000);     // sleep for DURATION seconds

  done = 1;                   // have everybody stop

  for (i = 0; i < N; i++) {   // wait for each philosopher to to finish
    if (pthread_join(thread[i], NULL) != 0) {  // NOTE:  in order 0..N-1
      perror("pthread_join");
      return 2;
    }
  }

  printf("\n");
  for (i = 0; i < N; i++) {
    printf("Philosopher %d got to eat %d times\n", i, eatcount[i]);
  }

  return 0;
}
示例#28
0
文件: int.c 项目: bhanderson/cpts460
int kcinth()
{
	ushort seg, off, r;
	int    x, y, z, w;

	seg = running->uss; off = running->usp;

	x = get_word(seg, off + 2*13);
	y = get_word(seg, off + 2*14);
	z = get_word(seg, off + 2*15);
	w = get_word(seg, off + 2*16);

	switch(x){
		case 0 : r = running->pid;		break;
		case 1 : r = do_ps();			break;
		case 2 : r = chname(y);			break;
		case 3 : r = kmode();			break;
		case 4 : r = tswitch();			break;
		case 5 : r = do_wait(y);		break;
		case 6  : r = do_exit(y);		break;

		case 7  : r = ufork();			break;
		case 8 :  r = exec(y);			break;

		case 9 : r = chcolor(y);		break;

		case 10: r = putc(y);			break;

		case 11: mysleep(y);		break;

		case 99 : do_exit(y);			break;

		default: printf("invalid syscall # : %d\n", x);
				 break;
	}
	put_word(r, seg, off + 2*8);
}
示例#29
0
int main(int argc,char *argv[])
{
   int rtn;
   openlog("yktbu",LOG_PID|LOG_CONS|LOG_NDELAY,LOG_LOCAL0);
   g_pSvrLink = BUPubInitialize(g_XBDefines,CallBDFunc,WriteAppInfo,&g_LogFile);
   SetLogShowLevel(0);   
   sprintf(g_szVerNo,"%s %s (%s)",argv[0],YKT_VERSION,__DATE__);
   if(argc==2)
   {
	   if(strncmp(argv[1],"-v",2)==0||strncmp(argv[1],"-V",2)==0)
	   {
		  printf("%s\n",g_szVerNo);
		  closelog();
		  return 0;
	   }
   }
   if (argc<2)
      ReadIni("ksbu.ini");
   else
      ReadIni(argv[1]);

   ResetBPFunctions();
   if (argc>2)
   {
      ListBPFunctions(argv[2]);
   }

   // 初始化数据库连接:
   SQLInitialize();
   if (SQLConnectToServer()!=0)
   {
      DEBUG_RUNTIME_MSGOUT("不能正常建立数据库连接, 检查配置和数据库服务器!\n");
      return(-100);
   }
	 DEBUG_RUNTIME_MSGOUT("连接数据库成功!\n");
   CAccTrans& ats=CAccTrans::GetInst();
   if(ats.LoadCfg()!=0)
   {
	 	
			DEBUG_RUNTIME_MSGOUT("加载系统参数失败!\n");
	   //RAISE_RUNTIME_ERROR("加载数据库账务配置参数失败!\n");
			return(-200);
   }
	 DEBUG_RUNTIME_MSGOUT("加载系统参数成功!\n");
   // 初始化与BCC连接:
   do 
   {
      rtn = g_pSvrLink->ToLink(&g_BUnit);
      if (rtn==1)
      {
         DEBUG_RUNTIME_MSGOUT("与业务调度中心(BCC)的连接成功!\n");
         break;
      }
      else if (rtn==-100)
      {
         DEBUG_RUNTIME_MSGOUT("估计业务调度中心(BCC)尚未正式启动,或者检查配置中的[SERVER]项参数\n");
         mysleep(g_BUnit.iHBInterval);
      }
      else
      {
         // 应该属于故障,或对方并不是BCC
         return(rtn);
      }
   } while (1);
#ifdef WIN32
   setnoblockgetch();
#endif

   while (g_pSvrLink->LinkOK())
   {
#ifdef WIN32
      switch (mygetch())
      {
      case '?':
      case 'h':
      case 'H':
         printf("\nCommand List:\n");
         printf("\t ? or h: display this Help informations!\n");
         printf("\t x: To eXit this business unit.\n");
         printf("\t d: Display functions status.\n");
         printf("\t l: List functions status into <function.lst>.\n");
         printf("Enter command to select:");
         break;
      case 'x':
      case 'X':
         g_pSvrLink->bExit = true;
         continue;
         break;
      case 'd':
      case 'D':
         ListBPFunctions(NULL);
         break;
      case 'l':
      case 'L':
         ListBPFunctions("function.lst");
         break;
      }
#endif
      if (!SQLIsConnectOK())
      {
         mysleep(1000);
         if (!g_pSvrLink->CheckLink()) 
            break;  // BCC exit (可能用户发现数据库连接断开,需要维护系统,导致手工将BCC退出同时也需要BU退出)
         if (SQLConnectToServer()!=0)
         {
            // SQL Link error:
            DEBUG_RUNTIME_MSGOUT("不能正常建立数据库连接, 检查配置和数据库服务器!\n");
         }
         else
         {
            DEBUG_RUNTIME_MSGOUT("与数据库连接成功!\n");
         }
         continue;
      }
      else 
         g_pSvrLink->Processing(&g_BUnit);
      if (g_pSvrLink->bExit) break;
   }


/* ****** Updated by CHENYH at 2004-4-14 11:07:19 ****** 
   经过测试后,CheckLink()工作正常,测试环境为:BCC(WIN)+BU(WIN),BCC(LINUX)+BU(WIN),BCC(LINUX)+BU(LINUX)
   while (1)
   {
      mysleep(1000);
      if (!g_SvrLink.CheckLink())
      {
         printf("TEST CHECK LINK return <false>!\n");
         break;
      }
   }
*/
   g_pSvrLink->Close();
   SQLExit();
   DEBUG_RUNTIME_MSGOUT("业务处理单元BU系统正常退出!\n");
   g_LogFile.Close();
   closelog();
   return(0);
}
示例#30
0
int main(int argc, char* argv[])
{
	::CoInitialize(NULL);				// 结合SQL SERVER2000使用
	int rtn = 0;
	time_t cur_time;
	time_t last_time;
	time(&last_time);

	g_pSvrLink = BUPubInitialize(g_XBDefines,CallBDFunc,WriteAppInfo,&g_LogFile);
	SetLogShowLevel(0);
	if (argc<2)
		ReadIni("ksbu.ini");
	else
		ReadIni(argv[1]);

	ResetBPFunctions();
	if (argc>2)
	{
		ListBPFunctions(argv[2]);
	}
	
#ifdef _DYNAMIC_LOAD	
	// 加载对接第三方动态库
	if (rtn = g_LoadDll.LoadDataInfo("DataInfo.dll"))
	{
		g_LogFile.WriteLogEx(1002, "加载DataInfo.dll失败--错误码:[%d]", rtn);
		return rtn;
	}
	g_LogFile.WriteLogEx(1002, "加载DataInfo.dll成功");
#endif

	// 初始化第三方数据库信息
#ifdef SYNJONES_FUNC
	if (rtn = InitDB())
	{
		g_LogFile.WriteLogEx(1002, "初始化第三方数据库失败--错误码:[%d]", rtn);
		return rtn;
	}
	g_LogFile.WriteLogEx(1002, "初始化第三方数据库成功");
#endif
	
	// 初始化与BCC连接:
	do 
	{
		rtn = g_pSvrLink->ToLink(&g_BUnit);
		if (rtn==1)
		{
			DEBUG_RUNTIME_MSGOUT("与业务调度中心(BCC)的连接成功!\n");
			break;
		}
		else if (rtn==-100)
		{
			DEBUG_RUNTIME_MSGOUT("估计业务调度中心(BCC)尚未正式启动,或者检查配置中的[SERVER]项参数\n");
			mysleep(g_BUnit.iHBInterval);
		}
		else
		{
			// 应该属于故障,或对方并不是BCC
			return(rtn);
		}
	} while (1);
#ifdef WIN32
	setnoblockgetch();
#endif

	while (g_pSvrLink->LinkOK())
	{
#ifdef WIN32
		switch (mygetch())
		{
		case '?':
		case 'h':
		case 'H':
			printf("\nCommand List:\n");
			printf("\t ? or h: display this Help informations!\n");
			printf("\t x: To eXit this business unit.\n");
			printf("\t d: Display functions status.\n");
			printf("\t l: List functions status into <function.lst>.\n");
			printf("Enter command to select:");
			break;
		case 'x':
		case 'X':
			g_pSvrLink->bExit = true;
			continue;
			break;
		case 'd':
		case 'D':
			ListBPFunctions(NULL);
			break;
		case 'l':
		case 'L':
			ListBPFunctions("function.lst");
			break;
		}
#endif
		time(&cur_time);
		if (cur_time - last_time > g_ini_para.flash_dealy)
		{
			if (rtn = InitDB())
			{
				g_LogFile.WriteLogEx(1002, "初始化数据库失败:[%d]", rtn);
			}
			last_time = cur_time;
			g_LogFile.WriteLogEx(1002, "初始化数据库成功:[%d]", rtn);
		}

		g_pSvrLink->Processing(&g_BUnit);
		if (g_pSvrLink->bExit) break;
	}

	g_pSvrLink->Close();
	DEBUG_RUNTIME_MSGOUT("业务处理单元BU系统正常退出!\n");
	g_LogFile.Close();

#ifdef _DYNAMIC_LOAD
	CloseDB();
	g_LoadDll.UnLoadAllDll();
#endif
	
	::CoUninitialize();
	return(0);
}