Example #1
0
void task_queue::enqueue_internal(task* task)
{
    auto& sp = task->spec();
    auto throttle_mode = sp.rpc_request_throttling_mode;
    if (throttle_mode != TM_NONE)
    {        
        int ac_value = 0;
        if (_spec->enable_virtual_queue_throttling)
        {
            ac_value = _virtual_queue_length;
        }
        else
        {
            ac_value = count();
        }
               
        if (throttle_mode == TM_DELAY)
        {
            int delay_ms = sp.rpc_request_delayer.delay(ac_value, _spec->queue_length_throttling_threshold);
            if (delay_ms > 0)
            {
                auto rtask = static_cast<rpc_request_task*>(task);
                rtask->get_request()->io_session->delay_recv(delay_ms);

                dwarn("too many pending tasks (%d), delay traffic from %s for %d milliseconds",
                    ac_value,
                    rtask->get_request()->header->from_address.to_string(),
                    delay_ms
                    );
            }
        }
        else
        {
            dbg_dassert(TM_REJECT == throttle_mode, "unknow mode %d", (int)throttle_mode);

            if (ac_value > _spec->queue_length_throttling_threshold)
            {
                auto rtask = static_cast<rpc_request_task*>(task);
                auto resp = rtask->get_request()->create_response();
                task::get_current_rpc()->reply(resp, ERR_BUSY);

                dwarn("too many pending tasks (%d), reject message from %s with trace_id = %016" PRIx64,
                    ac_value,
                    rtask->get_request()->header->from_address.to_string(),
                    rtask->get_request()->header->trace_id
                    );

                task->release_ref(); // added in task::enqueue(pool)
                return;
            }
        }
    }

    tls_dsn.last_worker_queue_size = increase_count();
    enqueue(task);
}
Example #2
0
void simple_bus::write(unsigned int unique_priority
                       , int *data
                       , unsigned int address
                       , bool lock)
{
    if (m_verbose)
        sb_fprintf(stdout, "%g %s : write(%d) @ %x\n",
                   sc_time_stamp().to_double(), name(), unique_priority, address);

    simple_bus_request *request = get_request(unique_priority);

    // abort when the request is still not finished
    sc_assert((request->status == SIMPLE_BUS_OK) ||
              (request->status == SIMPLE_BUS_ERROR));

    request->do_write           = true; // we are writing
    request->address            = address;
    request->end_address        = address;
    request->data               = data;

    if (lock)
        request->lock = (request->lock == SIMPLE_BUS_LOCK_SET) ?
                        SIMPLE_BUS_LOCK_GRANTED : SIMPLE_BUS_LOCK_SET;

    request->status = SIMPLE_BUS_REQUEST;
}
Example #3
0
	void* handle_requests_loop(void* data)
	{
	int rc;                         /* return code of pthreads functions.  */
	struct request* a_request;      /* pointer to a request.               */
	int thread_id = *((int*)data);  /* thread identifying number           */

	/* lock the mutex, to access the requests list exclusively. */
	rc = pthread_mutex_lock(&request_mutex);

	while (1) {
	   if (num_requests > 0) { /* a request is pending */
	      a_request = get_request(&list_mutex);
	      /* got a request */
	      if (a_request) {
	         /*handle request */
	         handle_request(a_request, thread_id);
	         /* free it */
	         free(a_request);
	         }
	      }
	   else {
	      if (quit) {
	         pthread_mutex_unlock(&request_mutex); // unlock mutex before exit
	         pthread_exit(NULL);
	         }
	      rc = pthread_cond_wait(&got_request, &request_mutex);
	      }
	   }
	}
Example #4
0
/*
 * Provides information regarding a handle, ie. if a communication operation has been completed.
 * If the operation has been completed the predicate succeeds with the completion status,
 * otherwise it fails.
 *
 * mpi_test(+Handle,-Status,-Data).
 */
