예제 #1
0
int BBSDirect::upkint() {
	int i;
	i = nrnmpi_upkint(recvbuf_);
#if debug
	printf("upkint returning %d\n", i);
#endif
	return i;
}
예제 #2
0
void BBSDirectServer::handle1(int size, int tag, int cid) {
	bbsmpibuf* recv;
	bbsmpibuf* send;
	char* key;
	int index;
	send = nil;
	recv = nrnmpi_newbuf(size);
	nrnmpi_ref(recv);
	nrnmpi_bbsrecv(cid, recv);
	++bbs_msg_cnt_;
	if (size > 0) {
		nrnmpi_upkbegin(recv);
	}
	switch (tag) {
	case POST_TODO:
		index = nrnmpi_upkint(recv); // the parent index
#if debug
printf("handle POST_TODO from %x when cross=%g\n", cid, hoc_cross_x_);
#endif
		BBSDirectServer::server_->post_todo(index, cid, recv);
		break;
	case POST_RESULT:
		index = nrnmpi_getid(recv);
#if debug
printf("handle POST_RESULT %d from %x when cross=%g\n", index, cid, hoc_cross_x_);
#endif
		BBSDirectServer::server_->post_result(index, recv);
		break;
	case POST:
		key = nrnmpi_getkey(recv);
#if debug
printf("handle POST %s from %x when cross=%g\n", key, cid, hoc_cross_x_);
#endif
		BBSDirectServer::server_->post(key, recv);
		break;
	case LOOK:
		key = nrnmpi_getkey(recv);
#if debug
printf("handle LOOK %s from %x when cross=%g\n", key, cid, hoc_cross_x_);
#endif
		if (BBSDirectServer::server_->look(key, &send)) {
			nrnmpi_bbssend(cid, LOOK_YES, send);
			nrnmpi_unref(send);
		}else{
			nrnmpi_bbssend(cid, LOOK_NO, nil);
		}
		break;
	case LOOK_TAKE:
		key = nrnmpi_getkey(recv);
#if debug
printf("handle LOOK_TAKE %s from %x when cross=%g\n", key, cid, hoc_cross_x_);
#endif
		if (BBSDirectServer::server_->look_take(key, &send)) {
#if debug
printf("handle sending back something\n");
#endif
			nrnmpi_bbssend(cid, LOOK_TAKE_YES, send);
			nrnmpi_unref(send);
		}else{
			nrnmpi_bbssend(cid, LOOK_TAKE_NO, nil);
		}
		break;
	case TAKE:
		key = nrnmpi_getkey(recv);
#if debug
printf("handle TAKE %s from %x when cross=%g\n", key, cid, hoc_cross_x_);
#endif
		if (BBSDirectServer::server_->look_take(key, &send)) {
#if debug
printf("handle sending back something\n");
#endif
			nrnmpi_bbssend(cid, TAKE, send);
			nrnmpi_unref(send);
		}else{
#if debug
printf("handle put_pending %s for %d\n", key, cid);
#endif
			BBSDirectServer::server_->put_pending(key, cid);
		}
		break;
	case LOOK_TAKE_TODO:
#if debug
printf("handle LOOK_TAKE_TODO for cid=%x\n", cid);
#endif
		index = BBSDirectServer::server_->look_take_todo(&send);
#if debug
printf("handle sending back id=%d\n", index);
#endif
		nrnmpi_bbssend(cid, index+1, send);
		if (index) {
			nrnmpi_unref(send);
		}			
		break;
	case LOOK_TAKE_RESULT:
		index = nrnmpi_getid(recv);
#if debug
printf("handle LOOK_TAKE_RESULT for %x pid=%d\n", cid, index);
#endif
		index = BBSDirectServer::server_->look_take_result(index, &send);
#if debug
printf("handle sending back id=%d\n", index);
#endif
		nrnmpi_bbssend(cid, index+1, send);
		if (index) {
			nrnmpi_unref(send);
		}
		break;
	case TAKE_TODO:
#if debug
printf("handle TAKE_TODO for %x\n", cid);
#endif
		if (server_->remaining_context_cnt_ > 0
		    && server_->send_context(cid)) {
#if debug
printf("handle sent back a context\n");
#endif
			break;
		}
		index = BBSDirectServer::server_->look_take_todo(&send);
		if (index) {
#if debug
printf("handle sending back id=%d\n", index);
#endif
			nrnmpi_bbssend(cid, index+1, send);		
			nrnmpi_unref(send);
		}else{
#if debug
printf("handle add_looking_todo\n");
#endif
			BBSDirectServer::server_->add_looking_todo(cid);
		}
		break;
	case HELLO:
#if debug
printf("handle HELLO from %x when cross=%g\n", cid, hoc_cross_x_);
#endif
		nrnmpi_pkbegin(recv);
		nrnmpi_enddata(recv);
		nrnmpi_bbssend(cid, HELLO, recv);
		break;
	default:
printf("unknown message\n");
		break;
	}
	nrnmpi_unref(recv);
}