Ejemplo n.º 1
0
void zmq::stream_engine_t::mechanism_ready ()
{
    if (options.recv_identity) {
        msg_t identity;
        mechanism->peer_identity (&identity);
        const int rc = session->push_msg (&identity);
        if (rc == -1 && errno == EAGAIN) {
            // If the write is failing at this stage with
            // an EAGAIN the pipe must be being shut down,
            // so we can just bail out of the identity set.
            return;
        }
        errno_assert (rc == 0);
        session->flush ();
    }

    next_msg = &stream_engine_t::pull_and_encode;
    process_msg = &stream_engine_t::write_credential;

    //  Compile metadata.
    properties_t properties;
    init_properties(properties);

    //  Add ZAP properties.
    const properties_t& zap_properties = mechanism->get_zap_properties ();
    properties.insert(zap_properties.begin (), zap_properties.end ());

    //  Add ZMTP properties.
    const properties_t& zmtp_properties = mechanism->get_zmtp_properties ();
    properties.insert(zmtp_properties.begin (), zmtp_properties.end ());

    zmq_assert (metadata == NULL);
    if (!properties.empty ())
        metadata = new (std::nothrow) metadata_t (properties);
}
Ejemplo n.º 2
0
void
init(void)
{
  mode = MOVECAM;
  object = TORUS;
  sphere_radius = INITRAD;

  /* Initial camera location and orientation */
  eye_pos0 = XVec4f(2.0, 3.0, 6.0, 1.0);
  gaze_dir0 = XVec4f(-2.0, -3.0, -6.1, 0.0); // c = (0,0,0); g = c - e
  top_dir0 = XVec4f(0.0, 1.0, 0.0, 0.0);
  zNear0 = -0.1;
  zFar0 = -25.0;
  fovy0 = 27.0;
  cam = Camera(eye_pos0, gaze_dir0, top_dir0, zNear0, zFar0, fovy0);

  glClearColor(0.0, 0.0, 0.0, 1.0);
  glMatrixMode(GL_TEXTURE);
  glLoadIdentity();
  glGetDoublev(GL_TEXTURE_MATRIX, cmodview);

  init_properties();
  
  /* YOUR CODE HERE . . .
   * Initialize your lights: some needs to be positioned
   * before viewing transform, others after.
  */
    //initialize eye light
    //glLightfv(lightname,param,value)
    
    glLightfv(EYELIGHT, GL_SPOT_DIRECTION, eyelight_position);
    glLightfv(EYELIGHT, GL_POSITION, eyelight_position);
  setup_view();           // in viewing.cpp
    glLightfv(SUNLIGHT, GL_POSITION, sunlight_position);
    glLightfv(OBJLIGHT, GL_POSITION, objlight_position);
  /* . . . AND/OR HERE */
    //initialize sun light
    
    
  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  /* YOUR CODE HERE - enable various other pieces of OpenGL state
   * 1. Depth test, so that OpenGL has a sense of depth (Cf. glEnable())
   * 2. Automatic normalization of normals (Cf. glEnable())
   * 3. Back face culling (Cf. glEnable())
   * 4. Smooth shading of polygons (Cf. glShadeModel())
   * 5. Filled rendering of polygons (Cf. glPolygonMode())
  */
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_NORMALIZE);
    glEnable(GL_CULL_FACE);
    glShadeModel(GL_SMOOTH);
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    
  glColor4f(0.0, 0.0, 1.0, 0.4);
  initWorld(); // TODO in objects.cpp

  return;
}
Ejemplo n.º 3
0
/* Destructor */
void                    queue_destroy(struct queue *self)
{
  if (self != NULL)
    {
      list_destroy(&self->list);
      init_properties(self);
    }
}
Ejemplo n.º 4
0
void                    queue_init(struct queue *self)
{
  if (self != NULL)
    {
      init_properties(self);
      init_method_ptr(self);
    }
}
void http_header::append(std::string const& chunk) {
    static const std::string header_end{"\r\n\r\n"};
    
    data += chunk;
    
    if (data.find(header_end) != std::string::npos) {
        state = State::READED;
        init_properties();
    }
}
Ejemplo n.º 6
0
void zmq::stream_engine_t::mechanism_ready ()
{
    if (options.heartbeat_interval > 0) {
        add_timer(options.heartbeat_interval, heartbeat_ivl_timer_id);
        has_heartbeat_timer = true;
    }

    if (options.recv_identity) {
        msg_t identity;
        mechanism->peer_identity (&identity);
        const int rc = session->push_msg (&identity);
        if (rc == -1 && errno == EAGAIN) {
            // If the write is failing at this stage with
            // an EAGAIN the pipe must be being shut down,
            // so we can just bail out of the identity set.
            return;
        }
        errno_assert (rc == 0);
        session->flush ();
    }

    next_msg = &stream_engine_t::pull_and_encode;
    process_msg = &stream_engine_t::write_credential;

    //  Compile metadata.
    properties_t properties;
    init_properties(properties);

    //  Add ZAP properties.
    const properties_t& zap_properties = mechanism->get_zap_properties ();
    properties.insert(zap_properties.begin (), zap_properties.end ());

    //  Add ZMTP properties.
    const properties_t& zmtp_properties = mechanism->get_zmtp_properties ();
    properties.insert(zmtp_properties.begin (), zmtp_properties.end ());

    zmq_assert (metadata == NULL);
    if (!properties.empty ())
    {
        metadata = new (std::nothrow) metadata_t (properties);
        alloc_assert (metadata);
    }

#ifdef ZMQ_BUILD_DRAFT_API
    socket->event_handshake_succeeded (endpoint, 0);
#endif
}
Ejemplo n.º 7
0
void zmq::stream_engine_t::plug (io_thread_t *io_thread_,
    session_base_t *session_)
{
    zmq_assert (!plugged);
    plugged = true;

    //  Connect to session object.
    zmq_assert (!session);
    zmq_assert (session_);
    session = session_;
    socket = session-> get_socket ();

    //  Connect to I/O threads poller object.
    io_object_t::plug (io_thread_);
    handle = add_fd (s);
    io_error = false;

    if (options.raw_socket) {
        // no handshaking for raw sock, instantiate raw encoder and decoders
        encoder = new (std::nothrow) raw_encoder_t (out_batch_size);
        alloc_assert (encoder);

        decoder = new (std::nothrow) raw_decoder_t (in_batch_size);
        alloc_assert (decoder);

        // disable handshaking for raw socket
        handshaking = false;

        next_msg = &stream_engine_t::pull_msg_from_session;
        process_msg = &stream_engine_t::push_raw_msg_to_session;

        properties_t properties;
        if (init_properties(properties)) {
            //  Compile metadata.
            zmq_assert (metadata == NULL);
            metadata = new (std::nothrow) metadata_t (properties);
        }

        if (options.raw_notify) {
            //  For raw sockets, send an initial 0-length message to the
            // application so that it knows a peer has connected.
            msg_t connector;
            connector.init();
            push_raw_msg_to_session (&connector);
            connector.close();
            session->flush ();
        }
    }
    else {
        // start optional timer, to prevent handshake hanging on no input
        set_handshake_timer ();

        //  Send the 'length' and 'flags' fields of the identity message.
        //  The 'length' field is encoded in the long format.
        outpos = greeting_send;
        outpos [outsize++] = 0xff;
        put_uint64 (&outpos [outsize], options.identity_size + 1);
        outsize += 8;
        outpos [outsize++] = 0x7f;
    }

    set_pollin (handle);
    set_pollout (handle);
    //  Flush all the data that may have been already received downstream.
    in_event ();
}
Ejemplo n.º 8
0
int main() {
    init_properties();
    
    int n = 0;
    int count = 1;
    
    while (scanf("%d", &n) == 1){
        if(count == 1){
            WIDTH = n;
        }
        if(count == 2){
            HEIGHT = n;
            break;
        }
        ++count;
    }
    if(WIDTH < 0 || HEIGHT < 0){
        printf("You can't have negative sized rooms\n");
        exit(1);
    }
    
    if(WIDTH == 0 || HEIGHT == 0){
        printf("You can't have a room with a zero width or height\n");
        exit(1);
    }
    
    if(WIDTH == 1 && HEIGHT == 1) {
        printf("You need at least 2 rooms\n");
        exit(1);
    }
    if(WIDTH > 15 || HEIGHT > 15){
        printf("Width and Height are limited to 15 due to memory and time constraints\n");
        exit(1);
    }
    
    ROOMSIZE = WIDTH * HEIGHT;
    
    //int array[width][height];
    count = 0;
    schar h = 0;
    schar w = 0;
    uchar omission_occurrences = 0;
    uchar path_length = 0; 
    uchar omit_list[ROOMSIZE];
    int c = 0;
    while(c < ROOMSIZE){
        omit_list[c] = 0;
        ++c;
    }
    struct Node room[ROOMSIZE];
    //struct Instance* inst = new_instance();
    //inst->path_count = 1;

    while (scanf("%d", &n) == 1){
        if(w == WIDTH){
            w = 0;
            ++h;
        }
        room[count].x = w;
        room[count].y = h;
        room[count].value = n;
        room[count].position = count;

        if(n < 0 || n > 3){
            printf("Invalid input for room types\n");
            exit(1);
        }
        if(n == 1){
            ++omission_occurrences;
            room[count].type = OMIT;
            omit_list[count] = 1;
        }
        if(n == 0 || n == 2 || n == 3){
            ++path_length;
            room[count].type = FOURWAY;
            if((0 < w < WIDTH-1) && h == 0){
                room[count].type = TOPEDGE;
            }
            if((0 < w < WIDTH-1) && h == HEIGHT-1){
                room[count].type = BOTTOMEDGE;
            }
            if(w == 0 && (0 < h < HEIGHT-1)){
                room[count].type = LEFTEDGE;
            }
            if(w == WIDTH-1 && (0 < h < HEIGHT-1)){
                room[count].type = RIGHTEDGE;
            }
            if(w == 0 && h == 0){
                room[count].type = TOPLEFTCORNER;
            }
            if(w == 0 && h == HEIGHT-1){
                room[count].type = BOTTOMLEFTCORNER;
            }
            if(w == WIDTH-1 && h == 0){
                room[count].type = TOPRIGHTCORNER;
            }
            if(w == WIDTH-1 && h == HEIGHT-1){
                room[count].type = BOTTOMRIGHTCORNER;
            }
        }
        if(n == 2){
            if(GLOBAL_PROPERTIES.start == -1){
                GLOBAL_PROPERTIES.start = count;
            } else {
                printf("You can only have 1 intake\n");
                exit(1);
            }
            //room[count].type = START;
            //room[count].start = 1;
            //--path_length;
        }
        if(n == 3){
            if(GLOBAL_PROPERTIES.end == -1){
                GLOBAL_PROPERTIES.end = count;
            } else {
                printf("You can only have 1 ac unit\n");
                exit(1);
            }
            
            room[count].type = END;
            //--path_length;
            //room[count].end = 1;
        }  
        ++count;
        ++w;
        if(count > ROOMSIZE-1){
            break;
        }
    }    
    
    if(GLOBAL_PROPERTIES.start == -1){
        printf("There has to be a intake duct marked with a value of 2\n");
        exit(1);
    }
    if(GLOBAL_PROPERTIES.end == -1){
        printf("There has to be an air conditioner marked with a value of 3\n");
        exit(1);
    }
    if(path_length != (ROOMSIZE-omission_occurrences)){
        printf("Error detected in input values\n");
        exit(1);
    } else {
        GLOBAL_PROPERTIES.max_path_length = path_length;
    } 
    
    int total_paths = 0;
    struct LList* list = new_list();
    struct LLNode* node = new_llnode();
    node->position = GLOBAL_PROPERTIES.start;
    memcpy(node->omit, omit_list,sizeof(uchar)*ROOMSIZE);
    push(list, node);
    while(list->count > 0){
        struct LLNode* n = pop(list);
        //printf("position %i \n", n->position);
        n->omit[n->position] = 1;
        n->path_count = n->path_count + 1;
        n->segment_x[room[n->position].x] = 1;
        n->segment_y[room[n->position].y] = 1;
        n->segment_x_path[room[n->position].x] = n->position;
        n->segment_y_path[room[n->position].y] = n->position;
        switch(room[n->position].type)
        {
            case TOPEDGE:
                //VERTICAL_SEGMENT_DETECT        
                PROCESS_NEIGHBOUR(n->position-1);
                PROCESS_NEIGHBOUR(n->position+1);
                PROCESS_NEIGHBOUR(n->position+WIDTH);
                break;
            case BOTTOMEDGE:
                //VERTICAL_SEGMENT_DETECT
                PROCESS_NEIGHBOUR(n->position-1);
                PROCESS_NEIGHBOUR(n->position-WIDTH);
                PROCESS_NEIGHBOUR(n->position+1);
                break;
            
            case LEFTEDGE:
                //HORIZONTAL_SEGMENT_DETECT
                PROCESS_NEIGHBOUR(n->position-WIDTH);
                PROCESS_NEIGHBOUR(n->position+1);
                PROCESS_NEIGHBOUR(n->position+WIDTH);
                break;
            
            case RIGHTEDGE:
                //HORIZONTAL_SEGMENT_DETECT
                PROCESS_NEIGHBOUR(n->position-1);
                PROCESS_NEIGHBOUR(n->position-WIDTH);
                PROCESS_NEIGHBOUR(n->position+WIDTH);
                break;
                
            case FOURWAY:
                n->edge_broken = 1;
                PROCESS_NEIGHBOUR(n->position-1);
                PROCESS_NEIGHBOUR(n->position-WIDTH);
                PROCESS_NEIGHBOUR(n->position+1);
                PROCESS_NEIGHBOUR(n->position+WIDTH);
                break;
                
            case TOPLEFTCORNER:
                //VERTICAL_SEGMENT_DETECT
                //HORIZONTAL_SEGMENT_DETECT
                PROCESS_NEIGHBOUR(n->position+1);
                PROCESS_NEIGHBOUR(n->position+WIDTH);
                break;
                
            case TOPRIGHTCORNER:
                //VERTICAL_SEGMENT_DETECT
                //HORIZONTAL_SEGMENT_DETECT
                PROCESS_NEIGHBOUR(n->position-1);
                PROCESS_NEIGHBOUR(n->position+WIDTH);
                break;
                    
            case BOTTOMLEFTCORNER:
                //VERTICAL_SEGMENT_DETECT
                //HORIZONTAL_SEGMENT_DETECT
                PROCESS_NEIGHBOUR(n->position-WIDTH);
                PROCESS_NEIGHBOUR(n->position+1);
                break;
                
            case BOTTOMRIGHTCORNER:
                //VERTICAL_SEGMENT_DETECT
                //HORIZONTAL_SEGMENT_DETECT
                PROCESS_NEIGHBOUR(n->position-1);
                PROCESS_NEIGHBOUR(n->position-WIDTH);
                break;
            
            case OMIT:
                printf("impossible!\n");
                break;
                
            case END:
                if(n->path_count == GLOBAL_PROPERTIES.max_path_length){
                    ++total_paths;
                }
                break;
        }
        DESTROY_LLNODE(n);
        //destroy_llnode(n);
    }
    
    //int total_paths = search_path(GLOBAL_PROPERTIES.start, room, inst);
    printf("%i\n", total_paths);
    //destroy_instance(inst);
    destroy_list(list);
    return 0;
}
Ejemplo n.º 9
0
static int device_init(DeviceIntPtr dev, InputInfoPtr local)
{
	struct mtev_mtouch *mt = local->private;
	Atom atom;
	int i;
	int j;
	unsigned char map[MT_NUM_BUTTONS + 1];
	Atom btn_labels[MT_NUM_BUTTONS] = { 0 };
	Atom axes_labels[MT_NUM_VALUATORS] = { 0, };
	int r;

	if (MT_NUM_VALUATORS > MAX_VALUATORS) {
		xf86Msg(X_ERROR, "MT_NUM_VALUATORS(%d) > MAX_VALUATORS(%d)\n",
			MT_NUM_VALUATORS, MAX_VALUATORS);
		return BadValue;
	}

	for (i = 0; i < MT_NUM_BUTTONS; i++)
		btn_labels[i] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_UNKNOWN);

	atom = XIGetKnownProperty(BTN_LABEL_PROP_BTN_LEFT);
	btn_labels[0] = atom;

	init_axes_labels(axes_labels, MT_NUM_VALUATORS);

	r = init_properties(dev);
	if (r != Success)
		return r;

	local->fd = xf86OpenSerial(local->options);
	if (local->fd < 0) {
		xf86Msg(X_ERROR, "mtev: cannot open device\n");
		return !Success;
	}
	if (mtouch_configure(mt, local->fd)) {
		xf86Msg(X_ERROR, "mtev: cannot configure device\n");
		return !Success;
	}
	xf86CloseSerial(local->fd);

	for (i = 0; i < MT_NUM_BUTTONS+1; i++)
		map[i] = i;

	InitPointerDeviceStruct((DevicePtr)dev,
				map,
				MT_NUM_BUTTONS,
				btn_labels,
				pointer_control,
				GetMotionHistorySize(),
				MT_NUM_VALUATORS,
				axes_labels);

	for (i = 0; i < MT_NUM_FINGERS; i++) {
		for (j = 0; j < MT_AXIS_PER_FINGER; j++) {
			const int val = (i * MT_AXIS_PER_FINGER) + j;
			int min;
			int max;

			switch (j) {
			case 0:
				min = mt->caps.abs_position_x.minimum;
				max = mt->caps.abs_position_x.maximum;
				if (mt->swap_xy) {
					mt->min_y = min;
					mt->max_y = max;
				} else {
					mt->min_x = min;
					mt->max_x = max;
				}
				break;
			case 1:
				min = mt->caps.abs_position_y.minimum;
				max = mt->caps.abs_position_y.maximum;
				if (mt->swap_xy) {
					mt->min_x = min;
					mt->max_x = max;
				} else {
					mt->min_y = min;
					mt->max_y = max;
				}
				break;
			case 2:
				min = mt->caps.abs_touch_major.minimum;
				max = mt->caps.abs_touch_major.maximum;
				break;
			case 3:
				if (mt->caps.has_touch_minor) {
					min = mt->caps.abs_touch_minor.minimum;
					max = mt->caps.abs_touch_minor.maximum;
				} else {
					min = mt->caps.abs_touch_major.minimum;
					max = mt->caps.abs_touch_major.maximum;
				}
				break;
			case 4: // Tracking id
				min = mt->caps.abs_tracking_id.minimum;
				max = mt->caps.abs_tracking_id.maximum >
					(MT_NUM_FINGERS-1) ?
					(MT_NUM_FINGERS-1) :
					mt->caps.abs_tracking_id.maximum;
				break;
			default:
				return BadValue;
			}

			xf86InitValuatorAxisStruct(dev, val, axes_labels[val],
						   min,
						   max,
						   1, 0, 1, Absolute);
			xf86InitValuatorDefaults(dev, val);
		}
	}

	XIRegisterPropertyHandler(dev, pointer_property, NULL, NULL);

	return Success;
}
Ejemplo n.º 10
0
 CheckerboardDetector::CheckerboardDetector(const Size &size):
   m_data(0){
   init_properties();
   init(size);
 }
