mirror of
https://git.jami.net/savoirfairelinux/jami-daemon.git
synced 2025-08-12 22:09:25 +08:00
agent/agent: Fix wait for announcement problems
Change-Id: I1de543265671728148e02d5b4d7d1878e22d6e18
This commit is contained in:

committed by
Adrien Béraud

parent
95617cc2ec
commit
cbcb68214e
@ -20,50 +20,52 @@
|
|||||||
#:use-module (ice-9 threads)
|
#:use-module (ice-9 threads)
|
||||||
#:use-module ((jami account) #:prefix account:)
|
#:use-module ((jami account) #:prefix account:)
|
||||||
#:use-module ((jami call) #:prefix call:)
|
#:use-module ((jami call) #:prefix call:)
|
||||||
#:use-module ((jami signal) #:prefix jami:))
|
#:use-module ((jami signal) #:prefix jami:)
|
||||||
|
#:export (ensure-account
|
||||||
|
ensure-account-from-archive))
|
||||||
|
|
||||||
(define-public account-id "afafafafafafafaf")
|
(define-public account-id (make-fluid "afafafafafafafaf"))
|
||||||
(define-public peer-id #f)
|
(define-public peer-id (make-fluid))
|
||||||
|
|
||||||
(define (wait-for-announcement-of% accounts)
|
(define* (ensure-account% this-account-id account-details #:optional (wait-for-announcement? #t))
|
||||||
(let ((mtx (make-mutex))
|
(if wait-for-announcement?
|
||||||
(cnd (make-condition-variable)))
|
(let ((mtx (make-mutex))
|
||||||
(map (lambda (this-account)
|
(cnd (make-condition-variable)))
|
||||||
(jami:on-signal 'volatile-details-changed
|
(jami:on-signal 'volatile-details-changed
|
||||||
(lambda (accountID details)
|
(lambda (accountID details)
|
||||||
(cond
|
(cond
|
||||||
((not (string= accountID this-account)) #f)
|
((and (string= accountID this-account-id)
|
||||||
((not (string= "true" (assoc-ref details "Account.deviceAnnounced"))) #f)
|
(string= "true" (assoc-ref details "Account.deviceAnnounced")))
|
||||||
(else
|
(with-mutex mtx
|
||||||
(with-mutex mtx
|
(signal-condition-variable cnd)
|
||||||
(signal-condition-variable cnd))
|
#f))
|
||||||
#t))))
|
(else #t))))
|
||||||
(with-mutex mtx
|
(when (null? (account:get-details this-account-id))
|
||||||
(wait-condition-variable cnd mtx)))
|
(account:add account-details this-account-id))
|
||||||
accounts)))
|
|
||||||
|
|
||||||
(define (wait-for-announcement-of accounts)
|
(with-mutex mtx
|
||||||
(if (string? accounts)
|
(wait-condition-variable cnd mtx)))
|
||||||
(wait-for-announcement-of% (list accounts))
|
|
||||||
(wait-for-announcement-of% accounts)))
|
|
||||||
|
|
||||||
(define-public (ensure-account)
|
(when (null? (account:get-details this-account-id))
|
||||||
|
(account:add account-details this-account-id)))
|
||||||
|
|
||||||
(when (null? (account:get-details account-id))
|
(let ((details (account:get-details this-account-id)))
|
||||||
(account:add '(("Account.type" . "RING")
|
(fluid-set! peer-id (assoc-ref details "Account.username"))))
|
||||||
("Account.displayName" . "AGENT")
|
|
||||||
("Account.alias" . "AGENT")
|
|
||||||
("Account.archivePassword" . "")
|
|
||||||
("Account.archivePIN" . "")
|
|
||||||
("Account.archivePath" . ""))
|
|
||||||
account-id))
|
|
||||||
|
|
||||||
(let ((result (wait-for-announcement-of account-id)))
|
(define* (ensure-account #:key (wait-for-announcement? #t))
|
||||||
(display result)
|
(ensure-account% (fluid-ref account-id) '(("Account.type" . "RING")
|
||||||
(newline)
|
("Account.displayName" . "AGENT")
|
||||||
(unless (car result)
|
("Account.alias" . "AGENT")
|
||||||
(format #t "Timeout while waiting for account announcement~%")))
|
("Account.archivePassword" . "")
|
||||||
|
("Account.archivePIN" . "")
|
||||||
|
("Account.archivePath" . ""))
|
||||||
|
wait-for-announcement?))
|
||||||
|
|
||||||
|
(define* (ensure-account-from-archive path #:key (wait-for-announcement? #t))
|
||||||
(let ((details (account:get-details account-id)))
|
(ensure-account% (fluid-ref account-id) `(("Account.type" . "RING")
|
||||||
(set! peer-id (assoc-ref details "Account.username"))))
|
("Account.displayName" . "AGENT")
|
||||||
|
("Account.alias" . "AGENT")
|
||||||
|
("Account.archivePassword" . "")
|
||||||
|
("Account.archivePIN" . "")
|
||||||
|
("Account.archivePath" . ,path))
|
||||||
|
wait-for-announcement?))
|
||||||
|
Reference in New Issue
Block a user