static YAP_Bool 
mpi_test_recv(void) {
  YAP_Term t1 = YAP_Deref(YAP_ARG1); // data

  MPI_Status status;
  MPI_Request *handle;
  int flag,len,ret;
  char *s;
  YAP_Term out;

  // The first argument (handle) must be an integer
  if(!YAP_IsIntTerm(t1)) {
    return false;
  }
  CONT_TIMER();

  handle=INT2HANDLE(YAP_IntOfTerm(t1));
  //
  if( MPI_CALL(MPI_Test( handle , &flag, &status ))!=MPI_SUCCESS) {
    PAUSE_TIMER();
    return false;
  }
  s=(char*)get_request(handle);
  len=strlen(s);
  out = string2term(s,(size_t*)&len);
  // make sure we only fetch ARG3 after constructing the term
  ret=YAP_Unify(YAP_ARG3,out);
  free_request(handle);
  PAUSE_TIMER();
  return(ret & YAP_Unify(YAP_ARG2,YAP_MkIntTerm(status.MPI_ERROR)));
}
Example #5
0
/*
 * handle_requests_loop(): 处理请求的无限循环
 * 算法:如果有请求要处理,取第一个处理。然后守候指定条件变量,收到信号后
 *       重新开始循环,并把待处理的请求数加 1。
 */
void*
handle_requests_loop(void* data)
{
    int rc;	                    /* pthread 函数的返回值  */
    struct request* a_request;      /* 请求指针              */
    int thread_id = *((int*)data);  /* 线程序号              */

    /* 锁定 mutex,以保证排它性访问链表 */
    rc = pthread_mutex_lock(&request_mutex);

    /* 无限循环 ... */
    while (1) {
	if (num_requests > 0) {
	    a_request = get_request(&request_mutex);
	    if (a_request) {
		handle_request(a_request, thread_id);
		free(a_request);
	    }
	}
	else {
            /* 等待请求抵达:解锁——守候——锁定——返回 */
	    rc = pthread_cond_wait(&got_request, &request_mutex);
	}
    }
}
Example #6
0
void *GallocyServer::handle(int client_socket, struct sockaddr_in client_name) {
  Request *request = get_request(client_socket);
  request->peer_ip = utils::parse_internet_address(inet_ntoa(client_name.sin_addr));
  Response *response = routes.match(request->uri)(request);

  if (send(client_socket, response->str().c_str(), response->size(), 0) == -1) {
    error_die("send");
  }

  LOG_INFO(request->method
    << " "
    << request->uri
    << " - "
    << "HTTP " << response->status_code
    << " - "
    << inet_ntoa(client_name.sin_addr)
    << " "
    << request->headers["User-Agent"]);

  // Teardown
  request->~Request();
  internal_free(request);
  response->~Response();
  internal_free(response);

  shutdown(client_socket, SHUT_RDWR);
  close(client_socket);

  return nullptr;
}
Example #7
0
static int		get_ressources(t_conf *conf,void *req,
				       int in_len, struct sockaddr_in *sa)
{
  int			out_len = -1;
  char			buffer[MAX_HOST_NAME_ENCODED + 1];
  int			len;
  t_packet		*packet;

  if ((len = get_request(req, buffer, conf, sa)) == -1)
    return (-1);
  packet = (void *)&buffer;
  if (! packet->type)
    out_len = build_ressources_reply(conf, req, in_len);
  else
    out_len = login_user(conf, req, buffer, in_len, sa);
  if (out_len == -1)
    {
      MYERROR("parsing error\n");
      return (-1);
    }
  if ((out_len = sendto(conf->sd_udp, req, out_len, 
			0, (struct sockaddr *)sa, sizeof(struct sockaddr))) == -1)
    {
      MYERROR("send error\n");
      return (-1);
    }
  return (0);
 }
Example #8
0
Promise<void> Client::ClientSession (
    String access_token,
    String profile_id,
    String server_id,
    const Vector<Byte> & secret,
    const Vector<Byte> & public_key
) {

    //	Create JSON request
    JSON::Object obj;
    obj.Add(
        session_token_key,
        std::move(access_token),
        session_profile_key,
        std::move(profile_id),
        session_server_id_key,
        get_hash(server_id,secret,public_key)
    );

    //	We have to use a custom URL
    auto request=get_request(std::move(obj));
    request.URL=String::Format(
                    session_url,
                    client_session_endpoint
                );

    //	Dispatch
    return dispatch<void>(std::move(request));

}
int main()
{
	//FT_HANDLE fthandle=scan_device();
	//float t;
	//char entry[MAX_ENTRY];
	char *request=NULL;
	printf("Content-type: text/plain\n\n");
#if DEBUG
	request=get_request();
	parse_request(request);
#else
	request=get_request();
	parse_request(request);
#endif
	return 0;
}
Example #10
0
/** mpi_wait(+Handle,-Status,-Data
 *   
 *  Completes a non-blocking operation. IF the operation was a send, the
 * function waits until the message is buffered or sent by the runtime
 * system. At this point the send buffer is released. If the operation
 * was a receive, it waits until the message is copied to the receive
 * buffer.
 * .
 */