Ejemplo n.º 11
0
 CheckerboardDetector::CheckerboardDetector():m_data(0){
   init_properties();
 }
Ejemplo n.º 12
0
int main(int argc, char **argv) {

#ifndef WIN32
    // Signal handling, use POSIX calls with standardized semantics
    struct sigaction sa;
    sigemptyset(&sa.sa_mask);
    sa.sa_flags = SA_RESTART;
    sa.sa_handler = term_handler;
    sigaction(SIGINT, &sa, NULL);
    sigaction(SIGQUIT, &sa, NULL);
    sigaction(SIGTERM, &sa, NULL);
    sa.sa_handler = SIG_IGN;
    sigaction(SIGHUP, &sa, NULL);
    sigaction(SIGPIPE, &sa, NULL);
#endif

    /*
    printf("LONG_MIN %ld\n", LONG_MIN);
    printf("LONG_MAX %ld\n", LONG_MAX);
    printf("INT_MIN %d\n", INT_MIN);
    printf("INT_MAX %d\n", INT_MAX);
     */

    // set default error message prefix
    ms_loginit(NULL, NULL, NULL, "ERROR: ");

    // defaults
    verbose = 0;
    strcpy(port_path_hint, "/dev/usbdev1.1");
    strcpy(propfile, PROP_FILE_NAME_DEFAULT);

    // Process input parameters
    if (parameter_proc(argc, argv) < 0)
        return 1;
    init_properties(propfile);

    // set encoding type
    // possible: DE_ASCII, DE_INT16, DE_INT32, DE_FLOAT32, DE_FLOAT64, DE_STEIM1, DE_STEIM2
    // supported: DE_INT16, DE_INT32, DE_STEIM1, DE_STEIM2
    if (strcmp(mswrite_data_encoding_type, "DE_INT16") == 0) {
        mswrite_data_encoding_type_code = DE_INT16;
        num_samples_in_record = (SLREC_DATA_SIZE) / 2;
    } else if (strcmp(mswrite_data_encoding_type, "DE_INT32") == 0) {
        mswrite_data_encoding_type_code = DE_INT32;
        num_samples_in_record = (SLREC_DATA_SIZE) / 4;
        /*
    } else if (strcmp(mswrite_data_encoding_type, "DE_ASCII") == 0) {
        mswrite_data_encoding_type_code = DE_ASCII;
    } else if (strcmp(mswrite_data_encoding_type, "DE_FLOAT32") == 0) {
        mswrite_data_encoding_type_code = DE_FLOAT32;
    } else if (strcmp(mswrite_data_encoding_type, "DE_FLOAT64") == 0) {
        mswrite_data_encoding_type_code = DE_FLOAT64;
         */
    } else if (strcmp(mswrite_data_encoding_type, "DE_STEIM1") == 0) {
        mswrite_data_encoding_type_code = DE_STEIM1;
        num_samples_in_record = (SLREC_DATA_SIZE) / 4; // estimate, inefficient, assumes int32 data
    } else if (strcmp(mswrite_data_encoding_type, "DE_STEIM2") == 0) {
        mswrite_data_encoding_type_code = DE_STEIM2;
        num_samples_in_record = (SLREC_DATA_SIZE) / 4; // estimate, inefficient, assumes int32 data
    }

    // enter infinite loop, term_handler() performs cleanup
    while (1) {

        // find device and connect
        find_device_and_connect(port_path_hint);

        // set sample rate and gain for SEP064
        if (do_settings_sep064) {
            if (set_seo064_sample_rate_and_gain(nominal_sample_rate, nominal_gain, TIMEOUT_SMALL, verbose)) {
                continue;
            }
        }

        // collect data and write
        if (collect_and_write()) { // collect_and_write() returned error
            logprintf(ERROR_FLAG, "Reading from %s, will try reconnecting...\n", port_path);
            disconnect(verbose);
        } else {
            break; // collect_and_write() returned normally
        }

    }

    return (0);

} /* End of main() */