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