static YAP_Bool 
mpi_wait_recv(term_t YAP_ARG1,...) {
  YAP_Term t1 = YAP_Deref(YAP_ARG1); // data
  MPI_Status status;
  MPI_Request *handle;
  char *s;
  int ret;
  size_t len;
  YAP_Term out;

  // The first argument (handle) must be an integer
  if(!YAP_IsIntTerm(t1)) {
    return false;
  }
  CONT_TIMER();

  handle=INT2HANDLE(YAP_IntOfTerm(t1));
  s=(char*)get_request(handle);
  // wait for communication completion
  if( MPI_CALL(MPI_Wait( handle , &status )) != MPI_SUCCESS) {
    PAUSE_TIMER();
    return false;
  }
  len=YAP_SizeOfExportedTerm(s);
  // make sure we only fetch ARG3 after constructing the term
  out = string2term(s,(size_t*)&len);
  MSG_RECV(len);
  free_request(handle);
  PAUSE_TIMER();
  ret=YAP_Unify(YAP_ARG3,out);
  return(ret & YAP_Unify(YAP_ARG2,YAP_MkIntTerm(status.MPI_ERROR)));
}
int main()
{
    int i; 
    int pri;
    IBP_REQUESTS_QUEUE * queue;
    IBP_REQUEST_POOL * pool;
    IBP_REQUEST *request;
    IBP_CONNECTION *conn;

    queue = init_req_queue(1024,400);
    glbReqPool = init_request_pool();
    for (i=0; i< 1024;i++){
        conn = init_connection(i);
        request = create_request(conn);
        set_request_priority(request,random()%400);
        append_request(queue,request);
    }

    for(i=0; i< 1024; i++){
        request=get_request(queue);
        free_request(pool,request);
    }


    fprintf(stderr,"Total allocated  = %d idle request = %d\n",
                    glbReqPool->allocated,glbReqPool->num);
    delete_req_queue(queue);
    delete_request_pool(glbRequestPool);

    return 0;
}
Example #12
0
simple_bus_status simple_bus::burst_write(unsigned int unique_priority
        , int *data
        , unsigned int start_address
        , unsigned int length
        , bool lock)
{
    if (m_verbose)
        sb_fprintf(stdout, "%g %s : burst_write(%d) @ %x\n",
                   sc_time_stamp().to_double(), name(), unique_priority,
                   start_address);

    simple_bus_request *request = get_request(unique_priority);

    request->do_write           = true; // we are writing
    request->address            = start_address;
    request->end_address        = start_address + (length-1)*4;
    request->data               = data;

    if (lock)
        request->lock = (request->lock == SIMPLE_BUS_LOCK_SET) ?
                        SIMPLE_BUS_LOCK_GRANTED : SIMPLE_BUS_LOCK_SET;

    request->status = SIMPLE_BUS_REQUEST;

    wait(request->transfer_done);
    wait(clock->posedge_event());
    return request->status;
}
Example #13
0
value hxfcgi_add_header(value hreq,value type,value value) {
	val_check(type,string);
	val_check(value,string);
	hxfcgi::Request *req = get_request(hreq);
	req->addHeader(val_string(type),val_string(value));
	return val_null;	
}
Example #14
0
/* read HTTP request from sockfd, parse it into command
 * and its parameters (for instance, command='udp' and
 * parameters being '192.168.0.1:5002')
 */
