Norman James | 26072c0 | 2015-08-25 07:14:29 -0500 | [diff] [blame] | 1 | #include <stdint.h>
|
| 2 | #include <stdio.h>
|
| 3 | #include <stdlib.h>
|
| 4 | #include <string.h>
|
| 5 | #include <fcntl.h>
|
| 6 | #include <unistd.h>
|
| 7 | #include <sys/stat.h>
|
| 8 | #include <sys/mman.h>
|
Norman James | 8abb50c | 2015-09-16 10:58:16 -0500 | [diff] [blame] | 9 | #include <syslog.h>
|
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 10 | #include "interfaces/openbmc_intf.h"
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 11 | #include "openbmc.h"
|
| 12 | #include "gpio.h"
|
Norman James | cfc2b44 | 2015-10-31 17:31:46 -0500 | [diff] [blame] | 13 | #include "object_mapper.h"
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 14 |
|
| 15 | /* ---------------------------------------------------------------------------------------------------- */
|
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 16 | static const gchar* dbus_object_path = "/org/openbmc/control";
|
Norman James | 8fee6f2 | 2015-10-28 12:48:43 -0500 | [diff] [blame] | 17 | static const gchar* instance_name = "power0";
|
Norman James | 26072c0 | 2015-08-25 07:14:29 -0500 | [diff] [blame] | 18 | static const gchar* dbus_name = "org.openbmc.control.Power";
|
| 19 |
|
Norman James | 32e74e2 | 2015-09-15 21:28:06 -0500 | [diff] [blame] | 20 | //This object will use these GPIOs
|
Norman James | 3f97c5d | 2015-08-26 17:44:14 -0500 | [diff] [blame] | 21 | GPIO power_pin = (GPIO){ "POWER_PIN" };
|
| 22 | GPIO pgood = (GPIO){ "PGOOD" };
|
Norman James | cfc2b44 | 2015-10-31 17:31:46 -0500 | [diff] [blame] | 23 | GPIO usb_reset = (GPIO){ "USB_RESET" };
|
| 24 | GPIO pcie_reset = (GPIO){ "PCIE_RESET" };
|
| 25 |
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 26 |
|
| 27 | static GDBusObjectManagerServer *manager = NULL;
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 28 |
|
Norman James | 8887267 | 2015-09-21 16:51:35 -0500 | [diff] [blame] | 29 | time_t pgood_timeout_start = 0;
|
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 30 |
|
Norman James | 3d3b7fb | 2015-10-06 16:54:06 -0500 | [diff] [blame] | 31 | // TODO: Change to interrupt driven instead of polling
|
Norman James | ce46e3e | 2015-08-30 22:25:55 -0500 | [diff] [blame] | 32 | static gboolean poll_pgood(gpointer user_data)
|
| 33 | {
|
| 34 | ControlPower *control_power = object_get_control_power((Object*)user_data);
|
| 35 | Control* control = object_get_control((Object*)user_data);
|
Norman James | bd4abd1 | 2015-09-16 22:43:46 -0500 | [diff] [blame] | 36 |
|
| 37 | //send the heartbeat
|
Norman James | ce46e3e | 2015-08-30 22:25:55 -0500 | [diff] [blame] | 38 | control_emit_heartbeat(control,dbus_name);
|
Norman James | 32e74e2 | 2015-09-15 21:28:06 -0500 | [diff] [blame] | 39 | const gchar* obj_path = g_dbus_object_get_object_path((GDBusObject*)user_data);
|
Norman James | ce46e3e | 2015-08-30 22:25:55 -0500 | [diff] [blame] | 40 |
|
Norman James | 6a1283c | 2015-09-16 22:21:11 -0500 | [diff] [blame] | 41 | guint poll_int = control_get_poll_interval(control);
|
| 42 | if (poll_int == 0)
|
| 43 | {
|
Norman James | 2891c53 | 2015-10-06 08:01:56 -0500 | [diff] [blame] | 44 | printf("ERROR PowerControl: Poll interval cannot be 0\n");
|
Norman James | 6a1283c | 2015-09-16 22:21:11 -0500 | [diff] [blame] | 45 | return FALSE;
|
| 46 | }
|
Norman James | 8887267 | 2015-09-21 16:51:35 -0500 | [diff] [blame] | 47 | //handle timeout
|
| 48 | time_t current_time = time(NULL);
|
| 49 | if (difftime(current_time,pgood_timeout_start) > control_power_get_pgood_timeout(control_power)
|
| 50 | && pgood_timeout_start != 0)
|
Norman James | 32e74e2 | 2015-09-15 21:28:06 -0500 | [diff] [blame] | 51 | {
|
Norman James | 2891c53 | 2015-10-06 08:01:56 -0500 | [diff] [blame] | 52 | printf("ERROR PowerControl: Pgood poll timeout\n");
|
Norman James | bd4abd1 | 2015-09-16 22:43:46 -0500 | [diff] [blame] | 53 | // set timeout to 0 so timeout doesn't happen again
|
Norman James | 32e74e2 | 2015-09-15 21:28:06 -0500 | [diff] [blame] | 54 | control_power_set_pgood_timeout(control_power,0);
|
Norman James | 8887267 | 2015-09-21 16:51:35 -0500 | [diff] [blame] | 55 | pgood_timeout_start = 0;
|
Norman James | 8abb50c | 2015-09-16 10:58:16 -0500 | [diff] [blame] | 56 | return TRUE;
|
Norman James | 32e74e2 | 2015-09-15 21:28:06 -0500 | [diff] [blame] | 57 | }
|
Norman James | 32e74e2 | 2015-09-15 21:28:06 -0500 | [diff] [blame] | 58 | uint8_t gpio;
|
Norman James | 8887267 | 2015-09-21 16:51:35 -0500 | [diff] [blame] | 59 |
|
| 60 | int rc = gpio_open(&pgood);
|
| 61 | rc = gpio_read(&pgood,&gpio);
|
| 62 | gpio_close(&pgood);
|
Norman James | 32e74e2 | 2015-09-15 21:28:06 -0500 | [diff] [blame] | 63 | if (rc == GPIO_OK)
|
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 64 | {
|
Norman James | 32e74e2 | 2015-09-15 21:28:06 -0500 | [diff] [blame] | 65 | //if changed, set property and emit signal
|
| 66 | if (gpio != control_power_get_pgood(control_power))
|
| 67 | {
|
| 68 | control_power_set_pgood(control_power,gpio);
|
| 69 | if (gpio==0)
|
| 70 | {
|
| 71 | control_power_emit_power_lost(control_power);
|
Norman James | a3e47c4 | 2015-10-18 14:43:10 -0500 | [diff] [blame] | 72 | control_emit_goto_system_state(control,"HOST_POWERED_OFF");
|
Norman James | cfc2b44 | 2015-10-31 17:31:46 -0500 | [diff] [blame] | 73 | rc = gpio_open(&pcie_reset);
|
| 74 | rc = gpio_write(&pcie_reset,0);
|
| 75 | gpio_close(&pcie_reset);
|
| 76 |
|
| 77 | rc = gpio_open(&usb_reset);
|
| 78 | rc = gpio_write(&usb_reset,0);
|
| 79 | gpio_close(&usb_reset);
|
| 80 |
|
Norman James | 32e74e2 | 2015-09-15 21:28:06 -0500 | [diff] [blame] | 81 | }
|
| 82 | else
|
| 83 | {
|
| 84 | control_power_emit_power_good(control_power);
|
Norman James | a3e47c4 | 2015-10-18 14:43:10 -0500 | [diff] [blame] | 85 | control_emit_goto_system_state(control,"HOST_POWERED_ON");
|
Norman James | cfc2b44 | 2015-10-31 17:31:46 -0500 | [diff] [blame] | 86 | rc = gpio_open(&pcie_reset);
|
| 87 | rc = gpio_write(&pcie_reset,1);
|
| 88 | gpio_close(&pcie_reset);
|
| 89 |
|
| 90 | rc = gpio_open(&usb_reset);
|
| 91 | rc = gpio_write(&usb_reset,1);
|
| 92 | gpio_close(&usb_reset);
|
Norman James | 32e74e2 | 2015-09-15 21:28:06 -0500 | [diff] [blame] | 93 | }
|
| 94 | }
|
| 95 | } else {
|
Norman James | 2891c53 | 2015-10-06 08:01:56 -0500 | [diff] [blame] | 96 | printf("ERROR PowerControl: GPIO read error (gpio=%s,rc=%d)\n",pgood.name,rc);
|
Norman James | a3e47c4 | 2015-10-18 14:43:10 -0500 | [diff] [blame] | 97 | //return false so poll won't get called anymore
|
| 98 | return FALSE;
|
Norman James | 32e74e2 | 2015-09-15 21:28:06 -0500 | [diff] [blame] | 99 | }
|
| 100 | //pgood is not at desired state yet
|
| 101 | if (gpio != control_power_get_state(control_power) &&
|
Norman James | 8887267 | 2015-09-21 16:51:35 -0500 | [diff] [blame] | 102 | control_power_get_pgood_timeout(control_power) > 0)
|
Norman James | 32e74e2 | 2015-09-15 21:28:06 -0500 | [diff] [blame] | 103 | {
|
Norman James | 8887267 | 2015-09-21 16:51:35 -0500 | [diff] [blame] | 104 | if (pgood_timeout_start == 0 ) {
|
| 105 | pgood_timeout_start = current_time;
|
| 106 | }
|
Norman James | 32e74e2 | 2015-09-15 21:28:06 -0500 | [diff] [blame] | 107 | }
|
| 108 | else
|
| 109 | {
|
Norman James | 8887267 | 2015-09-21 16:51:35 -0500 | [diff] [blame] | 110 | pgood_timeout_start = 0;
|
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 111 | }
|
Norman James | ce46e3e | 2015-08-30 22:25:55 -0500 | [diff] [blame] | 112 | return TRUE;
|
| 113 | }
|
| 114 |
|
| 115 |
|
| 116 |
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 117 | static gboolean
|
Norman James | 3f97c5d | 2015-08-26 17:44:14 -0500 | [diff] [blame] | 118 | on_set_power_state (ControlPower *pwr,
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 119 | GDBusMethodInvocation *invocation,
|
| 120 | guint state,
|
| 121 | gpointer user_data)
|
| 122 | {
|
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 123 | Control* control = object_get_control((Object*)user_data);
|
Norman James | 32e74e2 | 2015-09-15 21:28:06 -0500 | [diff] [blame] | 124 | const gchar* obj_path = g_dbus_object_get_object_path((GDBusObject*)user_data);
|
Norman James | 3f97c5d | 2015-08-26 17:44:14 -0500 | [diff] [blame] | 125 | if (state > 1)
|
| 126 | {
|
| 127 | g_dbus_method_invocation_return_dbus_error (invocation,
|
| 128 | "org.openbmc.ControlPower.Error.Failed",
|
| 129 | "Invalid power state");
|
| 130 | return TRUE;
|
| 131 | }
|
Norman James | 9e6acf9 | 2015-09-08 07:00:04 -0500 | [diff] [blame] | 132 | // return from method call
|
| 133 | control_power_complete_set_power_state(pwr,invocation);
|
Norman James | 3f97c5d | 2015-08-26 17:44:14 -0500 | [diff] [blame] | 134 | if (state == control_power_get_state(pwr))
|
| 135 | {
|
Norman James | 9e6acf9 | 2015-09-08 07:00:04 -0500 | [diff] [blame] | 136 | g_print("Power already at requested state: %d\n",state);
|
Norman James | 3f97c5d | 2015-08-26 17:44:14 -0500 | [diff] [blame] | 137 | }
|
Norman James | 9e6acf9 | 2015-09-08 07:00:04 -0500 | [diff] [blame] | 138 | else
|
| 139 | {
|
Norman James | 32e74e2 | 2015-09-15 21:28:06 -0500 | [diff] [blame] | 140 | int error = 0;
|
| 141 | do {
|
Norman James | 19e4591 | 2015-10-04 20:19:41 -0500 | [diff] [blame] | 142 | if (state == 1) {
|
Norman James | a3e47c4 | 2015-10-18 14:43:10 -0500 | [diff] [blame] | 143 | control_emit_goto_system_state(control,"HOST_POWERING_ON");
|
Norman James | 19e4591 | 2015-10-04 20:19:41 -0500 | [diff] [blame] | 144 | } else {
|
Norman James | a3e47c4 | 2015-10-18 14:43:10 -0500 | [diff] [blame] | 145 | control_emit_goto_system_state(control,"HOST_POWERING_OFF");
|
Norman James | 19e4591 | 2015-10-04 20:19:41 -0500 | [diff] [blame] | 146 | }
|
Norman James | 32e74e2 | 2015-09-15 21:28:06 -0500 | [diff] [blame] | 147 | error = gpio_open(&power_pin);
|
Norman James | 8887267 | 2015-09-21 16:51:35 -0500 | [diff] [blame] | 148 | if (error != GPIO_OK) { break; }
|
Norman James | 32e74e2 | 2015-09-15 21:28:06 -0500 | [diff] [blame] | 149 | error = gpio_write(&power_pin,!state);
|
Norman James | 8887267 | 2015-09-21 16:51:35 -0500 | [diff] [blame] | 150 | if (error != GPIO_OK) { break; }
|
Norman James | 32e74e2 | 2015-09-15 21:28:06 -0500 | [diff] [blame] | 151 | gpio_close(&power_pin);
|
| 152 | control_power_set_state(pwr,state);
|
Norman James | 32e74e2 | 2015-09-15 21:28:06 -0500 | [diff] [blame] | 153 | } while(0);
|
| 154 | if (error != GPIO_OK)
|
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 155 | {
|
Norman James | 2891c53 | 2015-10-06 08:01:56 -0500 | [diff] [blame] | 156 | printf("ERROR PowerControl: GPIO set power state (rc=%d)\n",error);
|
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 157 | }
|
Norman James | 9e6acf9 | 2015-09-08 07:00:04 -0500 | [diff] [blame] | 158 | }
|
| 159 | return TRUE;
|
| 160 | }
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 161 |
|
Norman James | 9e6acf9 | 2015-09-08 07:00:04 -0500 | [diff] [blame] | 162 | static gboolean
|
| 163 | on_init (Control *control,
|
| 164 | GDBusMethodInvocation *invocation,
|
| 165 | gpointer user_data)
|
| 166 | {
|
Norman James | 8887267 | 2015-09-21 16:51:35 -0500 | [diff] [blame] | 167 | pgood_timeout_start = 0;
|
Norman James | 8fee6f2 | 2015-10-28 12:48:43 -0500 | [diff] [blame] | 168 | //guint poll_interval = control_get_poll_interval(control);
|
| 169 | //g_timeout_add(poll_interval, poll_pgood, user_data);
|
Norman James | 9e6acf9 | 2015-09-08 07:00:04 -0500 | [diff] [blame] | 170 | control_complete_init(control,invocation);
|
Norman James | 3f97c5d | 2015-08-26 17:44:14 -0500 | [diff] [blame] | 171 | return TRUE;
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 172 | }
|
| 173 |
|
| 174 | static gboolean
|
Norman James | 3f97c5d | 2015-08-26 17:44:14 -0500 | [diff] [blame] | 175 | on_get_power_state (ControlPower *pwr,
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 176 | GDBusMethodInvocation *invocation,
|
| 177 | gpointer user_data)
|
| 178 | {
|
Norman James | 3f97c5d | 2015-08-26 17:44:14 -0500 | [diff] [blame] | 179 | guint pgood = control_power_get_pgood(pwr);
|
| 180 | control_power_complete_get_power_state(pwr,invocation,pgood);
|
| 181 | return TRUE;
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 182 | }
|
| 183 |
|
| 184 | static void
|
| 185 | on_bus_acquired (GDBusConnection *connection,
|
| 186 | const gchar *name,
|
| 187 | gpointer user_data)
|
| 188 | {
|
Norman James | 3f97c5d | 2015-08-26 17:44:14 -0500 | [diff] [blame] | 189 | ObjectSkeleton *object;
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 190 | cmdline *cmd = user_data;
|
Norman James | 8fee6f2 | 2015-10-28 12:48:43 -0500 | [diff] [blame] | 191 | if (cmd->argc < 3)
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 192 | {
|
Norman James | 8fee6f2 | 2015-10-28 12:48:43 -0500 | [diff] [blame] | 193 | g_print("Usage: power_control.exe [poll interval] [timeout]\n");
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 194 | return;
|
| 195 | }
|
| 196 | manager = g_dbus_object_manager_server_new (dbus_object_path);
|
Norman James | 8887267 | 2015-09-21 16:51:35 -0500 | [diff] [blame] | 197 | gchar *s;
|
Norman James | 8fee6f2 | 2015-10-28 12:48:43 -0500 | [diff] [blame] | 198 | s = g_strdup_printf ("%s/%s",dbus_object_path,instance_name);
|
Norman James | 8887267 | 2015-09-21 16:51:35 -0500 | [diff] [blame] | 199 | object = object_skeleton_new (s);
|
| 200 | g_free (s);
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 201 |
|
Norman James | 8887267 | 2015-09-21 16:51:35 -0500 | [diff] [blame] | 202 | ControlPower* control_power = control_power_skeleton_new ();
|
| 203 | object_skeleton_set_control_power (object, control_power);
|
| 204 | g_object_unref (control_power);
|
| 205 |
|
| 206 | Control* control = control_skeleton_new ();
|
| 207 | object_skeleton_set_control (object, control);
|
| 208 | g_object_unref (control);
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 209 |
|
Norman James | cfc2b44 | 2015-10-31 17:31:46 -0500 | [diff] [blame] | 210 | ObjectMapper* mapper = object_mapper_skeleton_new ();
|
| 211 | object_skeleton_set_object_mapper (object, mapper);
|
| 212 | g_object_unref (mapper);
|
| 213 |
|
Norman James | 8887267 | 2015-09-21 16:51:35 -0500 | [diff] [blame] | 214 | //define method callbacks here
|
| 215 | g_signal_connect (control_power,
|
| 216 | "handle-set-power-state",
|
| 217 | G_CALLBACK (on_set_power_state),
|
| 218 | object); /* user_data */
|
Norman James | ce46e3e | 2015-08-30 22:25:55 -0500 | [diff] [blame] | 219 |
|
Norman James | 8887267 | 2015-09-21 16:51:35 -0500 | [diff] [blame] | 220 | g_signal_connect (control_power,
|
| 221 | "handle-get-power-state",
|
| 222 | G_CALLBACK (on_get_power_state),
|
| 223 | NULL); /* user_data */
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 224 |
|
Norman James | 8887267 | 2015-09-21 16:51:35 -0500 | [diff] [blame] | 225 | g_signal_connect (control,
|
| 226 | "handle-init",
|
| 227 | G_CALLBACK (on_init),
|
| 228 | object); /* user_data */
|
Norman James | 9e6acf9 | 2015-09-08 07:00:04 -0500 | [diff] [blame] | 229 |
|
| 230 |
|
Norman James | 8887267 | 2015-09-21 16:51:35 -0500 | [diff] [blame] | 231 | /* Export the object (@manager takes its own reference to @object) */
|
| 232 | g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object));
|
| 233 | g_object_unref (object);
|
Norman James | ce46e3e | 2015-08-30 22:25:55 -0500 | [diff] [blame] | 234 |
|
Norman James | 3f97c5d | 2015-08-26 17:44:14 -0500 | [diff] [blame] | 235 | /* Export all objects */
|
| 236 | g_dbus_object_manager_server_set_connection (manager, connection);
|
| 237 |
|
| 238 | // get gpio device paths
|
Norman James | bd4abd1 | 2015-09-16 22:43:46 -0500 | [diff] [blame] | 239 | int rc = GPIO_OK;
|
Norman James | 32e74e2 | 2015-09-15 21:28:06 -0500 | [diff] [blame] | 240 | do {
|
Norman James | 32e74e2 | 2015-09-15 21:28:06 -0500 | [diff] [blame] | 241 | rc = gpio_init(connection,&power_pin);
|
| 242 | if (rc != GPIO_OK) { break; }
|
| 243 | rc = gpio_init(connection,&pgood);
|
| 244 | if (rc != GPIO_OK) { break; }
|
Norman James | cfc2b44 | 2015-10-31 17:31:46 -0500 | [diff] [blame] | 245 | rc = gpio_init(connection,&pcie_reset);
|
| 246 | if (rc != GPIO_OK) { break; }
|
| 247 | rc = gpio_init(connection,&usb_reset);
|
| 248 | if (rc != GPIO_OK) { break; }
|
| 249 |
|
Norman James | 65a295a | 2015-09-26 22:21:10 -0500 | [diff] [blame] | 250 | uint8_t gpio;
|
Norman James | 32e74e2 | 2015-09-15 21:28:06 -0500 | [diff] [blame] | 251 | rc = gpio_open(&pgood);
|
Norman James | 65a295a | 2015-09-26 22:21:10 -0500 | [diff] [blame] | 252 | if (rc != GPIO_OK) { break; }
|
| 253 | rc = gpio_read(&pgood,&gpio);
|
| 254 | if (rc != GPIO_OK) { break; }
|
| 255 | gpio_close(&pgood);
|
| 256 | control_power_set_pgood(control_power,gpio);
|
Norman James | f66005a | 2015-10-08 15:11:44 -0500 | [diff] [blame] | 257 | printf("Pgood state: %d\n",gpio);
|
Norman James | cfc2b44 | 2015-10-31 17:31:46 -0500 | [diff] [blame] | 258 |
|
Norman James | 32e74e2 | 2015-09-15 21:28:06 -0500 | [diff] [blame] | 259 | } while(0);
|
Norman James | bd4abd1 | 2015-09-16 22:43:46 -0500 | [diff] [blame] | 260 | if (rc != GPIO_OK)
|
| 261 | {
|
Norman James | 2891c53 | 2015-10-06 08:01:56 -0500 | [diff] [blame] | 262 | printf("ERROR PowerControl: GPIO setup (rc=%d)\n",rc);
|
Norman James | 8fee6f2 | 2015-10-28 12:48:43 -0500 | [diff] [blame] | 263 | }
|
| 264 | //start poll
|
| 265 | pgood_timeout_start = 0;
|
| 266 | int poll_interval = atoi(cmd->argv[1]);
|
| 267 | int pgood_timeout = atoi(cmd->argv[2]);
|
| 268 | if (poll_interval < 1000 || pgood_timeout <5) {
|
| 269 | printf("ERROR PowerControl: poll_interval < 1000 or pgood_timeout < 5\n");
|
| 270 | } else {
|
| 271 | control_set_poll_interval(control,poll_interval);
|
| 272 | control_power_set_pgood_timeout(control_power,pgood_timeout);
|
| 273 | g_timeout_add(poll_interval, poll_pgood, object);
|
| 274 | }
|
Norman James | cfc2b44 | 2015-10-31 17:31:46 -0500 | [diff] [blame] | 275 | emit_object_added((GDBusObjectManager*)manager);
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 276 | }
|
| 277 |
|
| 278 | static void
|
| 279 | on_name_acquired (GDBusConnection *connection,
|
| 280 | const gchar *name,
|
| 281 | gpointer user_data)
|
| 282 | {
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 283 | }
|
| 284 |
|
| 285 | static void
|
| 286 | on_name_lost (GDBusConnection *connection,
|
| 287 | const gchar *name,
|
| 288 | gpointer user_data)
|
| 289 | {
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 290 | }
|
| 291 |
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 292 |
|
Norman James | 3f97c5d | 2015-08-26 17:44:14 -0500 | [diff] [blame] | 293 |
|
| 294 |
|
| 295 | /*----------------------------------------------------------------*/
|
| 296 | /* Main Event Loop */
|
| 297 |
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 298 | gint
|
| 299 | main (gint argc, gchar *argv[])
|
| 300 | {
|
| 301 | GMainLoop *loop;
|
Norman James | 90caa3c | 2015-08-27 21:28:48 -0500 | [diff] [blame] | 302 | cmdline cmd;
|
| 303 | cmd.argc = argc;
|
| 304 | cmd.argv = argv;
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 305 |
|
| 306 | guint id;
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 307 | loop = g_main_loop_new (NULL, FALSE);
|
| 308 |
|
Norman James | 5e792e3 | 2015-10-07 17:36:17 -0500 | [diff] [blame] | 309 | id = g_bus_own_name (DBUS_TYPE,
|
Norman James | 26072c0 | 2015-08-25 07:14:29 -0500 | [diff] [blame] | 310 | dbus_name,
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 311 | G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
|
| 312 | G_BUS_NAME_OWNER_FLAGS_REPLACE,
|
| 313 | on_bus_acquired,
|
| 314 | on_name_acquired,
|
| 315 | on_name_lost,
|
Norman James | 90caa3c | 2015-08-27 21:28:48 -0500 | [diff] [blame] | 316 | &cmd,
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 317 | NULL);
|
| 318 |
|
Norman James | ce46e3e | 2015-08-30 22:25:55 -0500 | [diff] [blame] | 319 | g_main_loop_run (loop);
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 320 |
|
| 321 | g_bus_unown_name (id);
|
| 322 | g_main_loop_unref (loop);
|
| 323 | return 0;
|
| 324 | }
|