Пример #1
0
static void
impl_deactivate	(TotemPlugin *plugin,
		 TotemObject *totem)
{
	TotemLircPlugin *pi = TOTEM_LIRC_PLUGIN (plugin);
	GError *error = NULL;

	if (pi->lirc_channel) {
		g_io_channel_shutdown (pi->lirc_channel, FALSE, &error);
		if (error != NULL) {
			g_warning ("Couldn't destroy lirc connection: %s",
				   error->message);
			g_error_free (error);
		}
		pi->lirc_channel = NULL;
	}

	if (pi->lirc_config) {
		lirc_freeconfig (pi->lirc_config);
		pi->lirc_config = NULL;

		lirc_deinit ();
	}

	if (pi->totem) {
		g_object_unref (pi->totem);
		pi->totem = NULL;
	}
}
Пример #2
0
static void
impl_deactivate	(PeasActivatable *bplugin)
{
	RBLircPlugin *plugin = RB_LIRC_PLUGIN (bplugin);
	GError *error = NULL;

	rb_debug ("Deactivating lirc plugin");

	if (plugin->lirc_channel) {
		g_io_channel_shutdown (plugin->lirc_channel, FALSE, &error);
		if (error != NULL) {
			g_warning ("Couldn't destroy lirc connection: %s",
				   error->message);
			g_error_free (error);
		}
		plugin->lirc_channel = NULL;
	}

	if (plugin->lirc_config) {
		lirc_freeconfig (plugin->lirc_config);
		plugin->lirc_config = NULL;

		lirc_deinit ();
	}

	if (plugin->shell_player) {
		g_object_unref (G_OBJECT (plugin->shell_player));
		plugin->shell_player = NULL;
	}
}
/**
 * Close the driver (do necessary clean-up).
 * \param drvthis  Pointer to driver structure.
 */
MODULE_EXPORT void
lircin_close (Driver *drvthis)
{
        PrivateData * p = drvthis->private_data;

	if (p != NULL) {
		if (p->lircrc != NULL)
			free(p->lircrc);
		p->lircrc = NULL;

		if (p->prog != NULL)
			free(p->prog);
		p->prog = NULL;

		if (p->lircin_irconfig != NULL)
			lirc_freeconfig (p->lircin_irconfig);
		p->lircin_irconfig = NULL;

		if (p->lircin_fd >= 0) {
			lirc_deinit ();
			close (p->lircin_fd);
		}
		p->lircin_fd = -1;

		free(p);
	}
	drvthis->store_private_ptr(drvthis, NULL);
}
Пример #4
0
static void
mex_lirc_deinit (struct lirc_config *config)
{
  if (config)
    lirc_freeconfig (config);
  lirc_deinit ();
}
Пример #5
0
/* Close lircd connection (if open) */
void close_lirc(void) {
    if (using_lirc) {
        lirc_freeconfig(lircconfig);
        lirc_deinit();
        using_lirc = false;
    }
}
Пример #6
0
void
mp_input_lirc_close(int fd) {
  free(cmd_buf);
  cmd_buf = NULL;
  lirc_freeconfig(lirc_config);
  lirc_deinit();
}
Пример #7
0
/* Close lircd connection (if open) */
void close_lirc(void){
   if (interactive.using_lirc) {
      lirc_freeconfig(interactive.lircconfig);
      lirc_deinit();
      interactive.using_lirc = false;
   }
}
Пример #8
0
int
main (int argc, const char *argv[]) {
  int fd;
  struct lirc_config *config;
  char *code;

  if ((fd = lirc_init("lirc", 1)) == -1) {
    fprintf(stderr, "cannot init lirc\n");
    exit(EXIT_FAILURE);
  }

  fprintf(stdout, "LIRC FD = %d\n", fd);
  fflush(stdout);

#if 0 // XXX test non-block socket (for integration with tcdr)
  if (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK) == -1) {
    fprintf(stderr, "cannot make socket as non block\n");
    exit(EXIT_FAILURE);
  }
#endif

  if (lirc_readconfig(NULL, &config, NULL) == 0) {
    while (lirc_nextcode(&code) == 0) {
      if (!code)
        continue;

      if (strstr(code, "KEY_MENU")) {
        fprintf(stdout, "MENU\n");
        fflush(stdout);
      } else if (strstr(code, "KEY_PLAYPAUSE")) {
        fprintf(stdout, "PLAY\n");
        fflush(stdout);
      } else if (strstr(code, "KEY_FORWARD")) {
        fprintf(stdout, "FWRD\n");
        fflush(stdout);
      } else if (strstr(code, "KEY_REWIND")) {
        fprintf(stdout, "RWND\n");
        fflush(stdout);
      } else if (strstr(code, "KEY_VOLUMEUP")) {
        fprintf(stdout, "VLUP\n");
        fflush(stdout);
      } else if (strstr(code, "KEY_VOLUMEDOWN")) {
        fprintf(stdout, "VLDN\n");
        fflush(stdout);
      } else {
        fprintf(stderr, "UNKN\n");
      }

      free(code);
    }

    lirc_freeconfig(config);
  }

  lirc_deinit();
  
  return 0;
}
Пример #9
0
Файл: lirc.cpp Проект: 63n/bino
void lircclient::deinit()
{
    if (_initialized)
    {
        lirc_freeconfig(_config);
        lirc_deinit();
        _initialized = false;
    }
}
Пример #10
0
/*****************************************************************************
 * Close: destroy interface
 *****************************************************************************/
