runOnce establishes a connection to the synchronisation server, registers for notifications, polls for notifications, then deregisters.
()
| 418 | // runOnce establishes a connection to the synchronisation server, registers |
| 419 | // for notifications, polls for notifications, then deregisters. |
| 420 | func (sc *syncClient) runOnce() { |
| 421 | if err := sc.dial(); err != nil { |
| 422 | log.Warningf("Sync client dial failed: %v", err) |
| 423 | return |
| 424 | } |
| 425 | defer sc.close() |
| 426 | |
| 427 | var sid SyncSessionID |
| 428 | self := sc.engine.config.Node.IPv4Addr |
| 429 | |
| 430 | // Register for synchronisation events. |
| 431 | // TODO(jsing): Implement timeout on RPC? |
| 432 | if err := sc.client.Call("SeesawSync.Register", self, &sid); err != nil { |
| 433 | log.Warningf("Sync registration failed: %v", err) |
| 434 | return |
| 435 | } |
| 436 | log.Infof("Registered for synchronisation notifications (ID %d)", sid) |
| 437 | |
| 438 | // TODO(jsing): Export synchronisation data to ECU/CLI. |
| 439 | |
| 440 | sc.poll(sid) |
| 441 | |
| 442 | // Attempt to deregister for notifications. |
| 443 | // TODO(jsing): Implement timeout on RPC? |
| 444 | if err := sc.client.Call("SeesawSync.Deregister", sid, nil); err != nil { |
| 445 | log.Warningf("Sync deregistration failed: %v", err) |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | // poll polls the synchronisation server for notifications, then dispatches |
| 450 | // them for processing. |