Home > other >  AllJoyn code structure and equipment information
AllJoyn code structure and equipment information

Time:09-21

In the previous article I use a few basic examples to explain the function of each module of the AllJoyn framework in this article, I will explain from the code level, how to start from scratch to build a core AllJoyn applications

In this article, all code can be download from the Git: code link

AllJoyn applications the overall framework of

In this paper, the use of application can be divided into three modules, to better help us understand AllJoyn framework:

The Main program - the Main application code Main functions:

Processing the command line input and output
Created and placed in the code calls the function, management AllJoyn API communication with each other in
AllJoyn API code - MyAllJoynCode main functions:

Said how to start the AllJoyn framework
The service of the service layer radio and found that using the About Feature attribute
For application of binding a Session and track the SessionId value of host
Using the Session Id to track the user
AllJoyn entities to communicate with others through the MyFirstBusObject
The implementation of the bus object MyFirstBusObject main functions:

Create and implement a AllJoyn interface
Said method how to send a bus and get feedback
Say how to send a signal and no session signal
Said how to obtain the signal
As shown above can code running alone, must be started together with the other two modules to ensure normal application, the classification of the above is just for a better understanding of using the AllJoyn API usage, so as to provide convenience for developers,

Module analysis

Every AllJoyn applications should create a bus subsidiary (BusAttachment), start to connect to the AllJoyn on the route (AllJoyn Router), bus attached objects can let AllJoyn applications call API, create the pattern as shown below:

MBusAttachment=new BusAttachment (" MyFirstApplication ", true);
/* Start the MSG bus */
If (ER_OK==status) {
The status=mBusAttachment - & gt; Start();
} else {
Printf (" BusAttachment: : Start failed \ n ");
}
/* Connect to the daemon */
If (ER_OK==status) {
The status=mBusAttachment - & gt; The Connect ().
If (ER_OK!={
the status)Printf (" BusAttachment Connect failed. \ n ");
}
}

Created bus affiliate, the next step to determine the application of the basic function, this chapter introduces the application is not only the client, as well as the server side, that is to say, the application is a P2P nodes, so in order to achieve the connection, we need to add BindSession,

/* the session is bound to the port to receive all of the join request */
SessionOpts opts (SessionOpts: : TRAFFIC_MESSAGES, true, SessionOpts: : PROXIMITY_ANY, TRANSPORT_ANY);
SessionPort sp=SESSION_PORT_ANY;
The status=mBusAttachment - & gt; BindSessionPort (sp, opts, * this);
If (ER_OK!={
the status)Printf (" can't binding session port \ n ");
}

Due to the port can be used in the application for any of the port, so we use SESSION_PORT_ANY, we hope we can for AllJoyn framework application allocation in the port and deliver to the About data, at the same time, in order to be able to inform other applications we exist, we need to set up the About feature

/* set About data, can be widely used and inform */
MAboutData=https://bbs.csdn.net/topics/new AboutPropertyStoreImpl ();
//set a alone has no ID, such as device's Mac address
//set a random value for the application, this method is common in commercial applications
MAboutData - & gt; SetDeviceId (getDeviceId ());
MAboutData - & gt; MyDeviceName setDeviceName (" ");
//AllJoyn applications of global recognition operators how to use an online GUID the generator to create
//use a random value for this application, this should persist in a comercial application
MAboutData - & gt; SetAppId (getAppId ());
STD: : vector Languages (1);
Languages [0]="en";
MAboutData - & gt; SetSupportedLangs (languages);
MAboutData - & gt; SetDefaultLang (" en ");
MAboutData - & gt; SetAppName (appName);
MAboutData - & gt; Tutorial5000 setModelNumber (" ");
MAboutData - & gt; 8/15/2014 setDateOfManufacture (" ");
MAboutData - & gt; 1.0 build setSoftwareVersion (" 1 ");
MAboutData - & gt; SetAjSoftwareVersion (ajn: : GetVersion ());
MAboutData - & gt; SetHardwareVersion (" N/A ");
MAboutData - & gt; SetDescription (" This is the my first AllJoyn Application!" , "en");
MAboutData - & gt; SetManufacturer (" Company ", "Me");
MAboutData - & gt; SetSupportUrl (" http://www.allseenalliance.org ");

/* the Initialize the About feature Service side */
MBusAttachment AboutServiceApi: : Init (* and * mAboutData);

/* Register the port with the About feature that was set when BindSession called */
Status=AboutServiceApi: : getInstance () - & gt; The Register (sp);
/* Register the About feature with AllJoyn */
The status=mBusAttachment - & gt; RegisterBusObject (* AboutServiceApi: : getInstance ());

Next, the application can start collection, we have for other applications and interconnected to write good platform

Sets the registered developers bus application */*/
/* *
* Here is where we add the objects we wish to expose.
* A developer order to modify this section to add the company BusObjects.
*/
MBusAttachment mMyFirstBusObject=new MyFirstBusObject (*);

/* Now register the object with AllJoyn and About */
QStatus status;
The status=mBusAttachment - & gt; MMyFirstBusObject RegisterBusObject (*);
If (ER_OK!={
the status)Printf (" Could not register the BusObject have the BusAttachment \ n ");
}

STD: : vector Interfaces;
For (int I=0; i Interfaces. The push_back (mMyFirstBusObject - & gt; GetInterfaceName (I));
}
Status=AboutServiceApi: : getInstance () - & gt; AddObjectDescription (mMyFirstBusObject - & gt; GetPath (), interfaces);
If (ER_OK!={
the status)Printf (" the Error returned by AddObjectDescription (% s). \ n ", QCC_StatusText (status));
}

BusObject and MyFirstBusObject contains all the information we communicate with each other, and will we open all of the API set beforehand, to allow other applications to call

BusAttachment is created when a connection is up and connection setup is done, the details of the equipment are set up automatically, and the object is registered good, the next chapter we will be able to make the registration call, so that the application can find our first_app application,

CodePudding user response:

You can refer to this link, a total of five parts: https://bbs.csdn.net/topics/391957303
  • Related