static void Close( vlc_object_t *p_this )
{
    intf_thread_t *p_intf = (intf_thread_t *)p_this;

    /* Destroy structure */
    lirc_freeconfig( p_intf->p_sys->config );
    lirc_deinit();
    free( p_intf->p_sys );
}
Пример #11
0
void die(const char* fmt, ...)
{
	va_list args;

	va_start(args, fmt);
	vfprintf(stderr, fmt, args);
	lirc_freeconfig(lconfig);
	lirc_deinit();
	exit(1);
}
Пример #12
0
void deinits() {
	lcdClear(lcdHandle);
	lirc_freeconfig(config);
	lirc_deinit();
	mysql_close(sqlCon);
	close(i2cfile);
	logger << "RasPiProg logging stopped normally." << endl;
	logfile.close();
	exit(EXIT_SUCCESS);
}
Пример #13
0
void lircStop(void)
{
    if(g_lircfd!=-1)
    {
        if(g_config != NULL)
        {
            lirc_freeconfig(g_config);
            g_config = NULL;
        }
        lirc_deinit();
        DebugMessage(M64MSG_INFO, "LIRC system shut down");
    }
}
Пример #14
0
static void
module_shutdown(Enna_Module *em)
{
#if 0
    enna_config_panel_unregister(_config_panel);
#endif
    if (mod->fd_handler)
    {
        lirc_freeconfig(mod->lirc_config);
        ecore_main_fd_handler_del(mod->fd_handler);
        lirc_deinit();
    }
}
Пример #15
0
Файл: lirc.c Проект: blinry/vlc
/*****************************************************************************
 * Close: destroy interface
 *****************************************************************************/
static void Close( vlc_object_t *p_this )
{
    intf_thread_t *p_intf = (intf_thread_t *)p_this;
    intf_sys_t *p_sys = p_intf->p_sys;

    vlc_cancel( p_sys->thread );
    vlc_join( p_sys->thread, NULL );

    /* Destroy structure */
    lirc_freeconfig( p_sys->config );
    lirc_deinit();
    free( p_sys );
}
Пример #16
0
static void *thread_func(void *arg)
{
	struct lirc_config *config;
	int    sock, flags;

	if ((sock = lirc_init("gmu", 1)) != -1) {
		fcntl(sock, F_SETOWN, getpid());
		flags = fcntl(sock, F_GETFL, 0);
		if (flags != -1) fcntl(sock, F_SETFL, flags|O_NONBLOCK);
		if (lirc_readconfig(NULL, &config, NULL) == 0) {
			char *code, *c;
			int   ret = 0;

			while (run && lirc_nextcode(&code) == 0) {
				if (code != NULL) {
					if ((ret = lirc_code2char(config, code, &c)) == 0 && c != NULL) {
						wdprintf(V_DEBUG, "lirc_frontend", "Got button press.\n");
						if (strcmp(c, "play") == 0)
							gmu_core_play();					
						else if (strcmp(c, "pause") == 0)
							gmu_core_pause();
						else if (strcmp(c, "stop") == 0)
							gmu_core_stop();
						else if (strcmp(c, "toggle_pause") == 0)
							gmu_core_play_pause();
						else if (strcmp(c, "toggle_play_pause") == 0)
							gmu_core_play_pause();
						else if (strcmp(c, "next") == 0)
							gmu_core_next();				
						else if (strcmp(c, "prev") == 0)
							gmu_core_previous();
						else if (strcmp(c, "volume_up") == 0)
							gmu_core_set_volume(gmu_core_get_volume()+1);
						else if (strcmp(c, "volume_down") == 0)
							gmu_core_set_volume(gmu_core_get_volume()-1);
						else
							wdprintf(V_WARNING, "lirc_frontend", "Unknown command: %s\n", c);
						c = NULL;
					}
				}
				usleep(400);
				free(code);
				if (ret == -1) break;
			}
			wdprintf(V_INFO, "lirc_frontend", "Exitting.\n");
			lirc_freeconfig(config);
		}
		lirc_deinit();
	}
	return NULL;
}
Пример #17
0
Файл: lirc.c Проект: blinry/vlc
/*****************************************************************************
 * Open: initialize interface
 *****************************************************************************/
