source: libi4uc/i4ucposixserialportutils.vala @ bed559542aed66b07b1f09f793d912e40bb53406

Revision bed559542aed66b07b1f09f793d912e40bb53406, 2.0 KB checked in by Matias De la Puente <mfpuente.ar@…>, 3 years ago (diff)

Create SerialPortUtils? according to the platform

  • Property mode set to 100644
Line 
1/* i4ucposixserialportutils.vala
2 *
3 * Copyright (C) 2010  Matias De la Puente
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Author:
19 *      Matias De la Puente <mfpuente.ar@gmail.com>
20 */
21using Gee;
22using DBus;
23using Hal;
24
25public class I4uc.PosixSerialPortUtils : SerialPortUtils
26{
27        public override Gee.List<string> list_serial_ports ()
28        {
29                var serial_ports = new ArrayList<string> ();
30               
31                var dbus_error = DBus.RawError ();
32                var hal = new Hal.Context ();
33               
34                if (hal == null)
35                        print ("Error getting HAL context\n");
36               
37                if (!hal.set_dbus_connection (RawBus.get (DBus.BusType.SYSTEM, ref dbus_error)))
38                        print ("Error setting dbus connection: %s\n".printf (dbus_error.message));
39               
40                if (!hal.init (ref dbus_error))
41                        print ("Cannot initialize connection to the hald\nNormally this means that the HAL deamon (hald) is not running or not ready\n");
42               
43                var udis = hal.find_device_by_capability ("serial", ref dbus_error);
44                if (dbus_error.is_set ())
45                        print ("Error finding serial devices: %s: %s\n".printf (dbus_error.name, dbus_error.message));
46               
47                foreach (var udi in udis)
48                {
49                        var device = hal.device_get_property_string (udi, "serial.device", ref dbus_error);
50                        if (dbus_error.is_set ())
51                                print ("Error getting property string: %s: %s\n".printf (dbus_error.name, dbus_error.message));
52                        serial_ports.add (device);
53                }
54               
55                return serial_ports.read_only_view;
56        }
57}
Note: See TracBrowser for help on using the repository browser.