~ubuntu-branches/ubuntu/karmic/pommed/karmic

« back to all changes in this revision

Viewing changes to pommed/pommed.c

  • Committer: Bazaar Package Importer
  • Author(s): Julien BLACHE
  • Date: 2007-11-18 13:47:18 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20071118134718-xanyixemly8hvan8
Tags: 1.11~dfsg-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * pommed - Apple laptops hotkeys handler daemon
3
3
 *
4
 
 * $Id: pommed.c 362 2007-10-01 15:11:34Z jblache $
 
4
 * $Id: pommed.c 376 2007-11-16 18:31:15Z jblache $
5
5
 *
6
6
 * Copyright (C) 2006-2007 Julien BLACHE <jb@jblache.org>
7
7
 *
28
28
#include <sys/time.h>
29
29
#include <time.h>
30
30
#include <string.h>
31
 
#include <poll.h>
32
31
#include <signal.h>
33
32
 
34
33
#include <syslog.h>
241
240
 
242
241
#else
243
242
 
 
243
/* Dummy backlight ops */
 
244
 
 
245
int
 
246
dummy_backlight_probe(void)
 
247
{
 
248
  logmsg(LOG_WARNING, "Backlight not supported on this model yet");
 
249
 
 
250
  return 0;
 
251
}
 
252
 
 
253
void
 
254
dummy_backlight_step(int dir)
 
255
{
 
256
  /* void */
 
257
}
 
258
 
 
259
void
 
260
dummy_backlight_toggle(int lvl)
 
261
{
 
262
  /* void */
 
263
}
 
264
 
244
265
struct machine_ops mb_mops[] = {
245
266
  /* MacBook Pro machines */
246
267
 
284
305
    .lcd_backlight_step = gma950_backlight_step,
285
306
    .lcd_backlight_toggle = gma950_backlight_toggle,
286
307
    .evdev_identify = evdev_is_geyser4,
 
308
  },
 
309
 
 
310
  {  /* MacBook3,1 (Core2 Duo Santa Rosa, November 2007) */
 
311
    .type = MACHINE_MACBOOK_3,
 
312
    .lcd_backlight_probe = dummy_backlight_probe,
 
313
    .lcd_backlight_step = dummy_backlight_step,
 
314
    .lcd_backlight_toggle = dummy_backlight_toggle,
 
315
    .evdev_identify = evdev_is_geyser4hf,
287
316
  }
288
317
};
289
318
#endif /* __powerpc__ */
568
597
  /* Core2 Duo MacBook (November 2006) */
569
598
  else if (strcmp(prop, "MacBook2,1") == 0)
570
599
    ret = MACHINE_MACBOOK_2;
 
600
  /* Core2 Duo Santa Rosa MacBook (November 2007) */
 
601
  else if (strcmp(prop, "MacBook3,1") == 0)
 
602
    ret = MACHINE_MACBOOK_3;
571
603
  else
572
604
    logmsg(LOG_ERR, "Unknown Apple machine: %s", prop);
573
605
 
584
616
static void
585
617
usage(void)
586
618
{
587
 
  printf("pommed v" M_VERSION " ($Rev: 362 $) Apple laptops hotkeys handler\n");
 
619
  printf("pommed v" M_VERSION " ($Rev: 376 $) Apple laptops hotkeys handler\n");
588
620
  printf("Copyright (C) 2006-2007 Julien BLACHE <jb@jblache.org>\n");
589
621
 
590
622
  printf("Usage:\n");
606
638
{
607
639
  int ret;
608
640
  int c;
609
 
  int i;
610
641
 
611
642
  FILE *pidfile;
612
643
 
613
 
  struct pollfd *fds;
614
 
  int nfds;
615
 
 
616
 
  int reopen;
617
644
  machine_type machine;
618
645
 
619
646
  struct timeval tv_now;
634
661
            break;
635
662
 
636
663
          case 'v':
637
 
            printf("pommed v" M_VERSION " ($Rev: 362 $) Apple laptops hotkeys handler\n");
 
664
            printf("pommed v" M_VERSION " ($Rev: 376 $) Apple laptops hotkeys handler\n");
638
665
            printf("Copyright (C) 2006-2007 Julien BLACHE <jb@jblache.org>\n");
639
666
 
640
667
            exit(0);
653
680
      openlog("pommed", LOG_PID, LOG_DAEMON);
654
681
    }
655
682
 
656
 
  logmsg(LOG_INFO, "pommed v" M_VERSION " ($Rev: 362 $) Apple laptops hotkeys handler");
 
683
  logmsg(LOG_INFO, "pommed v" M_VERSION " ($Rev: 376 $) Apple laptops hotkeys handler");
657
684
  logmsg(LOG_INFO, "Copyright (C) 2006-2007 Julien BLACHE <jb@jblache.org>");
658
685
 
659
686
  /* Load our configuration */
711
738
      exit(1);
712
739
    }
