これでメインの流れは終わりですが、大事なサブルーティン(クラスと言うほうが正しいかもしれませんを見てみましょう。
class BasicSampleObject : public BusObject {
public:
BasicSampleObject(BusAttachment& bus, const char* path) :
BusObject(path)
{
/** Add the test interface to this object */
const InterfaceDescription* exampleIntf = bus.GetInterface(INTERFACE_NAME);
assert(exampleIntf);
AddInterface(*exampleIntf); /オブジェクトにインタフェースを割り当てる/
/** Register the method handlers with the object */ /メッセージ到着時に起動するハンドラーとして、Catという名称のサブルーティンを登録する/
const MethodEntry methodEntries[] = {
{ exampleIntf->GetMember("cat"), stat-ic_cast<MessageReceiver::MethodHandler>(&BasicSampleObject::Cat) }
};
QStatus status = AddMethodHandlers(methodEntries, sizeof(methodEntries) / sizeof(methodEntries[0]));
if (ER_OK != status) {
printf("Failed to register method handlers for BasicSampleObject.\n");
}
}
ハンドラーのcatは以下のようになっています。引数に、到着したメッセージが入り次第それらを連結して、また、送付元へ戻すだけです。
void Cat(const InterfaceDescription::Member* member, Message& msg)
{
QCC_UNUSED(member);
/* Concatenate the two input strings and reply with the result. */
qcc::String inStr1 = msg->GetArg(0)->v_string.str;
qcc::String inStr2 = msg->GetArg(1)->v_string.str;
qcc::String outStr = inStr1 + inStr2;
MsgArg outArg("s", outStr.c_str());
QStatus status = MethodReply(msg, &outArg, 1);
if (ER_OK != status) {
printf("Ping: Error sending reply.\n");
}
}
Raspberry PiにAllJoynを移植して、IoTを自作する
「Alljoyn」のいまをクアルコムブースで見る
激化する“IoTの陣取り合戦”欠けているのは「共通言語」
Allseen Allianceの中核技術「Alljoyn」とは何か
IoT団体によるUPnP(Universal Plug and Play)吸収を読み解くCopyright © ITmedia, Inc. All Rights Reserved.
組み込み開発の記事ランキング
コーナーリンク
よく読まれている編集記者コラム