Exemple #1
0
	virtual bool parse(std::string buf)
	{
		clear();
		boost::optional<std::pair<boost::uint64_t, bool> > key = key_parse(buf);
		if(!key || key->first != field_ID || key->second != true){
			return false;
		}
		std::list<std::string> fields = message_split(buf);
		if(fields.empty()){
			return false;
		}
		for(std::list<std::string>::iterator it_cur = fields.begin(),
			it_end = fields.end(); it_cur != it_end; ++it_cur)
		{
			key = key_parse(*it_cur);
			if(!key){
				return false;
			}
			std::map<boost::uint64_t, field *>::iterator it = Field.find(key->first);
			if(it == Field.end()){
				unknown Unknown;
				if(!Unknown.parse(*it_cur)){
					return false;
				}
				Unknown_Field.insert(std::make_pair(Unknown.ID(), Unknown));
			}else{
				if(!it->second->parse(*it_cur)){
					return false;
				}
			}
		}
		return true;
	}
Exemple #2
0
	/*
	Return all fields in message, or empty list if malformed message.
	Postcondition: Parsed fields removed from buf. If message is malformed there
		are no guarantees on the state of buf after function returns.
	*/
	std::list<std::string> message_split(std::string & buf)
	{
		std::string key_vint = vint_split(buf);
		if(key_vint.empty() || buf.empty()){
			return std::list<std::string>();
		}
		boost::optional<std::pair<boost::uint64_t, bool> >
			key = key_parse(key_vint);
		if(!key || key->second != true){
			return std::list<std::string>();
		}
		std::string m_size_vint = vint_split(buf);
		if(m_size_vint.empty() || buf.empty()){
			return std::list<std::string>();
		}
		boost::uint64_t m_size = vint_to_uint(m_size_vint);
		if(buf.size() != m_size){
			return std::list<std::string>();
		}
		std::list<std::string> tmp_fields;
		while(!buf.empty()){
			key_vint = vint_split(buf);
			if(key_vint.empty() || buf.empty()){
				return std::list<std::string>();
			}
			key = key_parse(key_vint);
			if(key->second){
				std::string f_size_vint = vint_split(buf);
				if(f_size_vint.empty() || buf.empty()){
					return std::list<std::string>();
				}
				boost::uint64_t f_size = vint_to_uint(f_size_vint);
				if(buf.size() < f_size){
					return std::list<std::string>();
				}
				tmp_fields.push_back(key_vint + f_size_vint + buf.substr(0, f_size));
				buf.erase(0, f_size);
			}else{
				std::string val_vint = vint_split(buf);
				if(val_vint.empty()){
					return std::list<std::string>();
				}
				tmp_fields.push_back(key_vint + val_vint);
			}
		}
		return tmp_fields;
	}