static int
read_command( int sockfd, struct server_ctx *srv)
{
#define DBUF_SZ 2048  /* max size for raw data with HTTP request */
#define RBUF_SZ 512   /* max size for url-derived request */
    char httpbuf[ DBUF_SZ ] = "\0", request[ RBUF_SZ ] = "\0";
    ssize_t hlen;
    size_t  rlen;
    int rc = 0;

    assert( (sockfd > 0) && srv );

    TRACE( (void)tmfprintf( g_flog,  "Reading command from socket [%d]\n",
                            sockfd ) );
usleep(50);  /* ..workaround VLC behavior: wait for receiving entire HTTP request, one packet per line */
    hlen = recv( sockfd, httpbuf, sizeof(httpbuf), 0 );
    if( 0>hlen ) {
        rc = errno;
        if( !no_fault(rc) )
            mperror(g_flog, rc, "%s - recv (%d)", __func__, rc);
        else {
            TRACE( mperror(g_flog, rc, "%s - recv (%d)", __func__, rc) );
        }
        return rc;
    }
    if (0 == hlen) {
        (void) tmfprintf (g_flog, "%s: client closed socket [%d]\n",
            __func__, sockfd);
        return 1;
    }

    /* DEBUG - re-enable if needed */
    TRACE( (void)tmfprintf( g_flog, "HTTP buffer [%ld bytes] received\n%s", (long)hlen, httpbuf ) );
    /* TRACE( (void) save_buffer( httpbuf, hlen, "/tmp/httpbuf.dat" ) ); */

    rlen = sizeof(request);
    rc = get_request( httpbuf, (size_t)hlen, request, &rlen );
    if (rc) return rc;

    TRACE( (void)tmfprintf( g_flog, "Request=[%s], length=[%lu]\n",
                request, (u_long)rlen ) );

    rc = parse_auth( httpbuf, (size_t)hlen );
    TRACE( (void)tmfprintf( g_flog, "Auth result=[%d]\n",
                rc ) );
    if (rc) return rc;

    (void) memset( &srv->rq, 0, sizeof(srv->rq) );
    rc = parse_param( request, rlen, srv->rq.cmd, sizeof(srv->rq.cmd),
                srv->rq.param, sizeof(srv->rq.param),
                srv->rq.tail, sizeof(srv->rq.tail) );
    if( 0 == rc ) {
        TRACE( (void)tmfprintf( g_flog, "Command [%s] with params [%s], tail [%s]"
                    " read from socket=[%d]\n", srv->rq.cmd, srv->rq.param,
                        srv->rq.tail, sockfd) );
    }

    return rc;
}
Example #15
0
void* producer(void *arg)
{request_t *request;
	while(1)
	{request = get_request();
		add(request);
		sem_post(&requests_length);
	}
}
Example #16
0
value hxfcgi_print(value hreq,value msg) {
	val_check(msg,string);
	hxfcgi::Request *req = get_request(hreq);
	req->printHeaders();
	for (int i = 0; i < val_strlen(msg);i++)
		req->pchar(val_string(msg)[i]);
	return val_null;
}
/*
 * function handle_requests_loop(): infinite loop of requests handling
 * algorithm: forever, if there are requests to handle, take the first
 *            and handle it. Then wait on the given condition variable,
 *            and when it is signaled, re-do the loop.
 *            increases number of pending requests by one.
 * input:     id of thread, for printing purposes.
 * output:    none.
 */