static int Open( vlc_object_t *p_this )
{
    intf_thread_t *p_intf = (intf_thread_t *)p_this;
    intf_sys_t *p_sys;

    /* Allocate instance and initialize some members */
    p_intf->p_sys = p_sys = malloc( sizeof( intf_sys_t ) );
    if( p_sys == NULL )
        return VLC_ENOMEM;

    p_sys->i_fd = lirc_init( "vlc", 1 );
    if( p_sys->i_fd == -1 )
    {
        msg_Err( p_intf, "lirc initialisation failed" );
        goto error;
    }

    /* We want polling */
    fcntl( p_sys->i_fd, F_SETFL, fcntl( p_sys->i_fd, F_GETFL ) | O_NONBLOCK );

    /* Read the configuration file */
    char *psz_file = var_InheritString( p_intf, "lirc-file" );
    int val = lirc_readconfig( psz_file, &p_sys->config, NULL );
    free( psz_file );
    if( val != 0 )
    {
        msg_Err( p_intf, "failure while reading lirc config" );
        lirc_deinit();
        goto error;
    }

    if( vlc_clone( &p_sys->thread, Run, p_intf, VLC_THREAD_PRIORITY_LOW ) )
    {
        lirc_freeconfig( p_sys->config );
        lirc_deinit();
        goto error;
    }

    return VLC_SUCCESS;

error:
    free( p_sys );
    return VLC_EGENERIC;
}
Пример #18
0
void pa__done(pa_module*m) {
    struct userdata *u;
    pa_assert(m);

    if (!(u = m->userdata))
        return;

    if (u->io)
        m->core->mainloop->io_free(u->io);

    if (u->config)
        lirc_freeconfig(u->config);

    if (u->lirc_fd >= 0)
        lirc_deinit();

    pa_xfree(u->sink_name);
    pa_xfree(u);
}
Пример #19
0
Файл: lirc.cpp Проект: 63n/bino
void lircclient::init()
{
    if (!_initialized)
    {
        int socket_flags;
        _socket = lirc_init(const_cast<char *>(_client_name.c_str()), msg::level() == msg::DBG ? 1 : 0);
        if (_socket == -1)
        {
            throw exc(_("Cannot initialize LIRC."));
        }
        if ((socket_flags = fcntl(_socket, F_GETFL)) < 0
                || fcntl(_socket, F_SETFL, socket_flags | O_NONBLOCK) < 0)
        {
            lirc_deinit();
            throw exc(_("Cannot set LIRC socket properties."));
        }
        if (_conf_files.size() == 0)
        {
            if (lirc_readconfig(NULL, &_config, NULL) != 0)
            {
                lirc_deinit();
                throw exc(_("Cannot read LIRC default configuration."));
            }
        }
        else
        {
            _config = NULL;
            for (size_t i = 0; i < _conf_files.size(); i++)
            {
                if (lirc_readconfig(const_cast<char *>(_conf_files[i].c_str()), &_config, NULL) != 0)
                {
                    if (_config)
                    {
                        lirc_freeconfig(_config);
                    }
                    lirc_deinit();
                    throw exc(str::asprintf(_("Cannot read LIRC configuration file %s."), _conf_files[i].c_str()));
                }
            }
        }
        _initialized = true;
    }
}
Пример #20
0
static void lirc_cleanup(void)
{
    if (config)
    {
        g_source_remove(input_tag);
        lirc_freeconfig(config);
        config = NULL;
    }
    if (lirc_fd != -1)
    {
        lirc_deinit();
        lirc_fd = -1;
    }
    if (gio_chan)
    {
        g_io_channel_shutdown(gio_chan, TRUE, NULL);
        g_io_channel_unref(gio_chan);
    }
}
Пример #21
0
int main(int argc, char **argv)
{
		int retcode;

		/** Init **/
		if (lirc_init("lircE161",1)==-1) exit(EXIT_FAILURE); /* Init lirc_client */
		if (lirc_readconfig( lirc_configfile, &lirc_config, NULL) !=0 ){
				lirc_deinit();
				return EXIT_FAILURE;
		}

		/* Get the command to run on command_buf */
		strcpy(command_buf, getcommand(lirc_config));

		/* build up the arguments in arf_buf at every key press */
		while(1){
				retcode = getnextlircinput();
				if (retcode == LIRCE161_ERROR)
						goto out;
				if (retcode == LIRCE161_DONE) /* done, let get out and run */
						break;
		}

		/* Put the command together */
		sprintf(composite_buf, (const char *)command_buf, arg_buf);
#ifdef DEBUG
		printf("Command is %s\n", command_buf);
		printf("Arguments are %s\n", arg_buf);
		printf("Composite Command is %s\n", composite_buf);
#endif
		system(composite_buf);

		/* finish up */
out:
		lirc_freeconfig(lirc_config);
		lirc_deinit();

		return EXIT_SUCCESS;
}
Пример #22
0
/* This is our thread function.  It is like main(), but for a thread*/
void *threadFunc(void *arg)
{
    struct lirc_config *config;
    int buttonTimer = millis();

    char *code;
    char *c;

    //Initiate LIRC. Exit on failure
    if(lirc_init("lirc",1)==-1)
        exit(EXIT_FAILURE);

    //Read the default LIRC config at /etc/lirc/lircd.conf This is the config for your remot$
    if(lirc_readconfig(NULL,&config,NULL)==0)
    {
        //Do stuff while LIRC socket is open 0=open -1=closed.
        while(lirc_nextcode(&code)==0)
        {
            //If code = NULL, meaning nothing was returned from LIRC socket,
            //then skip lines below and start while loop again.
            if(code==NULL) continue;
            {
                if (millis() - buttonTimer  > 400) {
                    //Check to see if the string "KEY_#" appears anywhere within the string $
                    if(strstr (code,"KEY_F")) {
                        printf("MATCH on KEY_F\n");
                        sLED(0,200,0,0);
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_G")) {
                        printf("MATCH on KEY_G\n");
                        MODE = 2;
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_H")) {
                        printf("MATCH on KEY_H\n");
                        MODE = 1;
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_E")) {
                        printf("MATCH on KEY_E\n");
                        sLED(0,0,100,0);
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_A")) {
                        printf("MATCH on KEY_A\n");
                        sLED(0,0,0,0);
                        buttonTimer = millis();
                    }

                }
            }
            //Need to free up code before the next loop
            free(code);
        }
        //Frees the data structures associated with config.
        lirc_freeconfig(config);
    }
    //lirc_deinit() closes the connection to lircd and does some internal clean-up stuff.
    lirc_deinit();
    //exit(EXIT_SUCCESS);
    return NULL;
}
//Main function
int main(int argc, char* argv[])
{
    //LIRC Variables
    struct lirc_config *config;

    //HTTP Variables
    char *host = "10.0.0.2";
    char *http_request_format = "POST /php/remote_control_api.php HTTP/1.1\n"
                                "Host: 10.0.0.2\n"
                                "Content-Type: application/x-www-form-urlencoded\n"
                                "Content-Length: 10\n\n"
                                "function=%s\n";
    char http_request[MAX_HTTP_REQUEST_LEN];
    char http_response[MAX_HTTP_RESPONSE_LEN];

    //Socket Variables
    int sockfd, error;
    struct addrinfo hints, *addrinfo_list, *addrinfo;

    //Misc Variables
    int valid_key = 0;
    struct timeval tv;
    gettimeofday(&tv, NULL);
    time_t start_time = tv.tv_sec, end_time, time_delay;

    //Outputs usage and exits if given more than one file path in arguments
    if (argc>2)
    {
        fprintf(stderr, "Usage: %s <config file>\n", argv[0]);
        return -1;
    }

    //Initializes LIRC and exits if unsuccessful, called at start of execution
    if (lirc_init("lirc",1)==-1)
    {
        fprintf(stderr, "lirc_init: failed to initialize lirc\n");
        return -1;
    }

    //Clears hints structure and set appropriately for call to getaddrinfo()
    memset(&hints, 0, sizeof hints);
    hints.ai_family = AF_UNSPEC;
    hints.ai_socktype = SOCK_STREAM;

    //Gets the linked list of possible addrinfo structures
    if (error = getaddrinfo(host, PORT, &hints, &addrinfo_list) != 0)
    {
        fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(error));
        return -1;
    }

    //Iterate through linked list of possible addrinfo structures and attempts to create socket to connect to
    for (addrinfo = addrinfo_list; addrinfo != NULL; addrinfo = addrinfo->ai_next)
    {
        //Creates a socket
        if ((sockfd = socket(addrinfo->ai_family, addrinfo->ai_socktype, addrinfo->ai_protocol)) == -1)
        {
            continue;
        }

        //Connect to socket
        if (connect(sockfd, addrinfo->ai_addr, addrinfo->ai_addrlen) == -1)
        {
            close(sockfd);
            continue;
        }

        //Break out of loop if calls to socket() and connect() are both successful
        break;
    }

    //If none of the addrinfo structures in the linked list works, then exit program
    if (addrinfo == NULL)
    {
        fprintf(stderr, "failed to connect to %s\n", host);
        return -1;
    }

    fprintf(stdout, "connection to %s was successful\n\n", host);

    close(sockfd);

    //Read in configuration file from either argument or default path
    if (lirc_readconfig(argc==2 ? argv[1]:NULL, &config, NULL) == 0)
    {
        char *code; //Used to store the key code of the remote

        //Blocks the program until an IR signal is recieved from key press
        while (lirc_nextcode(&code)==0)
        {
            //Handle logic key press, if any
            if (code==NULL) continue;
            {
                gettimeofday(&tv, NULL);
                end_time = tv.tv_sec;
                printf("Starttime=%ld\tEndtime=%ld\n\n", start_time, end_time);
                if (end_time - start_time > DELAY)
                {
                    //Clears request and response buffer
                    memset(&http_request, 0, sizeof http_request);
                    memset(&http_response, 0, sizeof http_response);

                    if (strstr(code,"KEY_POWER"))
                    {
                        if ((valid_key = handle_key_power(http_request, http_request_format)) == -1) { return -1; }
                    }
                    else if (strstr(code,"KEY_STOP"))
                    {
                        if ((valid_key = handle_key_stop(http_request, http_request_format)) == -1) { return -1; }
                    }
                    else if (strstr(code,"KEY_PAUSE"))
                    {
                        if ((valid_key = handle_key_pause(http_request, http_request_format)) == -1) { return -1; }
                    }
                    else if (strstr(code,"KEY_PLAY"))
                    {
                        if ((valid_key = handle_key_play(http_request, http_request_format)) == -1) { return -1; }
                    }
                    else if (strstr(code,"KEY_REWIND"))
                    {
                        if ((valid_key = handle_key_rewind(http_request, http_request_format)) == -1) { return -1; }
                    }
                    else if (strstr(code,"KEY_FORWARD"))
                    {
                        if ((valid_key = handle_key_forward(http_request, http_request_format)) == -1) { return -1; }
                    }

                    if (valid_key)
                    {
                        //Creates socket
                        if ((sockfd = socket(addrinfo->ai_family, addrinfo->ai_socktype, addrinfo->ai_protocol)) == -1)
                        {
                            return -1;
                        }

                        //Connect to socket
                        if (connect(sockfd, addrinfo->ai_addr, addrinfo->ai_addrlen) == -1)
                        {
                            close(sockfd);
                            return -1;
                        }

                        if (send_http_request(sockfd, http_request) == -1)
                        {
                            fprintf(stderr, "An error has occur while sending the HTTP request\n");
                        }
                        else
                        {
                            fprintf(stdout, "HTTP request has been sent successfully.\n"
                                            "--------------------------------------------------\n"
                                            "%s\n\n", http_request);
                        }

                        if (receive_http_response(sockfd, http_response) == -1)
                        {
                            fprintf(stderr, "An error has occur while receiving the HTTP response\n");
                        }
                        else
                        {
                            fprintf(stdout, "HTTP response has been received successfully.\n"
                                            "--------------------------------------------------\n"
                                            "%s\n\n", http_response);
                        }

                        close(sockfd);
                    }
                    gettimeofday(&tv, NULL);
                    start_time = tv.tv_sec;
                }
            }
            free(code); //Free allocated memory for code after key press is handled
        }
        lirc_freeconfig(config); //Free allocated memory for configuration structure
    }

    //Deallocate memory from linked list of addrinfo structures
    freeaddrinfo(addrinfo_list);

    lirc_deinit(); //Deinitializes LIRC, called at end of program execution

    return 0; //EXIT_SUCCESS
} //end of main()
Пример #24
0
int main(int argc, char** argv)
{
	char* configfile;
	const char* socketfile = NULL;
	mode_t permission = S_IRUSR | S_IWUSR;
	int socket;
	int lircdfd;
	struct sigaction act;
	struct sockaddr_un addr;
	char dir[FILENAME_MAX + 1] = { 0 };

	lirc_log_open("lircrcd", 0, LIRC_NOLOG);
	while (1) {
		int c;
		static struct option long_options[] = {
			{ "help",	no_argument,	   NULL, 'h' },
			{ "version",	no_argument,	   NULL, 'v' },
			{ "permission", required_argument, NULL, 'p' },
			{ "output",	required_argument, NULL, 'o' },
			{ 0,		0,		   0,	 0   }
		};
		c = getopt_long(argc, argv, "hvp:o:", long_options, NULL);
		if (c == -1)
			break;
		switch (c) {
		case 'h':
			printf("Usage: %s [options] config-file\n", progname);
			printf("\t -h --help\t\t\tdisplay this message\n");
			printf("\t -v --version\t\t\tdisplay version\n");
			printf("\t -p --permission=mode\t\tfile permissions for socket\n");
			printf("\t -o --output=socket\t\toutput socket filename\n");
			return EXIT_SUCCESS;
		case 'v':
			printf("%s %s\n", progname, VERSION);
			return EXIT_SUCCESS;
		case 'p':
			if (oatoi(optarg) == -1) {
				fprintf(stderr, "%s: invalid mode\n", progname);
				return EXIT_FAILURE;
			}
			permission = oatoi(optarg);
			break;
		case 'o':
			socketfile = optarg;
			break;
		default:
			printf("Usage: %s [options] config-file\n", progname);
			return EXIT_FAILURE;
		}
	}
	if (optind == argc - 1) {
		configfile = argv[optind];
	} else {
		fprintf(stderr, "%s: invalid argument count\n", progname);
		return EXIT_FAILURE;
	}

	lircdfd = lirc_init("lircrcd", 0);
	if (lircdfd == -1)
		return EXIT_FAILURE;

	/* read config file */
	if (lirc_readconfig_only(configfile, &config, NULL) != 0) {
		lirc_deinit();
		return EXIT_FAILURE;
	}

	/* open socket */
	socket = opensocket(config->lircrc_class, socketfile, permission, &addr);
	if (socket == -1) {
		lirc_freeconfig(config);
		lirc_deinit();
		return EXIT_FAILURE;
	}

	/* fork */
	if (getcwd(dir, sizeof(dir)) == NULL) {
		lirc_freeconfig(config);
		lirc_deinit();
		perror("getcwd()");
		return EXIT_FAILURE;
	}
	if (daemon(0, 0) == -1) {
		perror("daemon() failed");
		shutdown(socket, 2);
		close(socket);
		lirc_deinit();
		lirc_freeconfig(config);
		return EXIT_FAILURE;
	}
	daemonized = 1;

	openlog(progname, LOG_CONS | LOG_PID, LOG_USER);
	umask(0);
	signal(SIGPIPE, SIG_IGN);

	act.sa_handler = sigterm;
	sigfillset(&act.sa_mask);
	act.sa_flags = SA_RESTART;      /* don't fiddle with EINTR */
	sigaction(SIGTERM, &act, NULL);
	sigaction(SIGINT, &act, NULL);
	sigaction(SIGHUP, &act, NULL);

	log_notice("%s started", progname);
	loop(socket, lircdfd);

	closelog();
	shutdown(socket, 2);
	close(socket);
	if (chdir(dir) == 0)
		unlink(addr.sun_path);
	lirc_freeconfig(config);
	lirc_deinit();
	return EXIT_SUCCESS;
}
Пример #25
0
int main(int argc, char* argv[])
{
	char keyname[128];
	int pointer_button, pointer_x, pointer_y;
	char windowname[64];
	struct lirc_config* config;
	char* config_file = NULL;
	int c;
	unsigned int WindowID;

	while ((c = getopt_long(argc, argv, "dhV", long_options, NULL)) != EOF) {
		switch (c) {
		case 'd':
			bDaemon = 1;
			continue;
		case 'h':
			printf("Usage: %s [option]... [config file]\n"
			       "       -d --daemon     fork and run in background\n"
			       "       -h --help       display usage summary\n"
			       "       -V --version    display version\n", prog);
			return EXIT_SUCCESS;
		case 'V':
			printf("%s %s\n", prog, VERSION);
			return EXIT_SUCCESS;
		case '?':
			fprintf(stderr, "unrecognized option: -%c\n", optopt);
			fprintf(stderr, "Try `%s --help' for more information.\n", prog);
			return EXIT_FAILURE;
		}
	}

	if (argc == optind + 1) {
		config_file = argv[optind];
	} else if (argc > optind + 1) {
		fprintf(stderr, "%s: incorrect number of arguments.\n", prog);
		fprintf(stderr, "Try `%s --help' for more information.\n", prog);
		return EXIT_FAILURE;
	}

	dpy = XOpenDisplay(NULL);
	if (dpy == NULL) {
		fprintf(stderr, "Can't open DISPLAY.\n");
		exit(1);
	}
	root = RootWindow(dpy, DefaultScreen(dpy));

	// windows may get closed at wrong time. Override default error handler...
	XSetErrorHandler(errorHandler);

	if (lirc_init("irxevent", 1) == -1)
		exit(EXIT_FAILURE);

	if (lirc_readconfig(config_file, &config, check) == 0) {
		char* ir;
		char* c;
		int ret;

		if (bDaemon) {
			if (daemon(1, 0) < 0) {
				perror("Failed to run as daemon");
				exit(EXIT_FAILURE);
			}
		}

		while (lirc_nextcode(&ir) == 0) {
			if (ir == NULL)
				continue;
			while ((ret = lirc_code2char(config, ir, &c)) == 0 && c != NULL) {
				log_debug("Received code: %s Sending:\n", ir);
				bInError = 0;   // reset error state, want to see error msg

				*windowname = 0;
				if (2 == sscanf(c, "Key %s Focus WindowID %i", keyname, &WindowID) ||
				    4 == sscanf(c, "Button %d %d %d Focus WindowID %i", &pointer_button, &pointer_x,
						&pointer_y, &WindowID)
				    || 4 == sscanf(c, "xy_Key %d %d %s Focus WindowID %i", &pointer_x, &pointer_y,
						   keyname, &WindowID)
				    || 2 == sscanf(c, "Key %s Focus %s", keyname, windowname)
				    || 4 == sscanf(c, "Button %d %d %d Focus %s", &pointer_button, &pointer_x,
						   &pointer_y, windowname)
				    || 4 == sscanf(c, "xy_Key %d %d %s Focus %s", &pointer_x, &pointer_y, keyname,
						   windowname)) {
					log_debug("Focus\n");
					/* focussed ? */
					if (*windowname) {
						WindowID = find_window_focused(root, windowname);
						if (!WindowID) {
							log_debug("target window '%s' doesn't have focus\n",
								  windowname);
							continue;
						}
						log_debug("focused:  %s\n", windowname);
					} else {
						Window cur;
						int tmp;

						XGetInputFocus(dpy, &cur, &tmp);
						if (WindowID != cur) {
							log_debug("target window '0x%x' doesn't have focus\n",
								  WindowID);
							continue;
						}
						log_debug("focused:  0x%x\n", WindowID);
					}
				} else if (2 == sscanf(c, "Key %s WindowID %i", keyname, &WindowID) ||
					   4 == sscanf(c, "Button %d %d %d WindowID %i", &pointer_button, &pointer_x,
						       &pointer_y, &WindowID)
					   || 4 == sscanf(c, "xy_Key %d %d %s WindowID %i", &pointer_x, &pointer_y,
							  keyname, &WindowID)) {
					log_debug("WindowID:  0x%x\n", WindowID);
					/* WindowID passed */
				} else if (2 == sscanf(c, "Key %s %s", keyname, windowname) ||
					   4 == sscanf(c, "Button %d %d %d %s", &pointer_button, &pointer_x, &pointer_y,
						       windowname)
					   || 4 == sscanf(c, "xy_Key %d %d %s %s\n", &pointer_x, &pointer_y, keyname,
							  windowname)) {
					log_debug("name: %s\n", windowname);
					WindowID = find_window(root, windowname);
					if (WindowID == 0) {
						log_debug("target window '%s' not found\n", windowname);
						continue;
					}
				}

				switch (c[0]) {
				case 'K':       // Key
					log_debug("keyname: %s \t WindowID: 0x%x\n", keyname, WindowID);
					log_debug("%s\n", c);
					sendkey(keyname, 1, 1, (Window)WindowID, 0);
					break;

				case 'B':       // Button
				case 'x':       // xy_Key
					subw = find_sub_window(root, windowname, &pointer_x, &pointer_y);
					if (subw) {
						if (WindowID == subw)
							subw = 0;
						log_debug("%s\n", c);
						switch (c[0]) {
						case 'B':
							/* FIXME: pointer_button potentially uninititalzed. */
							sendbutton(pointer_button, pointer_x, pointer_y, WindowID,
								   subw);
							break;
						case 'x':
							sendkey(keyname, pointer_x, pointer_y, WindowID, subw);
							break;
						}
					}
					break;
				}
			}
			free(ir);
			if (ret == -1)
				break;
		}
		lirc_freeconfig(config);
	}

	lirc_deinit();

	exit(0);
}
Пример #26
0
static void copy_loop(int ptym, int ignoreeof)
{
	pid_t child;
	int nread;
	char buf[BUFFSIZE];
	struct sigaction act;

	if ((child = fork()) < 0) {
		die("fork error");
	} else if (!child) {
		fd_set fds;

		while (1) {
			FD_ZERO(&fds);
			FD_SET(lsock, &fds);
			FD_SET(STDIN_FILENO, &fds);
			select(lsock + 1, &fds, NULL, NULL, NULL);

			if (FD_ISSET(STDIN_FILENO, &fds)) {
				if ((nread = read(STDIN_FILENO, buf, BUFFSIZE)) < 0)
					die("read error from stdin");
				else if (!nread)
					break;
				if (write(ptym, buf, nread) != nread)
					die("writen error to master pty");
			}
			if (FD_ISSET(lsock, &fds)) {
				char* ir;
				char* irchars;
				int ret;

				while ((ret = lirc_nextcode(&ir)) == 0) {
					if (ir == NULL)
						break;
					while ((ret = lirc_code2char(lconfig, ir, &irchars)) == 0 && irchars != NULL)
						if (write(ptym, irchars, strlen(irchars)) != (int) strlen(irchars))
							die("writen error to master pty");
					free(ir);
					if (ret == -1)
						break;
				}
				if (ret == -1)
					break;
			}
		}
		if (!ignoreeof)
			kill(getppid(), SIGTERM);
		lirc_freeconfig(lconfig);
		lirc_deinit();
		_exit(0);
	}

	act.sa_handler = sig_term;
	sigemptyset(&act.sa_mask);
	act.sa_flags = 0;       /* we need EINTR */
	sigaction(SIGTERM, &act, NULL);

	while (1) {
		if ((nread = read(ptym, buf, BUFFSIZE)) <= 0)
			break;
		if (write(STDOUT_FILENO, buf, nread) != nread)
			die("writen error to stdout");
	}
	if (!sigcaught)
		kill(child, SIGTERM);
	lirc_freeconfig(lconfig);
	lirc_deinit();
}
Пример #27
0
void master_irda::run()
{

    c_irda_logic irda_queue(my_data2);
    //Read the default LIRC config at /etc/lirc/lircd.conf  This is the config for your remote.
    if(lirc_readconfig(NULL,&config,NULL)==0)
    {
        // std::cout << " jestem w iflirc_readconfig(NULL,&config,NULL)==0 \n ";
        //Do stuff while LIRC socket is open  0=open  -1=closed.
        while(lirc_nextcode(&code)==0 )
        {
            std::cout << " w while \n";
            if (go_while==false)     /// TO NIE DZIALA DO POPRAWY
            {
                break;  // koncze petle zamykam wątek
            }
            //If code = NULL, meaning nothing was returned from LIRC socket,
            //then skip lines below and start while loop again.
            if(code==NULL) {
                std::cout << " kontynuuje\n";
                continue;}
            {
                //Make sure there is a 400ms gap before detecting button presses.
                if (millis() - buttonTimer  > 400 ){

                    digitalWrite(BUZZER,ON);

                    // time out   OK menu
                    if (millis() - buttonTimer  > 30000 && buttonMENU == 1){
                        log_file_mutex.mutex_lock();
                        log_file_cout << INFO<< " timeout menu " <<  std::endl;
                        log_file_mutex.mutex_unlock();
                        buttonMENU=0;  // flaga na 0  nie wejdze juz do timeout
                        irda_queue._add('e');
                    }
                    //////////////////////////////////////////////////////////////
                    //Check to see if the string "KEY_1" appears anywhere within the string 'code'.

                    if(strstr (code,"KEY_POWER")){
                        log_file_mutex.mutex_lock();
                        log_file_cout << INFO<< " wcisnieto POWER" <<  std::endl;
                        log_file_mutex.mutex_unlock();
                        irda_queue._add('P');
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_1")){
                        irda_queue._add('1');
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_2")){
                        irda_queue._add('2');
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_3")){
                        irda_queue._add('3');
                        //my_data2->mainLCD->printString(1,1,"klawisz 3");
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_4")){
                        irda_queue._add('4');
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_5")){
                        irda_queue._add('5');
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_6")){
                        irda_queue._add('6');
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_7")){
                        irda_queue._add('7');
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_8")){
                        irda_queue._add('8');
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_9")){
                        irda_queue._add('9');
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_0")){
                        irda_queue._add('0');
                        buttonTimer = millis();
                    }
                    ////////////////////////////////////
                    else if(strstr (code,"KEY_INFO")){
                        log_file_mutex.mutex_lock();
                        log_file_cout << INFO<< " operacja na diodzie" <<  std::endl;
                        log_file_mutex.mutex_unlock();
                        irda_queue._add('I');
                        buttonTimer = millis();
                    }
                    /////////////////////////////////////////////////
                    else if(strstr (code,"KEY_TV")){
                        log_file_mutex.mutex_lock();
                        log_file_cout << INFO<< " wcisnieto PLAY" <<  std::endl;
                        log_file_mutex.mutex_unlock();
                        irda_queue._add('t');
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_AUDIO")){
                        log_file_mutex.mutex_lock();
                        log_file_cout << INFO<< " wcisnieto PAUSE" <<  std::endl;
                        log_file_mutex.mutex_unlock();
                        irda_queue._add('A');
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_VOLUMEUP")){
                        irda_queue._add('+');
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_VOLUMEDOWN")){
                        irda_queue._add('-');
                        buttonTimer = millis();
                    }
                    /////////////////////////////////////////////

                    else if(strstr (code,"KEY_DOWN")){
                        irda_queue._add('D');
                        buttonTimer = millis();
                    }

                    else if(strstr (code,"KEY_UP")){
                        irda_queue._add('U');
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_OK")){
                        irda_queue._add('O');
                        buttonMENU=0;
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_MENU")){
                        irda_queue._add('M');
                        buttonMENU=1;// wlacz timeout dla menu
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_EXIT")){
                        irda_queue._add('e');
                        buttonMENU = 0;
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_RADIO")){
                        log_file_mutex.mutex_lock();
                        log_file_cout << INFO<< " sterowanie projektorem" <<  std::endl;
                        log_file_mutex.mutex_unlock();
                        irda_queue._add('r');   //idziemy do sterowania projektorem
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_EPG")){
                        log_file_mutex.mutex_lock();
                        log_file_cout << INFO<< " przegladanie katalogu z filmami" <<  std::endl;
                        log_file_mutex.mutex_unlock();
                        buttonMENU=1;
                        irda_queue._add('E');   //idziemy do sterowania projektorem
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_CHANNELUP")){

                        irda_queue._add('^');
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_CHANNELDOWN")){

                        irda_queue._add('/');
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_MUTE")){
                        irda_queue._add('m');
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_FAVORITES")){
                        irda_queue._add('F');
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_REFRESH")){
                        irda_queue._add('R');
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_LANGUAGE")){
                        irda_queue._add('L');
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_SUBTITLE")){
                        irda_queue._add('S');
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_SAT")){
                        irda_queue._add('s');
                        buttonTimer = millis();
                    }
                    else if(strstr (code,"KEY_TEXT")){
                        irda_queue._add('T');
                        buttonTimer = millis();
                    }
                }
            }
            //Need to free up code before the next loop
            free(code);

            digitalWrite(BUZZER,OFF);
        }
        //Frees the data structures associated with config.
        lirc_freeconfig(config);
    }
    log_file_mutex.mutex_lock();
    log_file_cout << INFO << " koniec watku master IRDA  "<<   std::endl;
    log_file_mutex.mutex_unlock();


    //lirc_deinit() closes the connection to lircd and does some internal clean-up stuff.
    lirc_deinit();
    // exit(EXIT_SUCCESS);


}
Пример #28
0
int main(int argc, char *argv[])
{
	struct lirc_config *config;
	int daemonize=0;

	progname="irexec-" VERSION;
	while(1)
	{
		int c;
		static struct option long_options[] =
		{
			{"help",no_argument,NULL,'h'},
			{"version",no_argument,NULL,'v'},
#ifdef DAEMONIZE
			{"daemon",no_argument,NULL,'d'},
#endif
			{0, 0, 0, 0}
		};
		c = getopt_long(argc,argv,"hvd",long_options,NULL);
		if(c==-1)
			break;
		switch (c)
		{
		case 'h':
			printf("Usage: %s [options] [config_file]\n",argv[0]);
			printf("\t -h --help\t\tdisplay this message\n");
			printf("\t -v --version\t\tdisplay version\n");
#ifdef DAEMONIZE
			printf("\t -d --daemon\t\trun in background\n");
#endif
			return(EXIT_SUCCESS);
		case 'v':
			printf("%s\n",progname);
			return(EXIT_SUCCESS);
#ifdef DAEMONIZE
		case 'd':
			daemonize=1;
			break;
#endif
		default:
			printf("Usage: %s [options] [config_file]\n",argv[0]);
			return(EXIT_FAILURE);
		}
	}
	if (optind < argc-1)
	{
		fprintf(stderr,"%s: too many arguments\n",progname);
		return(EXIT_FAILURE);
	}
	
	if(lirc_init("irexec",daemonize ? 0:1)==-1) exit(EXIT_FAILURE);

	if(lirc_readconfig(optind!=argc ? argv[optind]:NULL,&config,NULL)==0)
	{
		char *code;
		char *c;
		int ret;

#ifdef DAEMONIZE
		if(daemonize)
		{
			if(daemon(0,0)==-1)
			{
				fprintf(stderr,"%s: can't daemonize\n",
					progname);
				perror(progname);
				lirc_freeconfig(config);
				lirc_deinit();
				exit(EXIT_FAILURE);
			}
		}
#endif
		while(lirc_nextcode(&code)==0)
		{
			if(code==NULL) continue;
			while((ret=lirc_code2char(config,code,&c))==0 &&
			      c!=NULL)
			{
#if defined(DAEMONIZE) && defined(DEBUG)
				if(!daemonize)
				{
					printf("Execing command \"%s\"\n",c);
				}
#endif
				system(c);
			}
			free(code);
			if(ret==-1) break;
		}
		lirc_freeconfig(config);
	}

	lirc_deinit();
	exit(EXIT_SUCCESS);
}
Пример #29
0
static void copy_loop(int ptym, int ignoreeof)
{
	pid_t child;
	int nread;
	char buf[BUFFSIZE];
	struct sigaction act;
	struct pollfd pfd[2] = {
		{lsock, POLLIN, 0},
		{STDIN_FILENO, POLLIN, 0}
                // fd, events, revents
	};;

	if ((child = fork()) < 0) {
		die("fork error");
	} else if (!child) {

		while (1) {
			poll(pfd, 2, 0);

			if (pfd[1].revents & POLLIN) { /* STDIN_FILENO */
				if ((nread = read(STDIN_FILENO, buf, BUFFSIZE)) < 0)
					die("read error from stdin");
				else if (!nread)
					break;
				if (write(ptym, buf, nread) != nread)
					die("writen error to master pty");
			}
			if (pfd[0].revents & POLLIN) {  /*lsock */
				char* ir;
				char* irchars;
				int ret;

				while ((ret = lirc_nextcode(&ir)) == 0) {
					if (ir == NULL)
						break;
					while ((ret = lirc_code2char(lconfig, ir, &irchars)) == 0 && irchars != NULL)
						if (write(ptym, irchars, strlen(irchars)) != (int) strlen(irchars))
							die("writen error to master pty");
					free(ir);
					if (ret == -1)
						break;
				}
				if (ret == -1)
					break;
			}
		}
		if (!ignoreeof)
			kill(getppid(), SIGTERM);
		lirc_freeconfig(lconfig);
		lirc_deinit();
		_exit(0);
	}

	act.sa_handler = sig_term;
	sigemptyset(&act.sa_mask);
	act.sa_flags = 0;       /* we need EINTR */
	sigaction(SIGTERM, &act, NULL);

	while (1) {
		if ((nread = read(ptym, buf, BUFFSIZE)) <= 0)
			break;
		if (write(STDOUT_FILENO, buf, nread) != nread)
			die("writen error to stdout");
	}
	if (!sigcaught)
		kill(child, SIGTERM);
	lirc_freeconfig(lconfig);
	lirc_deinit();
}
Пример #30
0
int lirc_readconfig(const struct lirc_state *state,
                    const char *file,
                    struct lirc_config **config,
                    int (check)(char *s))
{
	struct sockaddr_un addr;
	int sockfd = -1;
	char *sha_bang, *filename;
	const char *sha_bang2;
	char *command;
	unsigned int ret;
	
	filename = NULL;
	sha_bang = NULL;
	if(lirc_readconfig_only_internal(state,file,config,check,&filename,&sha_bang)==-1)
	{
		return -1;
	}
	
	if(sha_bang == NULL)
	{
		goto lirc_readconfig_compat;
	}
	
	/* connect to lircrcd */

	addr.sun_family=AF_UNIX;
	if(lirc_getsocketname(filename, addr.sun_path, sizeof(addr.sun_path))>sizeof(addr.sun_path))
	{
		lirc_printf(state, "%s: WARNING: file name too long\n", state->lirc_prog);
		goto lirc_readconfig_compat;
	}
	sockfd=socket(AF_UNIX,SOCK_STREAM,0);
	if(sockfd==-1)
	{
		lirc_printf(state, "%s: WARNING: could not open socket\n",state->lirc_prog);
		lirc_perror(state, state->lirc_prog);
		goto lirc_readconfig_compat;
	}
	if(connect(sockfd, (struct sockaddr *)&addr, sizeof(addr))!=-1)
	{
		if(sha_bang!=NULL) free(sha_bang);
		(*config)->sockfd=sockfd;
		free(filename);
		
		/* tell daemon state->lirc_prog */
		if(lirc_identify(state, sockfd) == LIRC_RET_SUCCESS)
		{
			/* we're connected */
			return 0;
		}
		close(sockfd);
		lirc_freeconfig(*config);
		return -1;
	}
	close(sockfd);
	sockfd = -1;
	
	/* launch lircrcd */
	sha_bang2=sha_bang!=NULL ? sha_bang:"lircrcd";
	
	command=malloc(strlen(sha_bang2)+1+strlen(filename)+1);
	if(command==NULL)
	{
		goto lirc_readconfig_compat;
	}
	strcpy(command, sha_bang2);
	strcat(command, " ");
	strcat(command, filename);
	
	ret = myth_system_c(command, kMSNone, 0);
	free(command);
	
	if(ret!=EXIT_SUCCESS)
	{
		goto lirc_readconfig_compat;
	}
	
	if(sha_bang!=NULL) { free(sha_bang); sha_bang = NULL; }
	free(filename); filename = NULL;
	
	sockfd=socket(AF_UNIX,SOCK_STREAM,0);
	if(sockfd==-1)
	{
		lirc_printf(state, "%s: WARNING: could not open socket\n",state->lirc_prog);
		lirc_perror(state, state->lirc_prog);
		goto lirc_readconfig_compat;
	}
	if(connect(sockfd, (struct sockaddr *)&addr, sizeof(addr))!=-1)
	{
		if(lirc_identify(state, sockfd) == LIRC_RET_SUCCESS)
		{
			(*config)->sockfd=sockfd;
			return 0;
		}
	}
	close(sockfd);
	lirc_freeconfig(*config);
	return -1;
	
 lirc_readconfig_compat:
	/* compat fallback */
	if(sockfd != -1) close(sockfd);
	if(sha_bang!=NULL) free(sha_bang);
	free(filename);
	return 0;
}