1

how is AJTC both client and service

asked 2014-05-08 19:35:37 -0700

zhengkun gravatar image

Hi, i try to make my thin client both client and service , but i don't know how to do it. AJTC is the client , PC is the service. In my test , they have joined the same session, and AJTC try to make methodcall on PC, but there are errors.

image description

Here is part of my code:

static AJ_BusAttachment bus;

static const char DeviceName[] = "Alljoyn Thin Client";
static const char MainServiceName[] = "org.alljoyn.Bus.centralcontrol";
static const char DaemonBusName[] = "org.alljoyn.BusNode.measure";
static const uint16_t ServicePort = 24;
uint32_t sessionId = 0;

static const char MyServiceName[] = "org.alljoyn.sample.measure";
const char* busUniqueName;

//timeout config
#define CONNECT_TIMEOUT    (1000 * 1000)
#define UNMARSHAL_TIMEOUT  (1000 * 5)
#define METHOD_TIMEOUT     (100 * 10)

//thin client information
 static const char* const testInterface[] = {
    "org.alljoyn.sample.measure",
   "?On",
   "?Off",
   NULL
};


static const AJ_InterfaceDescription testInterfaces[] = {
    testInterface,

    NULL
};

/**
 * Objects implemented by the application
*/
static const AJ_Object AppObjects[] = {
    { "/org/alljoyn/sample/measure", testInterfaces },
    { NULL }
 };

/*
 * Message identifiers for the method calls this application implements
 */


#define APP_ON                          AJ_APP_MESSAGE_ID(0, 0, 0)
#define APP_OFF                         AJ_APP_MESSAGE_ID(0, 0, 1)


// main service information
// service interface
 static const char* const gatewayInterface[] = {
   "org.alljoyn.Bus.centralcontrol",
   "!Add DUS>s",
    NULL
};
static const AJ_InterfaceDescription gatewayInterfaces[] = {
    gatewayInterface,
    NULL

};

static const AJ_Object ProxyObjects[] = {

    { "/org/alljoyn/Bus/centralcontrol", gatewayInterfaces },
    { NULL }
};

#define PRX_ADD_METHOD   AJ_PRX_MESSAGE_ID(1, 0, 0)



 //make method call  
 AJ_Status AddMethod(AJ_BusAttachment* bus, uint32_t sessionId)
{
     AJ_Status status;
     AJ_Message msg;

     char *DUS = "Alljoyn Thin Client";

     status = AJ_MarshalMethodCall(bus,
                              &msg,
                              PRX_ADDDUSNAME_METHOD,
                              MainServiceName,
                              sessionId,
                              AJ_FLAG_ENCRYPTED,
                              METHOD_TIMEOUT);
   if (AJ_OK == status) {
       status = AJ_MarshalArgs(&msg, "s", &DUS);
        AJ_Printf("Marshal Method call successful");
   } else {
       AJ_Printf("Marshal Method call failed");
   }

   if (AJ_OK == status) {
       status = AJ_DeliverMsg(&msg);
   } else {
       AJ_Printf("Marshal DUS message failed");
   }
    AJ_Printf("Deliver DUS message successful");
    return status;
 }

......

int AJ_Main(void)
 {
     AJ_Initialize();
     AJ_PrintXML(AppObjects);
     AJ_PrintXML(ProxyObjects);
     AJ_RegisterObjects(AppObjects, NULL);
     AJ_RegisterObjects(NULL, ProxyObjects);
  ......
 while (TRUE) {
         AJ_Message msg;

         if (!connected) {
            status = AJ_StartClient(&bus,
                                    NULL, 
                                   CONNECT_TIMEOUT, 
                                   FALSE,
                                   MainServiceName,
                                   ServicePort,
                                   &sessionId,
                                   NULL);
AJ_BusSetPasswordCallback(&bus, PasswordCallback);
status = AddMethod(&bus,sessionId);
        if (status = AJ_OK){
        AJ_Printf("Register successful!\n");

        }else{
         AJ_Printf("Register failed on %d, please look over in aj_status.h\n ",status);
        }

    }

status = AJ_UnmarshalMsg(&bus, &msg, UNMARSHAL_TIMEOUT);
if (status == AJ_OK) {

     // AJ_Printf("msgId is %s\n",msg.msgId);
        switch (msg.msgId) {
         case AJ_REPLY_ID(AJ_METHOD_JOIN_SESSION):
            AJ_Printf("JoinSession SUCCESS (Session id=%d).\n", sessionId);
            break;
        case APP_ON:
            AppHandleOnOff(&msg, TRUE);
            break;
        case APP_OFF:
            AppHandleOnOff(&msg, FALSE);
       ......
}
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-05-16 10:35:41 -0700

bspencer gravatar image

The definition of

#define PRX_ADD_METHOD   AJ_PRX_MESSAGE_ID(1, 0, 0)

is incorrect. Change it to:

#define PRX_ADD_METHOD   AJ_PRX_MESSAGE_ID(0, 0, 0)
edit flag offensive delete publish link more
Login/Signup to Answer

Question Tools

Follow
1 follower

Stats

Asked: 2014-05-08 19:35:37 -0700

Seen: 136 times

Last updated: May 16 '14