void*
handle_requests_loop(void* data)
{
    int rc;	                    /* return code of pthreads functions.  */
    struct request* a_request;      /* pointer to a request.               */
    int thread_id = *((int*)data);  /* thread identifying number           */

#ifdef DEBUG
    printf("Starting thread '%d'\n", thread_id);
    fflush(stdout);
#endif /* DEBUG */

    /* lock the mutex, to access the requests list exclusively. */
    rc = pthread_mutex_lock(&request_mutex);

#ifdef DEBUG
    printf("thread '%d' after pthread_mutex_lock\n", thread_id);
    fflush(stdout);
#endif /* DEBUG */

    /* do forever.... */
    while (1) {
#ifdef DEBUG
    	printf("thread '%d', num_requests =  %d\n", thread_id, num_requests);
    	fflush(stdout);
#endif /* DEBUG */
	if (num_requests > 0) { /* a request is pending */
	    a_request = get_request(&request_mutex);
	    if (a_request) { /* got a request - handle it and free it */
    		/* unlock mutex - so other threads would be able to handle */
		/* other reqeusts waiting in the queue paralelly.          */
    		rc = pthread_mutex_unlock(&request_mutex);
		handle_request(a_request, thread_id);
		free(a_request);
    		/* and lock the mutex again. */
    		rc = pthread_mutex_lock(&request_mutex);
	    }
	}
	else {
	    /* wait for a request to arrive. note the mutex will be */
	    /* unlocked here, thus allowing other threads access to */
	    /* requests list.                                       */
#ifdef DEBUG
    	    printf("thread '%d' before pthread_cond_wait\n", thread_id);
    	    fflush(stdout);
#endif /* DEBUG */
	    rc = pthread_cond_wait(&got_request, &request_mutex);
	    /* and after we return from pthread_cond_wait, the mutex  */
	    /* is locked again, so we don't need to lock it ourselves */
#ifdef DEBUG
    	    printf("thread '%d' after pthread_cond_wait\n", thread_id);
    	    fflush(stdout);
#endif /* DEBUG */
	}
    }
}
Example #18
0
int main(int argc, char *argv[])
{
	int sockfd, numbytes;
	struct addrinfo hints, *servinfo, *p;
	int rv;
	char s[INET6_ADDRSTRLEN];

	if (argc != 2) {
	    fprintf(stderr,"usage: client hostname\n");
	    exit(1);
	}

	memset(&hints, 0, sizeof hints);
	hints.ai_family = AF_UNSPEC;
	hints.ai_socktype = SOCK_STREAM;

	if ((rv = getaddrinfo(argv[1], PORT, &hints, &servinfo)) != 0) {
		fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
		return 1;
	}

	// loop through all the results and connect to the first we can
	for(p = servinfo; p != NULL; p = p->ai_next) {
		if ((sockfd = socket(p->ai_family, p->ai_socktype,
				p->ai_protocol)) == -1) {
			perror("client: socket");
			continue;
		}

		if (connect(sockfd, p->ai_addr, p->ai_addrlen) == -1) {
			close(sockfd);
			perror("client: connect");
			continue;
		}

		break;
	}

	if (p == NULL) {
		fprintf(stderr, "client: failed to connect\n");
		return 2;
	}

	inet_ntop(p->ai_family, get_in_addr((struct sockaddr *)p->ai_addr),
			s, sizeof s);
	printf("client: connecting to %s\n", s);

	freeaddrinfo(servinfo); // all done with this structure

	get_request(sockfd);
	// put_request(sockfd);
	close(sockfd);
	printf("socket closed\n");
	exit(1);
	return 0;
}
Example #19
0
static MCPP::HTTPRequest get_request (const String & endpoint, const JSON::Value & value) {

    auto retr=get_request(value);
    retr.URL=String::Format(
                 url,
                 endpoint
             );

    return retr;

}
Example #20
0
// Dispatcher thread function
void * dispatch(void * arg)
{
	request_queue_t request;
	while(1){
		request.m_socket = accept_connection(); 
		get_request( request.m_socket, request.m_szRequest); 
		if ( addRequest(request) == -1){
			printf("The request could not be added by dispatcher of pthread_id: %d\n", pthread_self());
		}
	}
}
Example #21
0
unsigned char * get_request_proxy(size_t * len)
{
  mute();
  unsigned char * ret = get_request(len);
  unmute();

  stack_ptr("get_request");
  StoreBuf(&ret);

  readenv(ret, len, "request");
  return ret;
}
Example #22
0
void* dealer_thread(){

  request recived_request;
  int new_conn;
  pid_t son;

  printf("[Dealer]Politica:%s\n",policy);

  sem_wait(sem_full);
  sem_wait(sem_buffer);


  printf("[Schedule]%p\n",buffer);


  recived_request=buffer->request_list[0];
  /*buffer->out++;*/

  new_conn=recived_request.socket_id;
  printf("[Schedule]Recebi do Buffer:%d\n",recived_request.socket_id);

  sem_post(sem_buffer);
  sem_post(sem_empty);

  /* Process request*/
  get_request(new_conn);

  /* Verify if request is for a page or script*/
  if(!strncmp(req_buf,CGI_EXPR,strlen(CGI_EXPR))){
    /*manda para um processo pelos pipes*/
    if((son=fork())==0){
      /*criar nova função para leitura de scripts e envior para a message queue*/
      strcpy(recived_request.request_type,"dinamic");
      strcpy(recived_request.request_file,req_buf);

      execute_script(new_conn);
    }
    waitpid(son,0,0);
  }
  else{
    strcpy(recived_request.request_type,"static");
    strcpy(recived_request.request_file,req_buf);
    pipe_write(0,recived_request);

  }

  sleep(20);
  // Terminate connection with client
  close(new_conn);

  printf("[Dealer]terminei serviço\n");

}
Example #23
0
value hxfcgi_get_params(value hreq) {
	hxfcgi::Request *req = get_request(hreq);
	hxfcgi::Data d;
	map<string,string> params = d.getParams((*req));
	value ret = alloc_array(params.size()*2);
	unsigned int c = 0;
	for (map<string,string>::iterator iter = params.begin(); iter!=params.end(); iter++, c++) {
		val_array_set_i(ret,2*c,alloc_string(iter->first.c_str()));
		val_array_set_i(ret,2*c+1,alloc_string(iter->second.c_str()));
	}
	return ret;
}
Example #24
0
void 
pthread_handle (void)
{
    int fd;
    for (;;) {
        struct request *get = get_request();
        if (get != NULL) {
            fd = (get->fd);
            client_process(fd);
        }
    }
    
}
Example #25
0
int main(int argc, char *argv[])
{
    int c; /* c must be int not char, because the value of KEY_RESIZE is 632. */

    char buf[BUFSIZ];
    enum request request; 
    request = REQ_VIEW_MAIN; 

    struct view *view;
    if (argc < 2) {
        printf("Usage: %s <dir/filename> <keyword>\n", argv[0]);
        return;
    }
    signal(SIGINT, quit);

    if (argc == 3) {
        snprintf(buf, sizeof(buf), FIND_CMDD, argv[1], argv[2]);
        string_copy(fmt_cmd, buf);
    }else{
        snprintf(buf, sizeof(buf), FIND_CMD, argv[1]);
        string_copy(fmt_cmd, buf);
    }
    
	init();
            
	while (view_driver(display[current_view], request)) 
    {
        int i;

        foreach_view (view, i)
            update_view(view);

        c = wgetch(status_win);     
        request = get_request(c);
        
        if ( request == REQ_SCREEN_RESIZE) {

            int height, width;

            getmaxyx(stdscr, height, width);

            wresize(status_win, 1, width);
            mvwin(status_win, height - 1, 0);
            wrefresh(status_win);
        }
    }

	quit(0);

    return 0;
}
Example #26
0
/* NFS Callback for NFS_getdirent */
static
void
getdirent_cb(uintptr_t token, int status, int num_entries, struct nfs_filename *filenames,
		int next_cookie) {
	dprintf(1, "*** nfsfs_dirent_cb: %d, %d, %d, %d\n", token, status, num_entries, next_cookie);

	NFS_DirRequest *rq = (NFS_DirRequest *) get_request(token);
	if (rq == NULL) {
		dprintf(0, "!!! nfsfs: Corrupt dirent callback, no matching token: %d\n", token);
		return;
	}

	Process *p = process_lookup(rq->p.pid);

	if (status != NFS_OK) {
		syscall_reply(process_get_tid(p), status_nfs2vfs(status));
		remove_request((NFS_BaseRequest *) rq);
		return;
	}


	// got it
	if (rq->cpos + num_entries >= rq->pos + 1) {
		dprintf(2, "found file, getting now\n");
		int status = SOS_VFS_ERROR;
		struct nfs_filename *nfile = &filenames[rq->pos - rq->cpos];
		if (nfile->size + 1 <= rq->nbyte) {
			memcpy(rq->buf, nfile->file, nfile->size);
			rq->buf[nfile->size] = '\0';
			status = nfile->size;
		} else {
			dprintf(0, "!!! nfs_getdirent_cb: Filename too big for given buffer! (%d) (%d)\n",
					nfile->size, rq->nbyte);
			status = SOS_VFS_NOMEM;
		}
		syscall_reply(process_get_tid(p), status);
		remove_request((NFS_BaseRequest *) rq);
	}
	// need later directory entry
	else if (next_cookie > 0) {
		dprintf(2, "Need more dir entries to get file\n");
		rq->cpos += num_entries;
		nfs_readdir(&nfs_mnt, next_cookie, IO_MAX_BUFFER, getdirent_cb, rq->p.token);
	}
	// error case, just return SOS_VFS_OK to say nothing read, its not an error just eof
	else {
		dprintf(2, "nfsfs_getdirent: didnt find file (%d)\n", rq->pos);
		syscall_reply(process_get_tid(p), SOS_VFS_EOF);
		remove_request((NFS_BaseRequest *) rq);
	}
}
Example #27
0
gboolean
load3d_xml_file (GtkWidget * widget, gpointer * data)
{
  GtkWidget *filew;

  filew =
    gtk_file_chooser_dialog_new ("Open xml file", NULL,
				 GTK_FILE_CHOOSER_ACTION_OPEN,
				 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
				 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL);
  if (gtk_dialog_run (GTK_DIALOG (filew)) == GTK_RESPONSE_ACCEPT)
    {
      char *filename;
      Elements3D *k3d = get_request (REQ_KUPA_3D);
      SetsContainer *setcon = get_request (REQ_KUPAS_3D);

      memset (k3d, 0, sizeof (Elements3D));
      sets3d_del (setcon->sets);

      filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filew));
      setcon->sets = interpret_sets3d_xml (filename);
