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