mconnect - KDE Connect protocol implementation in Vala/C
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.0 KiB

  1. /* ex:ts=4:sw=4:sts=4:et */
  2. /* -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
  3. /**
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along
  14. * with this program; if not, write to the Free Software Foundation, Inc.,
  15. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  16. *
  17. * AUTHORS
  18. * Maciek Borzecki <maciek.borzecki (at] gmail.com>
  19. */
  20. class PacketHandlers : Object {
  21. private List<PacketHandlerInterface> _handlers = null;
  22. public List<PacketHandlerInterface> handlers {
  23. get {
  24. return _handlers;
  25. }
  26. private set {
  27. _handlers = handlers.copy();
  28. }
  29. }
  30. public string[] interfaces { get; private set; default = null; }
  31. public PacketHandlers() {
  32. _handlers = load_handlers();
  33. string [] ifaces;
  34. list_handlers(out ifaces);
  35. interfaces = ifaces;
  36. }
  37. private static List<PacketHandlerInterface> load_handlers() {
  38. List<PacketHandlerInterface> hnd = new List<PacketHandlerInterface>();
  39. var notification = NotificationHandler.instance();
  40. var battery = BatteryHandler.instance();
  41. var telephony = TelephonyHandler.instance();
  42. hnd.append(notification);
  43. hnd.append(battery);
  44. hnd.append(telephony);
  45. return hnd;
  46. }
  47. public void list_handlers(out string[] interfaces) {
  48. interfaces = new string[_handlers.length()];
  49. // string[] interfaces = new string[_handlers.length()];
  50. for (int i = 0; i < _handlers.length(); i++) {
  51. interfaces[i] = _handlers.nth_data(i).get_pkt_type();
  52. }
  53. // return interfaces;
  54. }
  55. public void use_device(Device dev) {
  56. _handlers.foreach((h) => {
  57. h.use_device(dev);
  58. });
  59. }
  60. }