#ifndef NDEBUG
      if (setcon->sets.nsets)
	{
	  *k3d = setcon->sets.sets[0];
	  fprintf (stderr,
		   "%s:%d: params: ncyls=%d, nsphers=%d,nmirages=%d\n",
		   __FILE__, __LINE__, k3d->ncyls, k3d->nsphers,
		   k3d->nmirages);
	  setcon->position = 0;
	}
#endif
    }
  gtk_widget_destroy (filew);
  visualization_generator (get_request (REQ_TENS));
  gdk_window_invalidate_rect (widget->window, NULL, TRUE);
  return FALSE;
}
Example #28
0
int
event_key_pressed (GtkWidget * widg, GdkEventKey * key, void *data)
{
  tensor *tens;

  tens = get_request (REQ_TENS);
  switch (key->hardware_keycode)
    {
    case 100 /* left */ :
      *tens = RotateCoord (0., 5. / 180. * M_PI, *tens);
      break;
    case 104 /* down */ :
      *tens = RotateCoord (5. / 180. * M_PI, 0., *tens);
      break;
    case 102 /* right */ :
      *tens = RotateCoord (0., -5. / 180. * M_PI, *tens);
      break;
    case 98 /* up */ :
      *tens = RotateCoord (-5. / 180. * M_PI, 0., *tens);
      break;
    case 43 /*H*/:
      *tens = RotateCoord (0., 1. / 180. * M_PI, *tens);
      break;
    case 44 /*J*/:
      *tens = RotateCoord (1. / 180. * M_PI, 0., *tens);
      break;
    case 45 /*K*/:
      *tens = RotateCoord (-1. / 180. * M_PI, 0., *tens);
      break;
    case 46 /*L*/:
      *tens = RotateCoord (0., -1. / 180. * M_PI, *tens);
      break;
    case 24 /*Q*/:
    case 9 /* esc */ :
      gtk_main_quit ();
      return 0;
    case 34 /* [ */ :
      move_box_position (-1);
      break;
    case 35 /* ] */ :
      move_box_position (1);
      break;
    default:
      printf ("HWKEY = %d\n", key->hardware_keycode);
      return 0;
    }
  visualization_generator (tens);
  gdk_window_invalidate_rect (widg->window, NULL, TRUE);
  return 0;
}
Example #29
0
void
move_box_position (int delta)
{
  SetsContainer *setcon = get_request (REQ_KUPAS_3D);
  Elements3D *k3d = get_request (REQ_KUPA_3D);
  GtkStatusbar *StatusBar = get_request (REQ_STATUSBAR);
  int max, pos;
  gchar *msg;

  max = setcon->sets.nsets;
  pos = setcon->position;
  pos += delta;
  if (pos < 0)
    pos = max - 1;
  if (pos >= max)
    pos = 0;
  setcon->position = pos;
  *k3d = setcon->sets.sets[pos];
  msg = g_strdup_printf ("%d/%d", pos + 1, max);
  gtk_statusbar_push (StatusBar, 0, msg);
  g_free (msg);
  // That is Not all
}
Example #30
0
int 
main(int argc,char **argv)
{
	FILE *fp;
	char ch;

	enum request request;
	request = REQ_VIEW_MAIN;
	
	
	fp = fopen("config","r+");
	if(fp == NULL)
		T_ERR("cannot read the file config!\nplease checkout the file is exist\n");
	
	argvs = argv;

	load_command(fp);
	fclose(fp);
	convert_command();
	
	command_type = parser_option(argc, argv);
	if(command_type == -1)
		exit(1);
	
	g_current = 0;
	g_change = 0;
#if CURSES_MOD == 1
	Init_Screen();
	mvwaddstr(stdscr,LINES/2,COLS/2,"Loading......");
#endif 
	
#if CURSES_MOD == 1
	while(view_control(request))
	{
		 ch = wgetch(status_win);
		 request = get_request(ch);
	}
#endif

#if CURSES_MOD == 1
	getch();
#endif

#if CURSES_MOD == 1
	quit(0);
#endif 

	return 0;
}