aboutsummaryrefslogtreecommitdiffstats
path: root/README.md
blob: 5d45704db7e47e4f986c087a0f7e0b8d69332793 (plain)
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# Helloworld Service

A binding example for AGL

## Pre-requisites

Please follow [this guide](https://docs.automotivelinux.org/docs/en/master/devguides/reference/2-download-packages.html)
to add the AGL-Master repository to your distribution.\
In order to load these files into the current shell script, use the following command :

* **Debian/Ubuntu**

```bash
source /etc/profile.d/agl-app-framework-binder.sh
```

### CMake module

Then install the cmake module using your distribution package manager.

* **Debian/Ubuntu**

```bash
sudo apt-get install agl-cmake-apps-module-bin
```

* **openSUSE**

```bash
sudo zypper install agl-cmake-apps-module
```

* **Fedora**

```bash
sudo dnf install agl-cmake-apps-module
```

### Build dependency

Because the helloworld-service binding uses json, the following package has to be installed.

* **Debian/Ubuntu**

```bash
sudo apt-get install libjson-c-dev agl-libafb-helpers-dev
```

* **openSUSE**

```bash
sudo zypper install libjson-c-devel agl-libafb-helpers-devel
```

* **Fedora**

```bash
sudo dnf install libjson-c-devel
```

## Setup

```bash
git clone https://gerrit.automotivelinux.org/gerrit/apps/agl-service-helloworld
cd agl-service-helloworld
```

## Build  for AGL

```bash
#setup your build environnement
. /xdt/sdk/environment-setup-aarch64-agl-linux
#build your application
./autobuild/agl/autobuild package
```

## Build for 'native' Linux distribution (Fedora, openSUSE, Debian, Ubuntu, ...)

```bash
./autobuild/linux/autobuild package
```

## Deploy

### Deploy on AGL

```bash
export YOUR_BOARD_IP=192.168.1.X
export APP_NAME=agl-service-helloworld
scp build/${APP_NAME}.wgt root@${YOUR_BOARD_IP}:/tmp
ssh root@${YOUR_BOARD_IP} afm-util install /tmp/${APP_NAME}.wgt
APP_VERSION=$(ssh root@${YOUR_BOARD_IP} afm-util list | grep ${APP_NAME}@ | cut -d"\"" -f4| cut -d"@" -f2)
ssh root@${YOUR_BOARD_IP} afm-util start ${APP_NAME}@${APP_VERSION}
```

## TEST

### TEST on AGL

```bash
export YOUR_BOARD_IP=192.168.1.X
export PORT=8000
ssh root@${YOUR_BOARD_IP} afb-daemon --ws-client=unix:/run/platform/apis/ws/helloworld --port=${PORT} --token='x' -v

#On an other terminal
ssh root@${YOUR_BOARD_IP} afb-client-demo -H 127.0.0.1:${PORT}/api?token=x helloworld ping true
#or
curl http://${YOUR_BOARD_IP}:${PORT}/api/helloworld/ping?token=x
#For a nice display
curl http://${YOUR_BOARD_IP}:${PORT}/api/helloworld/ping?token=x 2>/dev/null | python -m json.tool
```

### Native Linux

For native build you need to have tools **afb-daemon**.  
You can build it by yourself [app-framework-binder][app-framework-binder], or use binary package from OBS:[https://en.opensuse.org/LinuxAutomotive](https://en.opensuse.org/LinuxAutomotive)

```bash
export PORT=1234
cd build
afb-daemon --port=${PORT}  --ldpaths=package --workdir=. --roothttp=../htdocs --token= --verbose

xdg-open http://localhost:${PORT}/

#Command line test
curl http://localhost:${PORT}/api/helloworld/ping
#For a nice display
curl http://localhost:${PORT}/api/helloworld/ping 2>/dev/null | python -m json.tool
```

## Activate authentication security

To test auth just switch the line:

```diff
 static const struct afb_verb_v2 verbs[]= {
   /*Without security*/
-  { .verb = "ping"     , .session = AFB_SESSION_NONE, .callback = pingSample  , .auth = NULL},
+  /*{ .verb = "ping"     , .session = AFB_SESSION_NONE, .callback = pingSample  , .auth = NULL},*/
   /*With security "urn:AGL:permission:monitor:public:get"*/
-  /*{ .verb = "ping"     , .session = AFB_SESSION_NONE, .callback = pingSample  , .auth = &_afb_auths_v2_monitor[1]},*/
+  { .verb = "ping"     , .session = AFB_SESSION_NONE, .callback = pingSample  , .auth = &_afb_auths_v2_monitor[1]},
   {NULL}
 };
```

And rebuild your application

[app-framework-binder]:https://gerrit.automotivelinux.org/gerrit/#/admin/projects/src/app-framework-binder