713
740
 
714
 
  nfds = evdev_open(&fds);
715
 
  if (nfds < 1)
 
741
  ret = evdev_init();
 
742
  if (ret < 3)
716
743
    {
717
744
      logmsg(LOG_ERR, "No suitable event devices found");
718
745
 
719
746
      exit(1);
720
747
    }
721
748
 
722
 
  kbd_set_fnmode();
723
749
  kbd_backlight_init();
724
750
 
725
751
  ret = audio_init();
745
771
        {
746
772
          logmsg(LOG_ERR, "daemon() failed: %s", strerror(errno));
747
773
 
748
 
          evdev_close(&fds, nfds);
 
774
          evdev_cleanup();
749
775
 
750
776
          exit(-1);
751
777
        }
756
782
    {
757
783
      logmsg(LOG_WARNING, "Could not open pidfile %s: %s", PIDFILE, strerror(errno));
758
784
 
759
 
      evdev_close(&fds, nfds);
 
785
      evdev_cleanup();
760
786
 
761
787
      exit(-1);
762
788
    }
772
798
  signal(SIGINT, sig_int_term_handler);
773
799
  signal(SIGTERM, sig_int_term_handler);
774
800
 
775
 
  reopen = 0;
776
801
 
777
802
  while (running)
778
803
    {
779
 
      /* Attempt to reopen event devices, typically after resuming */
780
 
      if (reopen)
781
 
        {
782
 
          nfds = evdev_reopen(&fds, nfds);
783
 
 
784
 
          if (nfds < 1)
785
 
            {
786
 
              logmsg(LOG_ERR, "No suitable event devices found (reopen)");
787
 
 
788
 
              break;
789
 
            }
790
 
 
791
 
          /* Re-set the keyboard mode
792
 
           * When we need to reopen the event devices, it means we've
793
 
           * just resumed from sleep
794
 
           */
795
 
          kbd_set_fnmode();
796
 
 
797
 
          reopen = 0;
798
 
        }
799
 
 
800
 
      ret = poll(fds, nfds, LOOP_TIMEOUT);
 
804
      ret = evdev_event_loop();
801
805
 
802
806
      gettimeofday(&tv_now, NULL);
803
807
 
804
808
      if (ret < 0) /* error */
805
809
        {
806
 
          if (errno != EINTR)
807
 
            {
808
 
              logmsg(LOG_ERR, "poll() error: %s", strerror(errno));
809
 
 
810
 
              break;
811
 
            }
 
810
          break;
812
811
        }
813
812
      else if (ret != 0)
814
813
        {
815
 
          for (i = 0; i < nfds; i++)
816
 
            {
817
 
              /* the event devices cease to exist when suspending */
818
 
              if (fds[i].revents & (POLLERR | POLLHUP | POLLNVAL))
819
 
                {
820
 
                  logmsg(LOG_WARNING, "Error condition signaled on evdev, reopening");
821
 
                  reopen = 1;
822
 
                  break;
823
 
                }
824
 
 
825
 
              if (fds[i].revents & POLLIN)
826
 
                evdev_process_events(fds[i].fd);
827
 
            }
828
 
 
829
814
          /* is it time to chek the ambient light sensors and AC state ? */
830
815
          tv_diff.tv_sec = tv_now.tv_sec - tv_als.tv_sec;
831
816
          if (tv_diff.tv_sec < 0)
870
855
      mbpdbus_process_requests();
871
856
    }
872
857
 
873
 
  evdev_close(&fds, nfds);
 
858
  evdev_cleanup();
874
859
 
875
860
  beep_cleanup();
876
861