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