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,"");
|
Norman James | 8af7d4a | 2016-01-06 14:09:08 -0600 | [diff] [blame] | 168 | const gchar* filename = flash_get_filename(flash);
|
| 169 | rc = unlink(filename);
|
| 170 | if (rc != 0 )
|
| 171 | {
|
| 172 | printf("ERROR: Unable to delete file %s (%d)\n",filename,rc);
|
| 173 | }
|
Norman James | 166acf4 | 2015-10-22 07:11:51 -0500 | [diff] [blame] | 174 |
|
| 175 | return TRUE;
|
| 176 | }
|
| 177 |
|
| 178 |
|
| 179 | static gboolean
|
Norman James | f066e87 | 2015-10-07 15:29:51 -0500 | [diff] [blame] | 180 | on_update (Flash *flash,
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 181 | GDBusMethodInvocation *invocation,
|
| 182 | gchar* write_file,
|
| 183 | gpointer user_data)
|
| 184 | {
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 185 | int rc = 0;
|
| 186 | SharedResource *lock = object_get_shared_resource((Object*)user_data);
|
| 187 | gboolean locked = shared_resource_get_lock(lock);
|
Norman James | 166acf4 | 2015-10-22 07:11:51 -0500 | [diff] [blame] | 188 | flash_set_status(flash,"Flashing");
|
Norman James | f066e87 | 2015-10-07 15:29:51 -0500 | [diff] [blame] | 189 | flash_complete_update(flash,invocation);
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 190 | if (locked)
|
| 191 | {
|
| 192 | const gchar* name = shared_resource_get_name(lock);
|
| 193 | printf("BIOS Flash is locked: %s\n",name);
|
| 194 | }
|
| 195 | else
|
| 196 | {
|
| 197 | printf("Flashing BIOS from: %s\n",write_file);
|
Norman James | 166acf4 | 2015-10-22 07:11:51 -0500 | [diff] [blame] | 198 | flash_set_status(flash, "Flashing");
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 199 | shared_resource_set_lock(lock,true);
|
| 200 | shared_resource_set_name(lock,dbus_object_path);
|
| 201 | flash_set_filename(flash,write_file);
|
Norman James | 166acf4 | 2015-10-22 07:11:51 -0500 | [diff] [blame] | 202 | const gchar* obj_path = g_dbus_object_get_object_path((GDBusObject*)user_data);
|
| 203 | rc = update(flash,obj_path);
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 204 | if (!rc)
|
| 205 | {
|
| 206 | shared_resource_set_lock(lock,false);
|
| 207 | shared_resource_set_name(lock,"");
|
| 208 | }
|
| 209 | }
|
Norman James | 068efb3 | 2015-10-06 16:52:28 -0500 | [diff] [blame] | 210 | return TRUE;
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 211 | }
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 212 | static void
|
| 213 | on_flash_progress (GDBusConnection* connection,
|
| 214 | const gchar* sender_name,
|
| 215 | const gchar* object_path,
|
| 216 | const gchar* interface_name,
|
| 217 | const gchar* signal_name,
|
| 218 | GVariant* parameters,
|
| 219 | gpointer user_data)
|
| 220 | {
|
| 221 | Flash *flash = object_get_flash((Object*)user_data);
|
| 222 | SharedResource *lock = object_get_shared_resource((Object*)user_data);
|
| 223 | GVariantIter *iter = g_variant_iter_new(parameters);
|
| 224 | GVariant* v_filename = g_variant_iter_next_value(iter);
|
| 225 | GVariant* v_progress = g_variant_iter_next_value(iter);
|
Norman James | f066e87 | 2015-10-07 15:29:51 -0500 | [diff] [blame] | 226 |
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 227 | uint8_t progress = g_variant_get_byte(v_progress);
|
Norman James | 166acf4 | 2015-10-22 07:11:51 -0500 | [diff] [blame] | 228 |
|
| 229 | gchar *s;
|
| 230 | s = g_strdup_printf ("Flashing: %d%%",progress);
|
| 231 | flash_set_status(flash,s);
|
| 232 | g_free(s);
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 233 | }
|
| 234 |
|
| 235 | static void
|
| 236 | on_flash_done (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 succeeded; unlocking flash\n");
|
| 247 | shared_resource_set_lock(lock,false);
|
| 248 | shared_resource_set_name(lock,"");
|
Norman James | 166acf4 | 2015-10-22 07:11:51 -0500 | [diff] [blame] | 249 | flash_set_status(flash,"Flash Done");
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 250 | }
|
| 251 |
|
| 252 | static void
|
| 253 | on_flash_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("Flash Error; unlocking flash\n");
|
| 264 | shared_resource_set_lock(lock,false);
|
| 265 | shared_resource_set_name(lock,"");
|
| 266 | }
|
| 267 |
|
| 268 | static void
|
| 269 | on_download_error (GDBusConnection* connection,
|
| 270 | const gchar* sender_name,
|
| 271 | const gchar* object_path,
|
| 272 | const gchar* interface_name,
|
| 273 | const gchar* signal_name,
|
| 274 | GVariant* parameters,
|
| 275 | gpointer user_data)
|
| 276 | {
|
| 277 | Flash *flash = object_get_flash((Object*)user_data);
|
| 278 | SharedResource *lock = object_get_shared_resource((Object*)user_data);
|
| 279 | printf("ERROR: FlashBios: Download error; clearing flash lock\n");
|
| 280 | shared_resource_set_lock(lock,false);
|
| 281 | shared_resource_set_name(lock,"");
|
Norman James | f066e87 | 2015-10-07 15:29:51 -0500 | [diff] [blame] | 282 | }
|
| 283 |
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 284 | static void
|
| 285 | on_bus_acquired (GDBusConnection *connection,
|
| 286 | const gchar *name,
|
| 287 | gpointer user_data)
|
| 288 | {
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 289 | ObjectSkeleton *object;
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 290 | cmdline *cmd = user_data;
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 291 | manager = g_dbus_object_manager_server_new (dbus_object_path);
|
| 292 | int i=0;
|
Norman James | 166acf4 | 2015-10-22 07:11:51 -0500 | [diff] [blame] | 293 |
|
| 294 | //TODO: don't use fixed buffer
|
| 295 | char flasher_path[512];
|
| 296 | memset(flasher_path, '\0', sizeof(flasher_path));
|
| 297 | bool found = false;
|
| 298 | gchar *flasher_file;
|
| 299 | int c = strlen(cmd->argv[0]);
|
| 300 | while(c>0)
|
| 301 | {
|
| 302 | if (cmd->argv[0][c] == '/')
|
| 303 | {
|
| 304 | strncpy(flasher_path,cmd->argv[0],c);
|
| 305 | flasher_file = g_strdup_printf ("%s/%s",flasher_path,FLASHER_BIN);
|
| 306 | break;
|
| 307 | }
|
| 308 | c--;
|
| 309 | }
|
| 310 |
|
Norman James | 15aaa80 | 2015-10-28 06:54:48 -0500 | [diff] [blame] | 311 | const char* inst[] = {"bios","bmc","bmc_ramdisk","bmc_kernel"};
|
| 312 | for (i=0;i<4;i++)
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 313 | {
|
Norman James | 166acf4 | 2015-10-22 07:11:51 -0500 | [diff] [blame] | 314 | gchar* s;
|
| 315 | s = g_strdup_printf ("%s/%s",dbus_object_path,inst[i]);
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 316 | object = object_skeleton_new (s);
|
| 317 | g_free (s);
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 318 |
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 319 | Flash* flash = flash_skeleton_new ();
|
| 320 | object_skeleton_set_flash (object, flash);
|
| 321 | g_object_unref (flash);
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 322 |
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 323 | SharedResource* lock = shared_resource_skeleton_new ();
|
| 324 | object_skeleton_set_shared_resource (object, lock);
|
| 325 | g_object_unref (lock);
|
| 326 |
|
Norman James | cfc2b44 | 2015-10-31 17:31:46 -0500 | [diff] [blame] | 327 | ObjectMapper* mapper = object_mapper_skeleton_new ();
|
| 328 | object_skeleton_set_object_mapper (object, mapper);
|
| 329 | g_object_unref (mapper);
|
| 330 |
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 331 | shared_resource_set_lock(lock,false);
|
| 332 | shared_resource_set_name(lock,"");
|
| 333 |
|
Norman James | 166acf4 | 2015-10-22 07:11:51 -0500 | [diff] [blame] | 334 | flash_set_flasher_path(flash,flasher_file);
|
| 335 | flash_set_flasher_name(flash,FLASHER_BIN);
|
| 336 | flash_set_flasher_instance(flash,inst[i]);
|
| 337 | //g_free (s);
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 338 |
|
| 339 |
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 340 | //define method callbacks here
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 341 | g_signal_connect (lock,
|
| 342 | "handle-lock",
|
| 343 | G_CALLBACK (on_lock),
|
| 344 | NULL); /* user_data */
|
| 345 | g_signal_connect (lock,
|
| 346 | "handle-unlock",
|
| 347 | G_CALLBACK (on_unlock),
|
| 348 | NULL); /* user_data */
|
| 349 | g_signal_connect (lock,
|
| 350 | "handle-is-locked",
|
| 351 | G_CALLBACK (on_is_locked),
|
| 352 | NULL); /* user_data */
|
| 353 |
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 354 | g_signal_connect (flash,
|
Norman James | 8c6d838 | 2015-10-06 07:47:16 -0500 | [diff] [blame] | 355 | "handle-update",
|
| 356 | G_CALLBACK (on_update),
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 357 | object); /* user_data */
|
Norman James | 166acf4 | 2015-10-22 07:11:51 -0500 | [diff] [blame] | 358 |
|
| 359 | g_signal_connect (flash,
|
| 360 | "handle-error",
|
| 361 | G_CALLBACK (on_error),
|
| 362 | object); /* user_data */
|
| 363 |
|
| 364 | g_signal_connect (flash,
|
| 365 | "handle-done",
|
| 366 | G_CALLBACK (on_done),
|
| 367 | object); /* user_data */
|
| 368 |
|
Norman James | f066e87 | 2015-10-07 15:29:51 -0500 | [diff] [blame] | 369 | g_signal_connect (flash,
|
| 370 | "handle-update-via-tftp",
|
| 371 | G_CALLBACK (on_update_via_tftp),
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 372 | object); /* user_data */
|
Norman James | f066e87 | 2015-10-07 15:29:51 -0500 | [diff] [blame] | 373 |
|
Norman James | 471ab59 | 2015-08-30 22:29:40 -0500 | [diff] [blame] | 374 | g_signal_connect (flash,
|
| 375 | "handle-init",
|
| 376 | G_CALLBACK (on_init),
|
Norman James | 166acf4 | 2015-10-22 07:11:51 -0500 | [diff] [blame] | 377 | object); /* user_data */
|
Norman James | 471ab59 | 2015-08-30 22:29:40 -0500 | [diff] [blame] | 378 |
|
Norman James | 166acf4 | 2015-10-22 07:11:51 -0500 | [diff] [blame] | 379 | s = g_strdup_printf ("/org/openbmc/control/%s",inst[i]);
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 380 | g_dbus_connection_signal_subscribe(connection,
|
| 381 | NULL,
|
| 382 | "org.openbmc.FlashControl",
|
| 383 | "Progress",
|
| 384 | s,
|
| 385 | NULL,
|
| 386 | G_DBUS_SIGNAL_FLAGS_NONE,
|
| 387 | (GDBusSignalCallback) on_flash_progress,
|
| 388 | object,
|
| 389 | NULL );
|
| 390 |
|
| 391 | g_free (s);
|
Norman James | f066e87 | 2015-10-07 15:29:51 -0500 | [diff] [blame] | 392 |
|
Norman James | 471ab59 | 2015-08-30 22:29:40 -0500 | [diff] [blame] | 393 |
|
Norman James | 1899818 | 2015-10-11 21:54:53 -0500 | [diff] [blame] | 394 | flash_set_filename(flash,"");
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 395 | /* Export the object (@manager takes its own reference to @object) */
|
| 396 | g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object));
|
| 397 | g_object_unref (object);
|
| 398 | }
|
Norman James | 166acf4 | 2015-10-22 07:11:51 -0500 | [diff] [blame] | 399 | g_free(flasher_file);
|
Norman James | 10ff6a3 | 2015-08-27 14:24:17 -0500 | [diff] [blame] | 400 | /* Export all objects */
|
| 401 | g_dbus_object_manager_server_set_connection (manager, connection);
|
Norman James | cfc2b44 | 2015-10-31 17:31:46 -0500 | [diff] [blame] | 402 | emit_object_added((GDBusObjectManager*)manager);
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 403 | }
|
| 404 |
|
| 405 | static void
|
| 406 | on_name_acquired (GDBusConnection *connection,
|
| 407 | const gchar *name,
|
| 408 | gpointer user_data)
|
| 409 | {
|
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 410 | // g_print ("Acquired the name %s\n", name);
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 411 | }
|
| 412 |
|
| 413 | static void
|
| 414 | on_name_lost (GDBusConnection *connection,
|
| 415 | const gchar *name,
|
| 416 | gpointer user_data)
|
| 417 | {
|
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 418 | //g_print ("Lost the name %s\n", name);
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 419 | }
|
| 420 |
|
| 421 | gint
|
| 422 | main (gint argc, gchar *argv[])
|
| 423 | {
|
| 424 | GMainLoop *loop;
|
Norman James | 952b38d | 2015-08-27 21:30:06 -0500 | [diff] [blame] | 425 | cmdline cmd;
|
| 426 | cmd.argc = argc;
|
| 427 | cmd.argv = argv;
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 428 | guint id;
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 429 | loop = g_main_loop_new (NULL, FALSE);
|
| 430 |
|
Norman James | d1f41c7 | 2015-11-01 20:30:13 -0600 | [diff] [blame] | 431 | //signal(SIGCHLD, catch_child);
|
Norman James | 5e792e3 | 2015-10-07 17:36:17 -0500 | [diff] [blame] | 432 | id = g_bus_own_name (DBUS_TYPE,
|
Norman James | 26072c0 | 2015-08-25 07:14:29 -0500 | [diff] [blame] | 433 | dbus_name,
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 434 | G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
|
| 435 | G_BUS_NAME_OWNER_FLAGS_REPLACE,
|
| 436 | on_bus_acquired,
|
| 437 | on_name_acquired,
|
| 438 | on_name_lost,
|
Norman James | 952b38d | 2015-08-27 21:30:06 -0500 | [diff] [blame] | 439 | &cmd,
|
Norman James | e276510 | 2015-08-19 22:00:55 -0500 | [diff] [blame] | 440 | NULL);
|
| 441 |
|
| 442 | g_main_loop_run (loop);
|
| 443 |
|
| 444 | g_bus_unown_name (id);
|
| 445 | g_main_loop_unref (loop);
|
| 446 | return 0;
|
| 447 | }
|