コード例 #1
0
ファイル: mpd_watchupdates.c プロジェクト: dschoepe/configs
int main(int argc, char **argv) {
  int iport = 6600;
  char *hostname = getenv("MPD_HOST");
  char *port = getenv("MPD_PORT");
  char *password = getenv("MPD_PASSWORD");
  MpdObj *obj = NULL;
  if(!hostname) {
    hostname = "localhost";
  }
  if(port){
    iport = atoi(port);
  }
  /* Create mpd object */
  obj = mpd_new(hostname, iport,password); 
  /* Connect signals */
  mpd_signal_connect_error(obj,(ErrorCallback)error_callback, NULL);
  mpd_signal_connect_status_changed(obj,(StatusChangedCallback)status_changed, NULL);
  /* Set timeout */
  mpd_set_connection_timeout(obj, 10);

  if(!mpd_connect(obj))
    {
      mpd_send_password(obj);
      do{
        mpd_status_update(obj);
      } while(!usleep(300000));
    }
  mpd_free(obj);

  return 0;
}
コード例 #2
0
ファイル: gimmix.c プロジェクト: BackupTheBerlios/gimmix
bool
gimmix_connect (void)
{
	char 	*host = NULL;
	char	*pass = NULL;
	int	port;

	host = cfg_get_key_value (conf, "mpd_hostname");
	pass = cfg_get_key_value (conf, "mpd_password");
	port = atoi (cfg_get_key_value (conf, "mpd_port"));
	gmo = mpd_new (host, port, pass);
	mpd_signal_connect_error (gmo, (ErrorCallback)gimmix_mpd_connection_error_callback, NULL);
	
	if (mpd_connect(gmo) == MPD_OK)
	{
		mpd_send_password (gmo);
		printf ("connected to mpd\n");
		mpd_signal_connect_connection_changed (gmo, (ConnectionChangedCallback)gimmix_mpd_connection_changed_callback, NULL);
		return true;
	}
	else
	{
		mpd_free (gmo);
		gmo = NULL;
	}

	return false;
}
コード例 #3
0
bool
mpd_run_password(struct mpd_connection *connection, const char *password)
{
	return mpd_run_check(connection) &&
		mpd_send_password(connection, password) &&
		mpd_response_finish(connection);
}
コード例 #4
0
ファイル: mpd.c プロジェクト: cmende/mpd2irc
gboolean mpd_connect(void)
{
	mpd.conn = mpd_connection_new(prefs.mpd_server, prefs.mpd_port, 10000);
	mpd.idle_source = 0;

	if (mpd_connection_get_error(mpd.conn) != MPD_ERROR_SUCCESS) {
		g_warning("Failed to connect to MPD: %s",
				mpd_connection_get_error_message(mpd.conn));
		return FALSE;
	} else if (mpd_connection_cmp_server_version(mpd.conn, 0, 14, 0) < 0) {
		g_critical("MPD too old, please upgrade to 0.14 or newer");
		return FALSE;
	} else {
		GIOChannel *channel;

		mpd_command_list_begin(mpd.conn, TRUE);
		if (prefs.mpd_password)
			mpd_send_password(mpd.conn, prefs.mpd_password);
		mpd_send_status(mpd.conn);
		mpd_send_current_song(mpd.conn);
		mpd_command_list_end(mpd.conn);

		mpd.status = mpd_recv_status(mpd.conn);
		if (!mpd_response_next(mpd.conn)) {
			mpd_report_error();
			return FALSE;
		}
		mpd.song = mpd_recv_song(mpd.conn);
		if (!mpd_response_finish(mpd.conn)) {
			mpd_report_error();
			return FALSE;
		}

		g_message("Connected to MPD");
		irc_say("Connected to MPD");

		mpd_send_idle_mask(mpd.conn, MPD_IDLE_PLAYER);

		channel = g_io_channel_unix_new(
				mpd_connection_get_fd(mpd.conn));
		mpd.idle_source = g_io_add_watch(channel, G_IO_IN,
				(GIOFunc) mpd_parse, NULL);
		g_io_channel_unref(channel);

		return TRUE;
	}
}
コード例 #5
0
ファイル: g15mpd.c プロジェクト: trainman419/g15mpd
int main(int argc, char **argv)
{
    int fdstdin = 0;
    pthread_t Lkeys;
    pthread_t g15display;
    pthread_t EKeys;
    int volume;
    int volume_new;
    char devname[256] = "Unknown";
    int iport = 6600;
    char *hostname = getenv("MPD_HOST");
    char *port = getenv("MPD_PORT");
    char *password = getenv("MPD_PASSWORD");
    int eventdev;
    char evdev_name[128];
    pthread_mutex_init(&lockit,NULL);
    pthread_mutex_init(&daemon_mutex,NULL);
    int i;
      
    for (i=0;i<argc;i++) {
    char argument[20];
    memset(argument,0,20);
    strncpy(argument,argv[i],19);
    if (!strncmp(argument, "-q",2) || !strncmp(argument, "--quickscroll",13)) {
        quickscroll=1;
    }
    if (!strncmp(argument, "-h",2) || !strncmp(argument, "--help",6)) {
        printf("  %s version %s\n  (c)2006-2007 Mike Lampard\n\n",argv[0],VERSION);
        printf("%s -q or --quickscroll	Use volume control to scroll through the playlist\n",argv[0]);
        printf("%s -v or --version	Show program version\n",argv[0]);
        printf("%s -h or --help		This help text\n\n",argv[0]);
        exit(0);
    }
    if (!strncmp(argument, "-v",2) || !strncmp(argument, "--version",9)) {
      printf("%s version %s\n",argv[0],VERSION);
      exit(0);     
    }    
  }

    
    for(eventdev=0;eventdev<127;eventdev++) {
        snprintf(evdev_name,127,"/dev/input/event%i",eventdev);
        if ((mmedia_fd = open(evdev_name, O_NONBLOCK|O_RDONLY)) < 0) {
            // ignore errors when opening devices
            //printf("error opening interface %i\n",eventdev);
        } else {
            ioctl(mmedia_fd, EVIOCGNAME(sizeof(devname)), devname);
            printf("Device Name %s on %s\n", devname, evdev_name);
            if(0==strncmp(devname,"Logitech Logitech Gaming Keyboard",256)){
                printf("Found device: \"%s\" on %s ", devname,evdev_name);
                break;
            } else if(0==strncmp(devname,"G15 Gaming Keyboard",256)){
                printf("Found device: \"%s\" on %s ", devname,evdev_name);
                break;
            }else
                close(mmedia_fd);
        }
    }
    if (mmedia_fd) { // we assume that the next event device is the multimedia keys
        close(mmedia_fd);
        snprintf(evdev_name,127,"/dev/input/event%i",++eventdev);
        printf("and %s\n",evdev_name);
        if ((mmedia_fd = open(evdev_name, O_NONBLOCK|O_RDONLY)) < 0) {
            printf("error opening interface %i",eventdev);
        }
    }else {
        printf("Unable to find Keyboard via EVENT interface... is /dev/input/event[0-9] readable??\n");
    }

    /* set correct hostname */	
    if(!hostname) {
        hostname = "localhost";
    }
    if(port){
        iport = atoi(port);
    }

    if((g15screen_fd = new_g15_screen(G15_G15RBUF))<0){
        printf("Sorry, cant connect to the G15daemon\n");
        return 1;
    }

    canvas = (g15canvas *) malloc (sizeof (g15canvas));
    if (canvas != NULL) {
        memset(canvas->buffer, 0, G15_BUFFER_LEN);
        canvas->mode_cache = 0;
        canvas->mode_reverse = 0;
        canvas->mode_xor = 0;
    }

    /* Create mpd object */
    obj = mpd_new(hostname, iport,password); 
    /* Connect signals */
    mpd_signal_connect_error(obj,(ErrorCallback)error_callback, NULL);
    mpd_signal_connect_status_changed(obj,(StatusChangedCallback)status_changed, NULL);
    /* Set timeout */
    mpd_set_connection_timeout(obj, 10);

    if(0==mpd_connect(obj))
    {
        char buffer[20];
        pthread_attr_t attr;

        mpd_send_password(obj);
        memset(buffer, '\0', 20);
        pthread_attr_init(&attr);
        pthread_attr_setstacksize(&attr,32*1024); /* set stack to 64k - dont need 8Mb !! */

        pthread_create(&Lkeys, &attr, Lkeys_thread, NULL);
        pthread_create(&EKeys, &attr,event_key_thread, NULL);
        pthread_create(&g15display, &attr, g15display_thread, NULL);

        do{
            pthread_mutex_lock(&daemon_mutex);
            if(voltimeout) 
               --voltimeout;
            if(mute){
                volume_adjust = 0;
                mute = 0;
                if (muted_volume == 0) {
                    //printf("mute\n");
                    muted_volume = mpd_status_get_volume(obj);
                    mpd_status_set_volume (obj,0);
                } else {
                    //printf("unmute\n");
                    if (mpd_status_get_volume(obj) == 0) { /* if no other client has set volume up */
                        mpd_status_set_volume (obj,muted_volume);
                    }
                    muted_volume = 0;
                }
            }
            if(volume_adjust != 0){
                if (muted_volume != 0) {
                    volume=muted_volume;
                } else {
                    volume=mpd_status_get_volume(obj);
                }
                volume_new = volume + volume_adjust;
                volume_adjust = 0;
                if(volume_new < 0)
                    volume_new = 0;
                if(volume_new > 100)
                    volume_new = 100;
                if(volume != volume_new || muted_volume){
                    //printf("volume %d -> %d\n", volume, volume_new);
                    mpd_status_set_volume (obj,volume_new);
                }
                voltimeout=100;
                muted_volume=0;
            }
            mpd_status_update(obj);
            pthread_mutex_unlock(&daemon_mutex);

        }while(!usleep(5000) &&  !leaving);
      leaving = 1;
      pthread_join(Lkeys,NULL);
      pthread_join(g15display,NULL);
    }else
      printf("Unable to connect to MPD server. Exiting\n");

    if(obj)
      mpd_free(obj);
    close(fdstdin);

    if(canvas!=NULL)
        free(canvas);

    close(g15screen_fd);
    close(mmedia_fd);

    pthread_mutex_destroy(&lockit);

    return 1;
}