Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 1 | #include <stdio.h>
|
| 2 | #include <stdbool.h>
|
| 3 | #include <string.h>
|
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 4 | #include "interfaces/openbmc_intf.h"
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 5 | #include "openbmc.h"
|
Norman James | cfc2b44 | 2015-10-31 17:31:46 -0500 | [diff] [blame] | 6 | #include "object_mapper.h"
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 7 |
|
| 8 | /* ---------------------------------------------------------------------------------------------------- */
|
Norman James | 166acf4 | 2015-10-22 07:11:51 -0500 | [diff] [blame] | 9 | static const gchar* dbus_object_path = "/org/openbmc/control/flash";
|
| 10 | static const gchar* dbus_name = "org.openbmc.control.Flash";
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 11 | static const gchar* FLASHER_BIN = "flasher.exe";
|
| 12 | static const gchar* DLOAD_BUS = "org.openbmc.managers.Download";
|
| 13 | static const gchar* DLOAD_OBJ = "/org/openbmc/managers/Download";
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 14 |
|
| 15 | static GDBusObjectManagerServer *manager = NULL;
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 16 |
|
Norman James | 166acf4 | 2015-10-22 07:11:51 -0500 | [diff] [blame] | 17 | int update(Flash* flash, const char* obj_path)
|
Norman James | f066e87 | 2015-10-07 15:29:51 -0500 | [diff] [blame] | 18 | {
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 19 | pid_t pid;
|
| 20 | int status=-1;
|
| 21 | pid = fork();
|
| 22 | if (pid == 0)
|
| 23 | {
|
| 24 | const gchar* path = flash_get_flasher_path(flash);
|
| 25 | const gchar* name = flash_get_flasher_name(flash);
|
| 26 | const gchar* inst = flash_get_flasher_instance(flash);
|
| 27 | const gchar* filename = flash_get_filename(flash);
|
Norman James | 166acf4 | 2015-10-22 07:11:51 -0500 | [diff] [blame] | 28 | status = execl(path, name, inst, filename, obj_path, NULL);
|
Norman James | a3e47c4 | 2015-10-18 14:43:10 -0500 | [diff] [blame] | 29 | return status;
|
Norman James | f066e87 | 2015-10-07 15:29:51 -0500 | [diff] [blame] | 30 | }
|
Norman James | a3e47c4 | 2015-10-18 14:43:10 -0500 | [diff] [blame] | 31 | return 0;
|
Norman James | f066e87 | 2015-10-07 15:29:51 -0500 | [diff] [blame] | 32 | }
|
| 33 |
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 34 | static gboolean
|
Norman James | 471ab59 | 2015-08-30 22:29:40 -0500 | [diff] [blame] | 35 | on_init (Flash *f,
|
| 36 | GDBusMethodInvocation *invocation,
|
| 37 | gpointer user_data)
|
| 38 | {
|
Norman James | 65a295a | 2015-09-26 22:21:10 -0500 | [diff] [blame] | 39 | flash_complete_init(f,invocation);
|
Norman James | 068efb3 | 2015-10-06 16:52:28 -0500 | [diff] [blame] | 40 |
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 41 | //tune flash
|
Norman James | 166acf4 | 2015-10-22 07:11:51 -0500 | [diff] [blame] | 42 | if (strcmp(flash_get_flasher_instance(f),"bios") == 0)
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 43 | {
|
Norman James | 166acf4 | 2015-10-22 07:11:51 -0500 | [diff] [blame] | 44 | flash_set_filename(f,"");
|
| 45 | const gchar* obj_path = g_dbus_object_get_object_path((GDBusObject*)user_data);
|
| 46 | int rc = update(f,obj_path);
|
| 47 | if (rc==-1)
|
| 48 | {
|
| 49 | printf("ERROR FlashControl: Unable to init\n");
|
| 50 | }
|
Norman James | 50fb355 | 2015-10-28 20:27:23 -0500 | [diff] [blame] | 51 | //TODO: have to tune flash twice
|
| 52 | sleep(1);
|
Norman James | d5b5e62 | 2015-10-28 20:53:28 -0500 | [diff] [blame] | 53 | update(f,obj_path);
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 54 | }
|
| 55 | return TRUE;
|
| 56 | }
|
Norman James | 068efb3 | 2015-10-06 16:52:28 -0500 | [diff] [blame] | 57 |
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 58 | static gboolean
|
| 59 | on_lock (SharedResource *lock,
|
| 60 | GDBusMethodInvocation *invocation,
|
| 61 | gchar* name,
|
| 62 | gpointer user_data)
|
| 63 | {
|
Norman James | a3e47c4 | 2015-10-18 14:43:10 -0500 | [diff] [blame] | 64 | gboolean locked = shared_resource_get_lock(lock);
|
| 65 | if (locked)
|
| 66 | {
|
| 67 | const gchar* name = shared_resource_get_name(lock);
|
| 68 | printf("ERROR: BIOS Flash is already locked: %s\n",name);
|
| 69 | }
|
| 70 | else
|
| 71 | {
|
| 72 | printf("Locking BIOS Flash: %s\n",name);
|
| 73 | shared_resource_set_lock(lock,true);
|
| 74 | shared_resource_set_name(lock,name);
|
| 75 | }
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 76 | shared_resource_complete_lock(lock,invocation);
|
| 77 | return TRUE;
|
| 78 | }
|
| 79 | static gboolean
|
| 80 | on_is_locked (SharedResource *lock,
|
| 81 | GDBusMethodInvocation *invocation,
|
| 82 | gpointer user_data)
|
| 83 | {
|
| 84 | gboolean locked = shared_resource_get_lock(lock);
|
| 85 | const gchar* name = shared_resource_get_name(lock);
|
| 86 | shared_resource_complete_is_locked(lock,invocation,locked,name);
|
| 87 | return TRUE;
|
| 88 | }
|
| 89 |
|
| 90 |
|
| 91 | static gboolean
|
| 92 | on_unlock (SharedResource *lock,
|
| 93 | GDBusMethodInvocation *invocation,
|
| 94 | gpointer user_data)
|
| 95 | {
|
| 96 | printf("Unlocking BIOS Flash\n");
|
| 97 | shared_resource_set_lock(lock,false);
|
| 98 | shared_resource_set_name(lock,"");
|
| 99 | shared_resource_complete_unlock(lock,invocation);
|
Norman James | 65a295a | 2015-09-26 22:21:10 -0500 | [diff] [blame] | 100 | return TRUE;
|
Norman James | 471ab59 | 2015-08-30 22:29:40 -0500 | [diff] [blame] | 101 | }
|
| 102 |
|
| 103 | static gboolean
|
Norman James | f066e87 | 2015-10-07 15:29:51 -0500 | [diff] [blame] | 104 | on_update_via_tftp (Flash *flash,
|
| 105 | GDBusMethodInvocation *invocation,
|
| 106 | gchar* url,
|
| 107 | gchar* write_file,
|
| 108 | gpointer user_data)
|
| 109 | {
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 110 | SharedResource *lock = object_get_shared_resource((Object*)user_data);
|
| 111 | gboolean locked = shared_resource_get_lock(lock);
|
Norman James | f066e87 | 2015-10-07 15:29:51 -0500 | [diff] [blame] | 112 | flash_complete_update_via_tftp(flash,invocation);
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 113 | if (locked)
|
| 114 | {
|
| 115 | const gchar* name = shared_resource_get_name(lock);
|
| 116 | printf("BIOS Flash is locked: %s\n",name);
|
| 117 | }
|
| 118 | else
|
| 119 | {
|
| 120 | printf("Flashing BIOS from TFTP: %s,%s\n",url,write_file);
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 121 | flash_set_filename(flash,write_file);
|
| 122 | flash_emit_download(flash,url,write_file);
|
Norman James | 166acf4 | 2015-10-22 07:11:51 -0500 | [diff] [blame] | 123 | flash_set_status(flash,"Downloading");
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 124 | }
|
Norman James | f066e87 | 2015-10-07 15:29:51 -0500 | [diff] [blame] | 125 | return TRUE;
|
| 126 | }
|
| 127 |
|
| 128 | static gboolean
|
Norman James | 166acf4 | 2015-10-22 07:11:51 -0500 | [diff] [blame] | 129 | on_error (Flash *flash,
|
| 130 | GDBusMethodInvocation *invocation,
|
| 131 | gchar* error_msg,
|
| 132 | gpointer user_data)
|
| 133 | {
|
| 134 | int rc = 0;
|
| 135 | SharedResource *lock = object_get_shared_resource((Object*)user_data);
|
| 136 | gboolean locked = shared_resource_get_lock(lock);
|
| 137 | flash_set_status(flash, error_msg);
|
| 138 | flash_complete_error(flash,invocation);
|
| 139 | printf("ERROR: %s. Clearing locks\n",error_msg);
|
| 140 | shared_resource_set_lock(lock,false);
|
| 141 | shared_resource_set_name(lock,"");
|
| 142 |
|
| 143 | return TRUE;
|
| 144 | }
|
| 145 | static gboolean
|
| 146 | on_done (Flash *flash,
|
| 147 | GDBusMethodInvocation *invocation,
|
| 148 | gpointer user_data)
|
| 149 | {
|
| 150 | int rc = 0;
|
| 151 | SharedResource *lock = object_get_shared_resource((Object*)user_data);
|
| 152 | gboolean locked = shared_resource_get_lock(lock);
|
| 153 | flash_set_status(flash, "Flash Done");
|
| 154 | flash_complete_done(flash,invocation);
|
| 155 | printf("Flash Done. Clearing locks\n");
|
| 156 | shared_resource_set_lock(lock,false);
|
| 157 | shared_resource_set_name(lock,"");
|
| 158 |
|
| 159 | return TRUE;
|
| 160 | }
|
| 161 |
|
| 162 |
|
| 163 | static gboolean
|
Norman James | f066e87 | 2015-10-07 15:29:51 -0500 | [diff] [blame] | 164 | on_update (Flash *flash,
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 165 | GDBusMethodInvocation *invocation,
|
| 166 | gchar* write_file,
|
| 167 | gpointer user_data)
|
| 168 | {
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 169 | int rc = 0;
|
| 170 | SharedResource *lock = object_get_shared_resource((Object*)user_data);
|
| 171 | gboolean locked = shared_resource_get_lock(lock);
|
Norman James | 166acf4 | 2015-10-22 07:11:51 -0500 | [diff] [blame] | 172 | flash_set_status(flash,"Flashing");
|
Norman James | f066e87 | 2015-10-07 15:29:51 -0500 | [diff] [blame] | 173 | flash_complete_update(flash,invocation);
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 174 | if (locked)
|
| 175 | {
|
| 176 | const gchar* name = shared_resource_get_name(lock);
|
| 177 | printf("BIOS Flash is locked: %s\n",name);
|
| 178 | }
|
| 179 | else
|
| 180 | {
|
| 181 | printf("Flashing BIOS from: %s\n",write_file);
|
Norman James | 166acf4 | 2015-10-22 07:11:51 -0500 | [diff] [blame] | 182 | flash_set_status(flash, "Flashing");
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 183 | shared_resource_set_lock(lock,true);
|
| 184 | shared_resource_set_name(lock,dbus_object_path);
|
| 185 | flash_set_filename(flash,write_file);
|
Norman James | 166acf4 | 2015-10-22 07:11:51 -0500 | [diff] [blame] | 186 | const gchar* obj_path = g_dbus_object_get_object_path((GDBusObject*)user_data);
|
| 187 | rc = update(flash,obj_path);
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 188 | if (!rc)
|
| 189 | {
|
| 190 | shared_resource_set_lock(lock,false);
|
| 191 | shared_resource_set_name(lock,"");
|
| 192 | }
|
| 193 | }
|
Norman James | 068efb3 | 2015-10-06 16:52:28 -0500 | [diff] [blame] | 194 | return TRUE;
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 195 | }
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 196 | static void
|
| 197 | on_flash_progress (GDBusConnection* connection,
|
| 198 | const gchar* sender_name,
|
| 199 | const gchar* object_path,
|
| 200 | const gchar* interface_name,
|
| 201 | const gchar* signal_name,
|
| 202 | GVariant* parameters,
|
| 203 | gpointer user_data)
|
| 204 | {
|
| 205 | Flash *flash = object_get_flash((Object*)user_data);
|
| 206 | SharedResource *lock = object_get_shared_resource((Object*)user_data);
|
| 207 | GVariantIter *iter = g_variant_iter_new(parameters);
|
| 208 | GVariant* v_filename = g_variant_iter_next_value(iter);
|
| 209 | GVariant* v_progress = g_variant_iter_next_value(iter);
|
Norman James | f066e87 | 2015-10-07 15:29:51 -0500 | [diff] [blame] | 210 |
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 211 | uint8_t progress = g_variant_get_byte(v_progress);
|
Norman James | 166acf4 | 2015-10-22 07:11:51 -0500 | [diff] [blame] | 212 |
|
| 213 | gchar *s;
|
| 214 | s = g_strdup_printf ("Flashing: %d%%",progress);
|
| 215 | flash_set_status(flash,s);
|
| 216 | g_free(s);
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 217 | }
|
| 218 |
|
| 219 | static void
|
| 220 | on_flash_done (GDBusConnection* connection,
|
| 221 | const gchar* sender_name,
|
| 222 | const gchar* object_path,
|
| 223 | const gchar* interface_name,
|
| 224 | const gchar* signal_name,
|
| 225 | GVariant* parameters,
|
| 226 | gpointer user_data)
|
| 227 | {
|
| 228 | Flash *flash = object_get_flash((Object*)user_data);
|
| 229 | SharedResource *lock = object_get_shared_resource((Object*)user_data);
|
| 230 | printf("Flash succeeded; unlocking flash\n");
|
| 231 | shared_resource_set_lock(lock,false);
|
| 232 | shared_resource_set_name(lock,"");
|
Norman James | 166acf4 | 2015-10-22 07:11:51 -0500 | [diff] [blame] | 233 | flash_set_status(flash,"Flash Done");
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 234 | }
|
| 235 |
|
| 236 | static void
|
| 237 | on_flash_error (GDBusConnection* connection,
|
| 238 | const gchar* sender_name,
|
| 239 | const gchar* object_path,
|
| 240 | const gchar* interface_name,
|
| 241 | const gchar* signal_name,
|
| 242 | GVariant* parameters,
|
| 243 | gpointer user_data)
|
| 244 | {
|
| 245 | Flash *flash = object_get_flash((Object*)user_data);
|
| 246 | SharedResource *lock = object_get_shared_resource((Object*)user_data);
|
| 247 | printf("Flash Error; unlocking flash\n");
|
| 248 | shared_resource_set_lock(lock,false);
|
| 249 | shared_resource_set_name(lock,"");
|
| 250 | }
|
| 251 |
|
| 252 | static void
|
| 253 | on_download_error (GDBusConnection* connection,
|
| 254 | const gchar* sender_name,
|
| 255 | const gchar* object_path,
|
| 256 | const gchar* interface_name,
|
| 257 | const gchar* signal_name,
|
| 258 | GVariant* parameters,
|
| 259 | gpointer user_data)
|
| 260 | {
|
| 261 | Flash *flash = object_get_flash((Object*)user_data);
|
| 262 | SharedResource *lock = object_get_shared_resource((Object*)user_data);
|
| 263 | printf("ERROR: FlashBios: Download error; clearing flash lock\n");
|
| 264 | shared_resource_set_lock(lock,false);
|
| 265 | shared_resource_set_name(lock,"");
|
Norman James | f066e87 | 2015-10-07 15:29:51 -0500 | [diff] [blame] | 266 | }
|
| 267 |
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 268 | static void
|
| 269 | on_bus_acquired (GDBusConnection *connection,
|
| 270 | const gchar *name,
|
| 271 | gpointer user_data)
|
| 272 | {
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 273 | ObjectSkeleton *object;
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 274 | cmdline *cmd = user_data;
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 275 | manager = g_dbus_object_manager_server_new (dbus_object_path);
|
| 276 | int i=0;
|
Norman James | 166acf4 | 2015-10-22 07:11:51 -0500 | [diff] [blame] | 277 |
|
| 278 | //TODO: don't use fixed buffer
|
| 279 | char flasher_path[512];
|
| 280 | memset(flasher_path, '\0', sizeof(flasher_path));
|
| 281 | bool found = false;
|
| 282 | gchar *flasher_file;
|
| 283 | int c = strlen(cmd->argv[0]);
|
| 284 | while(c>0)
|
| 285 | {
|
| 286 | if (cmd->argv[0][c] == '/')
|
| 287 | {
|
| 288 | strncpy(flasher_path,cmd->argv[0],c);
|
| 289 | flasher_file = g_strdup_printf ("%s/%s",flasher_path,FLASHER_BIN);
|
| 290 | break;
|
| 291 | }
|
| 292 | c--;
|
| 293 | }
|
| 294 |
|
Norman James | 15aaa80 | 2015-10-28 06:54:48 -0500 | [diff] [blame] | 295 | const char* inst[] = {"bios","bmc","bmc_ramdisk","bmc_kernel"};
|
| 296 | for (i=0;i<4;i++)
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 297 | {
|
Norman James | 166acf4 | 2015-10-22 07:11:51 -0500 | [diff] [blame] | 298 | gchar* s;
|
| 299 | s = g_strdup_printf ("%s/%s",dbus_object_path,inst[i]);
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 300 | object = object_skeleton_new (s);
|
| 301 | g_free (s);
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 302 |
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 303 | Flash* flash = flash_skeleton_new ();
|
| 304 | object_skeleton_set_flash (object, flash);
|
| 305 | g_object_unref (flash);
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 306 |
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 307 | SharedResource* lock = shared_resource_skeleton_new ();
|
| 308 | object_skeleton_set_shared_resource (object, lock);
|
| 309 | g_object_unref (lock);
|
| 310 |
|
Norman James | cfc2b44 | 2015-10-31 17:31:46 -0500 | [diff] [blame] | 311 | ObjectMapper* mapper = object_mapper_skeleton_new ();
|
| 312 | object_skeleton_set_object_mapper (object, mapper);
|
| 313 | g_object_unref (mapper);
|
| 314 |
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 315 | shared_resource_set_lock(lock,false);
|
| 316 | shared_resource_set_name(lock,"");
|
| 317 |
|
Norman James | 166acf4 | 2015-10-22 07:11:51 -0500 | [diff] [blame] | 318 | flash_set_flasher_path(flash,flasher_file);
|
| 319 | flash_set_flasher_name(flash,FLASHER_BIN);
|
| 320 | flash_set_flasher_instance(flash,inst[i]);
|
| 321 | //g_free (s);
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 322 |
|
| 323 |
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 324 | //define method callbacks here
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 325 | g_signal_connect (lock,
|
| 326 | "handle-lock",
|
| 327 | G_CALLBACK (on_lock),
|
| 328 | NULL); /* user_data */
|
| 329 | g_signal_connect (lock,
|
| 330 | "handle-unlock",
|
| 331 | G_CALLBACK (on_unlock),
|
| 332 | NULL); /* user_data */
|
| 333 | g_signal_connect (lock,
|
| 334 | "handle-is-locked",
|
| 335 | G_CALLBACK (on_is_locked),
|
| 336 | NULL); /* user_data */
|
| 337 |
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 338 | g_signal_connect (flash,
|
Norman James | 8c6d838 | 2015-10-06 07:47:16 -0500 | [diff] [blame] | 339 | "handle-update",
|
| 340 | G_CALLBACK (on_update),
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 341 | object); /* user_data */
|
Norman James | 166acf4 | 2015-10-22 07:11:51 -0500 | [diff] [blame] | 342 |
|
| 343 | g_signal_connect (flash,
|
| 344 | "handle-error",
|
| 345 | G_CALLBACK (on_error),
|
| 346 | object); /* user_data */
|
| 347 |
|
| 348 | g_signal_connect (flash,
|
| 349 | "handle-done",
|
| 350 | G_CALLBACK (on_done),
|
| 351 | object); /* user_data */
|
| 352 |
|
Norman James | f066e87 | 2015-10-07 15:29:51 -0500 | [diff] [blame] | 353 | g_signal_connect (flash,
|
| 354 | "handle-update-via-tftp",
|
| 355 | G_CALLBACK (on_update_via_tftp),
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 356 | object); /* user_data */
|
Norman James | f066e87 | 2015-10-07 15:29:51 -0500 | [diff] [blame] | 357 |
|
Norman James | 471ab59 | 2015-08-30 22:29:40 -0500 | [diff] [blame] | 358 | g_signal_connect (flash,
|
| 359 | "handle-init",
|
| 360 | G_CALLBACK (on_init),
|
Norman James | 166acf4 | 2015-10-22 07:11:51 -0500 | [diff] [blame] | 361 | object); /* user_data */
|
Norman James | 471ab59 | 2015-08-30 22:29:40 -0500 | [diff] [blame] | 362 |
|
Norman James | 166acf4 | 2015-10-22 07:11:51 -0500 | [diff] [blame] | 363 | s = g_strdup_printf ("/org/openbmc/control/%s",inst[i]);
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 364 | g_dbus_connection_signal_subscribe(connection,
|
| 365 | NULL,
|
| 366 | "org.openbmc.FlashControl",
|
| 367 | "Progress",
|
| 368 | s,
|
| 369 | NULL,
|
| 370 | G_DBUS_SIGNAL_FLAGS_NONE,
|
| 371 | (GDBusSignalCallback) on_flash_progress,
|
| 372 | object,
|
| 373 | NULL );
|
| 374 |
|
| 375 | g_free (s);
|
Norman James | f066e87 | 2015-10-07 15:29:51 -0500 | [diff] [blame] | 376 |
|
Norman James | 471ab59 | 2015-08-30 22:29:40 -0500 | [diff] [blame] | 377 |
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 378 | flash_set_filename(flash,"");
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 379 | /* Export the object (@manager takes its own reference to @object) */
|
| 380 | g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object));
|
| 381 | g_object_unref (object);
|
| 382 | }
|
Norman James | 166acf4 | 2015-10-22 07:11:51 -0500 | [diff] [blame] | 383 | g_free(flasher_file);
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 384 | /* Export all objects */
|
| 385 | g_dbus_object_manager_server_set_connection (manager, connection);
|
Norman James | cfc2b44 | 2015-10-31 17:31:46 -0500 | [diff] [blame] | 386 | emit_object_added((GDBusObjectManager*)manager);
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 387 | }
|
| 388 |
|
| 389 | static void
|
| 390 | on_name_acquired (GDBusConnection *connection,
|
| 391 | const gchar *name,
|
| 392 | gpointer user_data)
|
| 393 | {
|
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 394 | // g_print ("Acquired the name %s\n", name);
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 395 | }
|
| 396 |
|
| 397 | static void
|
| 398 | on_name_lost (GDBusConnection *connection,
|
| 399 | const gchar *name,
|
| 400 | gpointer user_data)
|
| 401 | {
|
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 402 | //g_print ("Lost the name %s\n", name);
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 403 | }
|
| 404 |
|
| 405 | gint
|
| 406 | main (gint argc, gchar *argv[])
|
| 407 | {
|
| 408 | GMainLoop *loop;
|
Norman James | 952b38d | 2015-08-27 21:30:06 -0500 | [diff] [blame] | 409 | cmdline cmd;
|
| 410 | cmd.argc = argc;
|
| 411 | cmd.argv = argv;
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 412 | guint id;
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 413 | loop = g_main_loop_new (NULL, FALSE);
|
| 414 |
|
Norman James | 5e792e3 | 2015-10-07 17:36:17 -0500 | [diff] [blame] | 415 | id = g_bus_own_name (DBUS_TYPE,
|
Norman James | 26072c0 | 2015-08-25 07:14:29 -0500 | [diff] [blame] | 416 | dbus_name,
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 417 | G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
|
| 418 | G_BUS_NAME_OWNER_FLAGS_REPLACE,
|
| 419 | on_bus_acquired,
|
| 420 | on_name_acquired,
|
| 421 | on_name_lost,
|
Norman James | 952b38d | 2015-08-27 21:30:06 -0500 | [diff] [blame] | 422 | &cmd,
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 423 | NULL);
|
| 424 |
|
| 425 | g_main_loop_run (loop);
|
| 426 |
|
| 427 | g_bus_unown_name (id);
|
| 428 | g_main_loop_unref (loop);
|
| 429 | return 0;
|
| 430 | }
|