0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

AGL の binding の読み方

Last updated at Posted at 2023-03-25

AGL とは?

Automotive Grade Linux (以下、AGL) という コネクテッドカーに活用するオープンプラットフォームを開発する OSSのプロジェクト。
コネクテッドカーに関する 知見がつまっています。

AGL って難しそうな印象ありませんか?

AGL って難しそうな印象ありませんか?

自分も最初に読んでいた時は何かと難しいと感じていました。
ただ、binding という コマンドラインで イベントの subscription などを行うコード群を読む中で、AGL の binding なりのコードの書き方の流儀が少しだけ分かりました(自分も AGL を読み始めて 2ヶ月くらいで 間違っている部分があると思うので、発見したら教えていただけると嬉しいです)。

ここでは、AGL で有名なホームスクリーンではなくて、binding 限定ですが、どのように AGL を読んでいけばいいか説明してみます。

AGL binding とは?

上でも簡単に説明しましたが、対象の機能に関してコマンドラインで イベントの subscription などを行うコードになります。
例えば、can-low-level だと

low-can subscribe { "event": "doors.driver.open" }

という入力をすると、can0 からの can 情報の内 event名が doors.driver.open の情報が 登録されると、

ON-EVENT low-can/messages.doors.driver.open({"event":"low-can\/messages.doors.driver.open","data":{"name":"messages.doors.driver.open","value":true, "timestamp": 1505812906020023},"jtype":"afb-event"})

という形で subscribe された結果が表示されます。
他の binding も同じような形で 情報の subscribe を行っています(例えば、radio だと subscribe 以外に、周波数・バンド・音質などたくさんの機能がありますが)。

では、この binding の読み方を説明していきます。

AGL binding 読み方

まずは、

/*
 * array of the verbs exported to afb-daemon
 */
static const afb_verb_t binding_verbs[] =
{
  /* VERB'S NAME            SESSION MANAGEMENT          FUNCTION TO CALL         Authorization */
  { .verb= "get",          .session= AFB_SESSION_NONE, .callback= get,          .info = "get", .auth = NULL },
//  { .name= "set",          .session= AFB_SESSION_NONE, .callback= set,        .auth = NULL },
  { .verb= "list",         .session= AFB_SESSION_NONE, .callback= list,         .info = "list", .auth = NULL },
  { .verb= "subscribe",    .session= AFB_SESSION_NONE, .callback= subscribe,    .info = "subscribe", .auth = NULL },
  { .verb= "unsubscribe",  .session= AFB_SESSION_NONE, .callback= unsubscribe,  .info = "unsubscribe", .auth = NULL },
  { .verb= NULL } /* marker for end of the array */
};

/*
 * description of the binding for afb-daemon
 */
const afb_binding_t afbBindingExport =
{
	.api = "steering-wheel",
	.specification = NULL,
    .verbs = binding_verbs,			 /* the array describing the verbs of the API */
    .preinit = NULL,
    .init = init,
    .onevent = NULL,
    .noconcurrency = 1
};

のような、binding の verb ( binding のコマンドの subscribe の部分 ) が定義されている部分と、binding の設定がされている部分があるか探します(ない場合は、jsonファイルなどに記述されていることがあります)。

このファイルから、binding のコマンドの種類 と、initpreinit つまり binding のコマンドが呼びだされた時の初期化処理の場所(今回は init と NULLが分かります。

binding では init 処理時に作成したイベントループ などで イベントをプッシュし、そのイベントを subscribe 内でサブスクライブしていきます。
そのイベントプッシュとサブスクライブの資料がこちらになります。

流れとしてはまず、

event = afb_api_make_event(api, name);

でイベントを作り、

rc = afb_req_subscribe(req, event);

でイベントをサブスクライブし、
その後でイベントをプッシュすると、

rc = afb_event_push(event, JSON);

サブスクライブしたイベントに、

ON-EVENT サブスクライブした結果

が表示されるようになります。

ここまでの内容をまとめると、binding は、

init, preinit とコマンド一覧が定義されているところを探して、afb のライブサイクルを頭に入れて、それぞれの処理を見てみる

で簡単に読めるようになると思います。
機会があれば、

にレポジトリがあるので読んでみるといいと思います。

ここまで読んでいただきありがとうございました!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?