int Viewer::loop(){
    char key;

    // loop until esc is pressed
    while ( !exit_flag )
        //std::cout << "enter" << std::endl;
        if ( device.getSensorInfo( openni::SENSOR_DEPTH ) != NULL ) {
//             read the next frame
            depth.readFrame( &depthFrame );
            if ( !only_depth )
                color.readFrame( &colorFrame );
             //             make sure the data is valid

            if (( depthFrame.isValid() && only_depth ) || ( !only_depth && colorFrame.isValid() && depthFrame.isValid())) {
                cv::Mat normDepth, rgbd, depth_thresh;
                //process both images
                // depth image
                const openni::DepthPixel* depthBuffer = (const openni::DepthPixel*)depthFrame.getData();
                frameDepth.create( depthFrame.getHeight(), depthFrame.getWidth(), CV_16UC1 );
                memcpy( frameDepth.data, depthBuffer, depthFrame.getHeight() * depthFrame.getWidth() * sizeof( uint16_t ) );
                cv::flip( frameDepth, frameDepth, 1 );

                if ( !only_depth ) {
                    // color image
                    const openni::RGB888Pixel* imageBuffer = (const openni::RGB888Pixel*)colorFrame.getData();
                    frame.create( colorFrame.getHeight(), colorFrame.getWidth(), CV_8UC3 );
                    memcpy( frame.data, imageBuffer, 3 * colorFrame.getHeight() * colorFrame.getWidth() * sizeof( uint8_t ) );
                    cv::flip( frame, frame, 1 );
                    cv::cvtColor( frame, bgrMat, CV_RGB2BGR );
                    cv::imshow( "Color", bgrMat );
                }

                // create the rgbd image
                createRGBD( frameDepth, bgrMat, rgbd, depth_thresh );
                if ( !only_depth )
                    cv::imshow( "RGBD", rgbd );

                //normalize and show depth data
                cv::normalize( depth_thresh, normDepth, 0, 255, CV_MINMAX, CV_8UC1 );
                cv::imshow( "Depth", normDepth );

                if ( save_memory ) {
                    //store all data
                    if ( !only_depth )
                        rgb_images.push_back( bgrMat.clone() );
                    depth_images.push_back( depth_thresh.clone() );

                }

                // get key interaction
                key = cv::waitKey( 1 );
                key_parse( key );

            }
        }
    return 0;
}
Exemple #4
0
static void ini_parse_sections_and_keys(Ini *ini, const char *data)
{
	Key *key;
	Section *section;
	char *line;

	while ((line = sgetline(&data)) != NULL) {

		if (isingnorableline(line))
			continue;

		/* キーとして解釈 */
		if ((key = key_parse(line)) != NULL) {
			free(line);
			if (section_add_key(ini->current, key)) {
				key_delete(key);
				return;
			}
			continue;
		}

		/* セクションとして解釈 */
		if ((section = section_parse(line)) != NULL) {
			ini->current = section;
			free(line);
			if (ini_add_section(ini, ini->current)) {
				section_delete(ini->current);
				return;
			}
			continue;
		}

		free(line);

		return; /* 無効な文字列の場合にここまで来る */
	}
}
Exemple #5
0
	virtual bool parse(std::string buf)
	{
		/*
		To parse we take the key and prepend it to every list element before we
		pass the list elements to be parsed by the field_type. This makes it so
		fields don't have to understand the "packed" format.
		*/
		clear();
		std::string key_vint = vint_split(buf);
		if(key_vint.empty() || buf.empty()){
			return false;
		}
		boost::optional<std::pair<boost::uint64_t, bool> > key = key_parse(key_vint);
		if(!key || key->first != field_type::field_ID || key->second != true){
			return false;
		}
		if(field_type::length_delim == false && key->second == true){
			/*
			The vector is length delimited but the elements are not. Change the
			length delimited bit on the key before passing it to the field
			object to be parsed.
			*/
			key_vint = key_create(key->first, false);
		}
		std::string len_vint = vint_split(buf);
		if(len_vint.empty() || buf.empty()){
			return false;
		}
		boost::uint64_t len = vint_to_uint(len_vint);
		if(buf.size() != len){
			return false;
		}
		while(!buf.empty()){
			std::string packed_field;
			if(field_type::length_delim){
				std::string f_size_vint = vint_split(buf);
				if(f_size_vint.empty() || buf.empty()){
					return false;
				}
				boost::uint64_t f_size = vint_to_uint(f_size_vint);
				if(buf.size() < f_size){
					return false;
				}
				std::string reassembled = key_vint + f_size_vint + buf.substr(0, f_size);
				buf.erase(0, f_size);
				field_type Field;
				if(!Field.parse(reassembled)){
					return false;
				}
				val.push_back(Field);
			}else{
				std::string val_vint = vint_split(buf);
				if(val_vint.empty()){
					return false;
				}
				std::string reassembled = key_vint + val_vint;
				field_type Field;
				if(!Field.parse(reassembled)){
					return false;
				}
				val.push_back(Field);
			}
		}
		return true;
	}
