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