-
Notifications
You must be signed in to change notification settings - Fork 1
/
GeoclueAgent.go
executable file
·74 lines (59 loc) · 2.61 KB
/
GeoclueAgent.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package geoclue2
import "encoding/json"
// todo: not implemented
// Paths of methods and properties
const (
GeoclueAgentInterface = GeoclueInterface + ".Agent"
GeoclueAgentObjectPath = GeoclueObjectPath + "/Agent"
/* Methods */
GeoclueAgentAuthorizeApp = GeoclueAgentInterface + ".AuthorizeApp"
/* Property */
GeoclueAgentPropertyMaxAccuracyLevel = GeoclueAgentInterface + ".MaxAccuracyLevel" // readable u
)
// GeoclueAgent interface all application-authorizing agents must implement. There must be a separate agent object for every logged-in user on path "/org/freedesktop/GeoClue2/Agent".
type GeoclueAgent interface {
/* METHODS */
// This is the method that will be called by geoclue to get applications authorized to be given location information.
//IN string desktop_id: The desktop file id (the basename of the desktop file) of the application requesting location information.
//IN u req_accuracy_level: The level of location accuracy requested by client, as GClueAccuracyLevel.
//OUT b authorized: Return value indicating if application should be given location information or not.
//OUT u allowed_accuracy_level: The level of location accuracy allowed for client, as GClueAccuracyLevel.
AuthorizeApp(string, GClueAccuracyLevel) (bool, GClueAccuracyLevel, error)
/* PROPERTIES */
// The global maximum level of accuracy allowed for all clients. Since agents are per-user, this can be different for each user. See GClueAccuracyLevel for possible values.
GetMaxAccuracyLevel() (GClueAccuracyLevel, error)
MarshalJSON() ([]byte, error)
}
// NewGeoclueAgent returns new NewGeoclueAgent Interface
func NewGeoclueAgent() (GeoclueAgent, error) {
var gca geoclueAgent
return &gca, gca.init(GeoclueInterface, GeoclueAgentObjectPath)
}
type geoclueAgent struct {
dbusBase
}
func (gca geoclueAgent) AuthorizeApp(desktopId string, reqLevel GClueAccuracyLevel) (authorized bool, allowedLevel GClueAccuracyLevel, err error) {
var tmpUint uint32
err = gca.callWithReturn2(&authorized, &tmpUint, GeoclueAgentAuthorizeApp, &desktopId, &reqLevel)
if err != nil {
return false, GClueAccuracyLevelNone, err
}
allowedLevel = GClueAccuracyLevel(tmpUint)
return
}
func (gca geoclueAgent) GetMaxAccuracyLevel() (GClueAccuracyLevel, error) {
res, err := gca.getUint32Property(GeoclueAgentPropertyMaxAccuracyLevel)
if err != nil {
return GClueAccuracyLevelNone, err
}
return GClueAccuracyLevel(res), nil
}
func (gca geoclueAgent) MarshalJSON() ([]byte, error) {
maxAccuracyLevel, err := gca.GetMaxAccuracyLevel()
if err != nil {
return nil, err
}
return json.Marshal(map[string]interface{}{
"MaxAccuracyLevel": maxAccuracyLevel,
})
}