Exemple #6
0
key_output(struct mbuf *m, va_alist)
#endif
{
	struct sadb_msg *msg;
	int len, error = 0;
	int s;
	struct socket *so;
	va_list ap;

	va_start(ap, m);
	so = va_arg(ap, struct socket *);
	va_end(ap);

	if (m == 0)
		panic("key_output: NULL pointer was passed.");

	pfkeystat.out_total++;
	pfkeystat.out_bytes += m->m_pkthdr.len;

	len = m->m_pkthdr.len;
	if (len < sizeof(struct sadb_msg)) {
		pfkeystat.out_tooshort++;
		error = EINVAL;
		goto end;
	}

	if (m->m_len < sizeof(struct sadb_msg)) {
		if ((m = m_pullup(m, sizeof(struct sadb_msg))) == 0) {
			pfkeystat.out_nomem++;
			error = ENOBUFS;
			goto end;
		}
	}

	if ((m->m_flags & M_PKTHDR) == 0)
		panic("key_output: not M_PKTHDR ??");

	KEYDEBUG(KEYDEBUG_KEY_DUMP, kdebug_mbuf(m));

	msg = mtod(m, struct sadb_msg *);
	pfkeystat.out_msgtype[msg->sadb_msg_type]++;
	if (len != PFKEY_UNUNIT64(msg->sadb_msg_len)) {
		pfkeystat.out_invlen++;
		error = EINVAL;
		goto end;
	}

	/*XXX giant lock*/
#ifdef __NetBSD__
	s = splsoftnet();
#else
	s = splnet();
#endif
	error = key_parse(m, so);
	m = NULL;
	splx(s);
end:
	if (m)
		m_freem(m);
	return error;
}
Exemple #7
0
int settings_load(struct user_settings *s, const char *patharg)
{
    config_t cfg[1];
    config_setting_t *setting;
    const char *str;
    
    /* Load default settings */
    ui_defaults(s);
    tox_defaults(s);
	key_defaults(s);
#ifdef _AUDIO
    audio_defaults(s);
#endif
    
    config_init(cfg);

    char path[MAX_STR_SIZE];

    /* use default config file path */
    if (patharg == NULL) {
        char *user_config_dir = get_user_config_dir();
        snprintf(path, sizeof(path), "%s%stoxic.conf", user_config_dir, CONFIGDIR);
        free(user_config_dir);

        /* make sure path exists or is created on first time running */
        FILE *fp = fopen(path, "r");
        if (fp == NULL) {
            if ((fp = fopen(path, "w")) == NULL)
                return -1;
        }

        fclose(fp);
    } else {
        snprintf(path, sizeof(path), "%s", patharg);
    }
    
    if (!config_read_file(cfg, path)) {
        config_destroy(cfg);
        return -1;
    }
    
    /* ui */
    if ((setting = config_lookup(cfg, ui_strings.self)) != NULL) {
        config_setting_lookup_bool(setting, ui_strings.timestamps, &s->timestamps);
        config_setting_lookup_bool(setting, ui_strings.alerts, &s->alerts);
        config_setting_lookup_bool(setting, ui_strings.autolog, &s->autolog);
        config_setting_lookup_bool(setting, ui_strings.native_colors, &s->colour_theme);
        
        config_setting_lookup_int(setting, ui_strings.history_size, &s->history_size);
        config_setting_lookup_int(setting, ui_strings.time_format, &s->time);
        s->time = s->time == TIME_24 || s->time == TIME_12 ? s->time : TIME_24; /* Check defaults */
    }
    
    if ((setting = config_lookup(cfg, tox_strings.self)) != NULL) {
        if ( config_setting_lookup_string(setting, tox_strings.download_path, &str) ) {
            strcpy(s->download_path, str);
        }
    }
	/* keys */
	if((setting = config_lookup(cfg, key_strings.self)) != NULL) {
	   const char* tmp = NULL;
	   if(config_setting_lookup_string(setting, key_strings.next_tab, &tmp)) s->key_next_tab = key_parse(&tmp);
	   if(config_setting_lookup_string(setting, key_strings.prev_tab, &tmp)) s->key_prev_tab = key_parse(&tmp);
	   if(config_setting_lookup_string(setting, key_strings.scroll_line_up, &tmp)) s->key_scroll_line_up = key_parse(&tmp);
	   if(config_setting_lookup_string(setting, key_strings.scroll_line_down, &tmp)) s->key_scroll_line_down= key_parse(&tmp);
	   if(config_setting_lookup_string(setting, key_strings.half_page_up, &tmp)) s->key_half_page_up = key_parse(&tmp);
	   if(config_setting_lookup_string(setting, key_strings.half_page_down, &tmp)) s->key_half_page_down = key_parse(&tmp);
	   if(config_setting_lookup_string(setting, key_strings.page_bottom, &tmp)) s->key_page_bottom = key_parse(&tmp);
	   if(config_setting_lookup_string(setting, key_strings.peer_list_up, &tmp)) s->key_peer_list_up = key_parse(&tmp);
	   if(config_setting_lookup_string(setting, key_strings.peer_list_down, &tmp)) s->key_peer_list_down = key_parse(&tmp);
	}	   
    
#ifdef _AUDIO
    if ((setting = config_lookup(cfg, audio_strings.self)) != NULL) {
        config_setting_lookup_int(setting, audio_strings.input_device, &s->audio_in_dev);
        s->audio_in_dev = s->audio_in_dev < 0 || s->audio_in_dev > MAX_DEVICES ? 0 : s->audio_in_dev;
        
        config_setting_lookup_int(setting, audio_strings.output_device, &s->audio_out_dev);
        s->audio_out_dev = s->audio_out_dev < 0 || s->audio_out_dev > MAX_DEVICES ? 0 : s->audio_out_dev;
        
        config_setting_lookup_float(setting, audio_strings.VAD_treshold, &s->VAD_treshold);
    }    
#endif

#ifdef _SOUND_NOTIFY
    if ((setting = config_lookup(cfg, sound_strings.self)) != NULL) {
        if ( (config_setting_lookup_string(setting, sound_strings.error, &str) != CONFIG_TRUE) ||
                !set_sound(error, str) ) {
            if (strcasecmp(str, NO_SOUND) != 0)
                set_sound(error, PACKAGE_DATADIR "/sounds/Error.wav");
        }
        
        if ( !config_setting_lookup_string(setting, sound_strings.user_log_in, &str) ||
                !set_sound(user_log_in, str) ) {
            if (strcasecmp(str, NO_SOUND) != 0)
                set_sound(user_log_in, PACKAGE_DATADIR "/sounds/ContactLogsIn.wav");
        }
        
        if ( !config_setting_lookup_string(setting, sound_strings.self_log_in, &str) ||
                !set_sound(self_log_in, str) ) {
            if (strcasecmp(str, NO_SOUND) != 0)
                set_sound(self_log_in, PACKAGE_DATADIR "/sounds/LogIn.wav");
        }

        if ( !config_setting_lookup_string(setting, sound_strings.user_log_out, &str) ||
                !set_sound(user_log_out, str) ) {
            if (strcasecmp(str, NO_SOUND) != 0)
                set_sound(user_log_out, PACKAGE_DATADIR "/sounds/ContactLogsOut.wav");
        }

        if ( !config_setting_lookup_string(setting, sound_strings.self_log_out, &str) ||
                !set_sound(self_log_out, str) ) {
            if (strcasecmp(str, NO_SOUND) != 0)
                set_sound(self_log_out, PACKAGE_DATADIR "/sounds/LogOut.wav");
        }
        
        if ( !config_setting_lookup_string(setting, sound_strings.call_incoming, &str) ||
                !set_sound(call_incoming, str) ) {
            if (strcasecmp(str, NO_SOUND) != 0)
                set_sound(call_incoming, PACKAGE_DATADIR "/sounds/IncomingCall.wav");
        }
        
        if ( !config_setting_lookup_string(setting, sound_strings.call_outgoing, &str) ||
                !set_sound(call_outgoing, str) ) {
            if (strcasecmp(str, NO_SOUND) != 0)
                set_sound(call_outgoing, PACKAGE_DATADIR "/sounds/OutgoingCall.wav");
        }
        
        if ( !config_setting_lookup_string(setting, sound_strings.generic_message, &str) ||
                !set_sound(generic_message, str) ) {
            if (strcasecmp(str, NO_SOUND) != 0)
                set_sound(generic_message, PACKAGE_DATADIR "/sounds/NewMessage.wav");
        }
        
        if ( !config_setting_lookup_string(setting, sound_strings.transfer_pending, &str) ||
                !set_sound(transfer_pending, str) ) {
            if (strcasecmp(str, NO_SOUND) != 0)
                set_sound(transfer_pending, PACKAGE_DATADIR "/sounds/TransferPending.wav");
        }
        
        if ( !config_setting_lookup_string(setting, sound_strings.transfer_completed, &str) ||
                !set_sound(transfer_completed, str) ) {
            if (strcasecmp(str, NO_SOUND) != 0)
                set_sound(transfer_completed, PACKAGE_DATADIR "/sounds/TransferComplete.wav");
        }
    }
    else {
        set_sound(error, PACKAGE_DATADIR "/sounds/Error.wav");
        set_sound(user_log_in, PACKAGE_DATADIR "/sounds/ContactLogsIn.wav");
        set_sound(self_log_in, PACKAGE_DATADIR "/sounds/LogIn.wav");
        set_sound(user_log_out, PACKAGE_DATADIR "/sounds/ContactLogsOut.wav");
        set_sound(self_log_out, PACKAGE_DATADIR "/sounds/LogOut.wav");
        set_sound(call_incoming, PACKAGE_DATADIR "/sounds/IncomingCall.wav");
        set_sound(call_outgoing, PACKAGE_DATADIR "/sounds/OutgoingCall.wav");
        set_sound(generic_message, PACKAGE_DATADIR "/sounds/NewMessage.wav");
        set_sound(transfer_pending, PACKAGE_DATADIR "/sounds/TransferPending.wav");
        set_sound(transfer_completed, PACKAGE_DATADIR "/sounds/TransferComplete.wav");
    }
#endif

    config_destroy(cfg);
    return 0;
}
Exemple #8
0
int settings_load(struct user_settings *s, const char *patharg)
{
    config_t cfg[1];
    config_setting_t *setting;
    const char *str = NULL;

    /* Load default settings */
    ui_defaults(s);
    tox_defaults(s);
    key_defaults(s);

#ifdef AUDIO
    audio_defaults(s);
#endif

    config_init(cfg);

    char path[MAX_STR_SIZE];

    /* use default config file path */
    if (patharg == NULL) {
        char *user_config_dir = get_user_config_dir();
        snprintf(path, sizeof(path), "%s%stoxic.conf", user_config_dir, CONFIGDIR);
        free(user_config_dir);

        /* make sure path exists or is created on first time running */
        if (!file_exists(path)) {
            FILE *fp = fopen(path, "w");

            if (fp == NULL)
                return -1;

            fclose(fp);
        }
    } else {
        snprintf(path, sizeof(path), "%s", patharg);
    }

    if (!config_read_file(cfg, path)) {
        config_destroy(cfg);
        return -1;
    }

    /* ui */
    if ((setting = config_lookup(cfg, ui_strings.self)) != NULL) {
        config_setting_lookup_bool(setting, ui_strings.timestamps, &s->timestamps);

        int time = 24;
        if ( config_setting_lookup_int(setting, ui_strings.time_format, &time) ) {
            if (time == 12) {
                snprintf(s->timestamp_format, sizeof(s->timestamp_format), "%s", "%I:%M:%S %p");
                snprintf(s->log_timestamp_format, sizeof(s->log_timestamp_format), "%s", "%Y/%m/%d [%I:%M:%S %p]");
            }
        }

        if ( config_setting_lookup_string(setting, ui_strings.timestamp_format, &str) ) {
            snprintf(s->timestamp_format, sizeof(s->timestamp_format), "%s", str);
        }

        if ( config_setting_lookup_string(setting, ui_strings.log_timestamp_format, &str) ) {
            snprintf(s->log_timestamp_format, sizeof(s->log_timestamp_format), "%s", str);
        }

        config_setting_lookup_bool(setting, ui_strings.alerts, &s->alerts);
        config_setting_lookup_bool(setting, ui_strings.autolog, &s->autolog);
        config_setting_lookup_bool(setting, ui_strings.native_colors, &s->colour_theme);
        config_setting_lookup_int(setting, ui_strings.history_size, &s->history_size);
        config_setting_lookup_bool(setting, ui_strings.show_typing_self, &s->show_typing_self);
        config_setting_lookup_bool(setting, ui_strings.show_typing_other, &s->show_typing_other);
        config_setting_lookup_bool(setting, ui_strings.show_welcome_msg, &s->show_welcome_msg);

        if ( config_setting_lookup_string(setting, ui_strings.line_join, &str) ) {
            snprintf(s->line_join, sizeof(s->line_join), "%s", str);
        }
        if ( config_setting_lookup_string(setting, ui_strings.line_quit, &str) ) {
            snprintf(s->line_quit, sizeof(s->line_quit), "%s", str);
        }
        if ( config_setting_lookup_string(setting, ui_strings.line_alert, &str) ) {
            snprintf(s->line_alert, sizeof(s->line_alert), "%s", str);
        }
        if ( config_setting_lookup_string(setting, ui_strings.line_normal, &str) ) {
            snprintf(s->line_normal, sizeof(s->line_normal), "%s", str);
        }

        config_setting_lookup_bool (setting, ui_strings.mplex_away, &s->mplex_away);

        if (config_setting_lookup_string (setting, ui_strings.mplex_away_note, &str)) {
            snprintf (s->mplex_away_note, sizeof (s->mplex_away_note), "%s", str);
        }
    }

    /* paths */
    if ((setting = config_lookup(cfg, tox_strings.self)) != NULL) {
        if ( config_setting_lookup_string(setting, tox_strings.download_path, &str) ) {
            snprintf(s->download_path, sizeof(s->download_path), "%s", str);
            int len = strlen(s->download_path);

            /* make sure path ends with a '/' */
            if (len >= sizeof(s->download_path) - 2)
                s->download_path[0] = '\0';
            else if (s->download_path[len - 1] != '/')
                strcat(&s->download_path[len - 1], "/");
        }

        if ( config_setting_lookup_string(setting, tox_strings.chatlogs_path, &str) ) {
            snprintf(s->chatlogs_path, sizeof(s->chatlogs_path), "%s", str);
            int len = strlen(s->chatlogs_path);

            if (len >= sizeof(s->chatlogs_path) - 2)
                s->chatlogs_path[0] = '\0';
            else if (s->chatlogs_path[len - 1] != '/')
                strcat(&s->chatlogs_path[len - 1], "/");
        }

        if ( config_setting_lookup_string(setting, tox_strings.avatar_path, &str) ) {
            snprintf(s->avatar_path, sizeof(s->avatar_path), "%s", str);
            int len = strlen(str);

            if (len >= sizeof(s->avatar_path))
                s->avatar_path[0] = '\0';
        }
    }

    /* keys */
    if ((setting = config_lookup(cfg, key_strings.self)) != NULL) {
        const char* tmp = NULL;
        if (config_setting_lookup_string(setting, key_strings.next_tab, &tmp))
            s->key_next_tab = key_parse(&tmp);
        if (config_setting_lookup_string(setting, key_strings.prev_tab, &tmp))
            s->key_prev_tab = key_parse(&tmp);
        if (config_setting_lookup_string(setting, key_strings.scroll_line_up, &tmp))
            s->key_scroll_line_up = key_parse(&tmp);
        if (config_setting_lookup_string(setting, key_strings.scroll_line_down, &tmp))
            s->key_scroll_line_down= key_parse(&tmp);
        if (config_setting_lookup_string(setting, key_strings.half_page_up, &tmp))
            s->key_half_page_up = key_parse(&tmp);
        if (config_setting_lookup_string(setting, key_strings.half_page_down, &tmp))
            s->key_half_page_down = key_parse(&tmp);
        if (config_setting_lookup_string(setting, key_strings.page_bottom, &tmp))
            s->key_page_bottom = key_parse(&tmp);
        if (config_setting_lookup_string(setting, key_strings.peer_list_up, &tmp))
            s->key_peer_list_up = key_parse(&tmp);
        if (config_setting_lookup_string(setting, key_strings.peer_list_down, &tmp))
            s->key_peer_list_down = key_parse(&tmp);
        if (config_setting_lookup_string(setting, key_strings.toggle_peerlist, &tmp))
            s->key_toggle_peerlist = key_parse(&tmp);
    }

#ifdef AUDIO
    if ((setting = config_lookup(cfg, audio_strings.self)) != NULL) {
        config_setting_lookup_int(setting, audio_strings.input_device, &s->audio_in_dev);
        s->audio_in_dev = s->audio_in_dev < 0 || s->audio_in_dev > MAX_DEVICES ? 0 : s->audio_in_dev;

        config_setting_lookup_int(setting, audio_strings.output_device, &s->audio_out_dev);
        s->audio_out_dev = s->audio_out_dev < 0 || s->audio_out_dev > MAX_DEVICES ? 0 : s->audio_out_dev;

        config_setting_lookup_float(setting, audio_strings.VAD_treshold, &s->VAD_treshold);
    }
#endif

#ifdef SOUND_NOTIFY
    if ((setting = config_lookup(cfg, sound_strings.self)) != NULL) {
        if ( (config_setting_lookup_string(setting, sound_strings.notif_error, &str) != CONFIG_TRUE) ||
                !set_sound(notif_error, str) ) {
            if (str && strcasecmp(str, NO_SOUND) != 0)
                set_sound(notif_error, PACKAGE_DATADIR "/sounds/ToxicError.wav");
        }

        if ( !config_setting_lookup_string(setting, sound_strings.user_log_in, &str) ||
                !set_sound(user_log_in, str) ) {
            if (str && strcasecmp(str, NO_SOUND) != 0)
                set_sound(user_log_in, PACKAGE_DATADIR "/sounds/ToxicContactOnline.wav");
        }

        if ( !config_setting_lookup_string(setting, sound_strings.user_log_out, &str) ||
                !set_sound(user_log_out, str) ) {
            if (str && strcasecmp(str, NO_SOUND) != 0)
                set_sound(user_log_out, PACKAGE_DATADIR "/sounds/ToxicContactOffline.wav");
        }

        if ( !config_setting_lookup_string(setting, sound_strings.call_incoming, &str) ||
                !set_sound(call_incoming, str) ) {
            if (str && strcasecmp(str, NO_SOUND) != 0)
                set_sound(call_incoming, PACKAGE_DATADIR "/sounds/ToxicIncomingCall.wav");
        }

        if ( !config_setting_lookup_string(setting, sound_strings.call_outgoing, &str) ||
                !set_sound(call_outgoing, str) ) {
            if (str && strcasecmp(str, NO_SOUND) != 0)
                set_sound(call_outgoing, PACKAGE_DATADIR "/sounds/ToxicOutgoingCall.wav");
        }

        if ( !config_setting_lookup_string(setting, sound_strings.generic_message, &str) ||
                !set_sound(generic_message, str) ) {
            if (str && strcasecmp(str, NO_SOUND) != 0)
                set_sound(generic_message, PACKAGE_DATADIR "/sounds/ToxicRecvMessage.wav");
        }

        if ( !config_setting_lookup_string(setting, sound_strings.transfer_pending, &str) ||
                !set_sound(transfer_pending, str) ) {
            if (str && strcasecmp(str, NO_SOUND) != 0)
                set_sound(transfer_pending, PACKAGE_DATADIR "/sounds/ToxicTransferStart.wav");
        }

        if ( !config_setting_lookup_string(setting, sound_strings.transfer_completed, &str) ||
                !set_sound(transfer_completed, str) ) {
            if (str && strcasecmp(str, NO_SOUND) != 0)
                set_sound(transfer_completed, PACKAGE_DATADIR "/sounds/ToxicTransferComplete.wav");
        }
    }
    else {
        set_sound(notif_error, PACKAGE_DATADIR "/sounds/ToxicError.wav");
        set_sound(user_log_in, PACKAGE_DATADIR "/sounds/ToxicContactOnline.wav");
        set_sound(user_log_out, PACKAGE_DATADIR "/sounds/ToxicContactOffline.wav");
        set_sound(call_incoming, PACKAGE_DATADIR "/sounds/ToxicIncomingCall.wav");
        set_sound(call_outgoing, PACKAGE_DATADIR "/sounds/ToxicOutgoingCall.wav");
        set_sound(generic_message, PACKAGE_DATADIR "/sounds/ToxicRecvMessage.wav");
        set_sound(transfer_pending, PACKAGE_DATADIR "/sounds/ToxicTransferStart.wav");
        set_sound(transfer_completed, PACKAGE_DATADIR "/sounds/ToxicTransferComplete.wav");
    }
#endif

    config_destroy(cfg);
    return 0;
}
Exemple #9
0
int main() {
	adder::Polygon poly({{0, 0}, {144, 0}, {144, -72}, {72, -72}, {120, -48}, {48, -12}, {24, -24}, {72, -48}, {24 ,-72}, {0, -72}}, {256, 128});
	std::vector<glm::vec3> colors = {{0.2, 0.0, 0.8}, {0.2, 0.0, 0.8}, {1.0, 0.0, 0.8}, {1.0, 1.0, 0.0}, {1.0, 0.0, 0.8}, {1.0, 0.0, 0.8}, {1.0, 0.0, 0.8}, {1.0, 0.0, 0.8}, {1.0, 0.0, 0.8}, {1.0, 0.0, 0.8}};
	//poly.rotate(2*adder::PI/3, poly.get_pos());
	adder::Body body(100, 100, -.1, poly);

	boa::GLData poly_gl_data(poly.vertices(), 6);
	poly_gl_data.set_attribute(3, colors);

	boa::init(3, 3, GL_FALSE);
	GLFWwindow* window = boa::create_window(640, 480, "BOA TEST");
	glfwSetKeyCallback(window, key_callback);

	glEnable(GL_DEPTH_TEST);
	glClearColor(0.2, 0.5, 1.0, 0.0);
	//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); // Outline mode

	GLuint vertex_shader = boa::compile_shader("res/shaders/shader.vert", GL_VERTEX_SHADER);
	GLuint fragment_shader = boa::compile_shader("res/shaders/shader.frag", GL_FRAGMENT_SHADER);
	GLuint shader_program = boa::create_program({vertex_shader, fragment_shader});
	glDeleteShader(vertex_shader);
	glDeleteShader(fragment_shader);
	
	// Create vertex array object
	// The vertex array object stores the states of the vertex and index buffer
	// objects defined inside of it, allowing them to be easily reused again.
	// The vertex and index buffer objects store the vertex and index data on
	// the gpu, respectively. They are cleared automatically after each drawing
	// cycle, hence the need for the vertex array object. I think.
	// TODO: find some way to abstract this
	GLuint vao, vbo, ibo;
	glGenVertexArrays(1, &vao);
	glGenBuffers(1, &vbo);
	glGenBuffers(1, &ibo);

	glBindVertexArray(vao);

	glBindBuffer(GL_ARRAY_BUFFER, vbo);
	glBufferData(GL_ARRAY_BUFFER, poly_gl_data.get_verts_size(), poly_gl_data.get_vertices(), GL_STATIC_DRAW);

	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (GLvoid*)0);
	glEnableVertexAttribArray(0);
	glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));
	glEnableVertexAttribArray(1);

	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, poly_gl_data.get_indices_size(), poly_gl_data.get_indices(), GL_STATIC_DRAW);

	glBindVertexArray(0);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

	
	// Transformation matrices
	glm::mat4 model, view, projection;
	projection = glm::ortho(0.0f, 640.0f, 480.0f, 0.0f);


	while(!glfwWindowShouldClose(window)) {
		glfwPollEvents();
		key_parse();

		glUseProgram(shader_program);

		// Update view matrix with new camera position
		view = glm::translate(glm::mat4(), glm::vec3(camera_x, camera_y, 0.0f));
		// Load uniforms
		glUniformMatrix4fv(glGetUniformLocation(shader_program, "view"), 1, GL_FALSE, glm::value_ptr(view));
		glUniformMatrix4fv(glGetUniformLocation(shader_program, "projection"), 1, GL_FALSE, glm::value_ptr(projection));

		glBindVertexArray(vao);	

		// Render
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		model = glm::mat4();
		glUniformMatrix4fv(glGetUniformLocation(shader_program, "model"), 1, GL_FALSE, glm::value_ptr(model));

		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
		glDrawElements(GL_TRIANGLES, poly_gl_data.get_num_elements(), GL_UNSIGNED_INT, 0);

		glBindVertexArray(0);
		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
		glfwSwapBuffers(window);
	}

	glDeleteVertexArrays(1, &vao);
	glDeleteBuffers(1, &vbo);

	glfwDestroyWindow(window);
	glfwTerminate();

	return 0;
}