1

Using SIGNAL connectionless in iOS app

asked 2014-07-21 08:12:06 -0800

spark86 gravatar image

updated 2014-07-21 08:13:24 -0800

Hi, my goal is to create a demo application that allows to send a simple string to all device connected in the same wi-fi network. I want to do it using "SIGNALS" and connectionless. I was inspired by the AllJoynChat sample.

I implemented the service's interface in XML and then I generated the code with the code-generator.

<xml>
    <node name="org/mycompany/myapp/stringdemo">
        <annotation name="org.alljoyn.lang.objc" value="SendString"/>
        <interface name="org.mycompany.myapp.stringdemo">
            <annotation name="org.alljoyn.lang.objc" value="SendString"/>
            <signal name="SendString">
                <arg name="str1" type="s" direction="in">
                    <annotation name="org.alljoyn.lang.objc" value="sendStringWithSignal:"/>
                </arg>
            </signal>
        </interface>
    </node>
</xml>

After that, I created a simple UIViewController with a button and textField. This is the code:

@interface MyVC ()
@property (weak, nonatomic) IBOutlet UITextField *inputText;
@property (nonatomic, strong) AJNBusAttachment *bus;
@property (strong, nonatomic) SendString *busObject;
@property (nonatomic) AJNSessionId sessionId;
@end

@implementation MyVC

- (NSString *)sessionlessSignalMatchRule
{
    return @"sessionless='t'";
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    QStatus status = ER_OK;
    self.bus = [[AJNBusAttachment alloc] initWithApplicationName:@"MyDemoApp" allowRemoteMessages:YES];

    [self.bus registerSendStringSignalHandler:self];

    self.busObject = [[SendString alloc] initWithBusAttachment:self.bus onPath:@"/stringService"];

    [self.bus registerBusObject:self.mySignal];

    // start the bus
    //
    status = [self.bus start];
    if (status != ER_OK) {
        NSLog(@"ERROR: Failed to start bus. %@", [AJNStatus descriptionForStatusCode:status]);
    }

    // register our view controller as the bus listener
    //
    [self.bus registerBusListener:self];

    // connect to the bus
    //
    status = [self.bus connectWithArguments:@"null:"];
    if (status != ER_OK) {
        NSLog(@"ERROR: Failed to connect bus. %@", [AJNStatus descriptionForStatusCode:status]);
    }

    NSLog(@"Adding match rule : [%@]", self.sessionlessSignalMatchRule);
    status = [self.bus addMatchRule:self.sessionlessSignalMatchRule];

    if (status != ER_OK) {
        NSLog(@"ERROR: Unable to add match rule. %@", [AJNStatus descriptionForStatusCode:status]);
    }
}

- (IBAction)sendStringButtonPressed:(id)sender {
    [self.busObject sendsendStringWithSignal:self.inputText.text inSession:self.sessionId toDestination:@"/stringService"];
}

//Delegate method
- (void)didReceivesendStringWithSignal:(NSString*)str1 inSession:(AJNSessionId)sessionId message:(AJNMessage *)signalMessage {

    dispatch_async(dispatch_get_main_queue(), ^{
        NSLog(@"%@",str1);
    });
}

@end

In the viewDidLoad method I execute the initialization procedure, and it seems to be ok because at the end of the method, status is equal to ER_OK. The problem is that when I press the button in the UI, this instruction "[self.busObject sendsendStringWithSignal:self.inputText.text inSession:self.sessionId toDestination:@"/stringService"];" seems to do nothing, and the delegate method is never called.

Can someone tell me if it's possible to do what I want and what I'm doing wrong?

Thanks in advance

edit retag flag offensive close merge delete

Comments

What is the sessionId initialized to ? To send a sessionless signal the sessionId must be 0.

Nikhil Dabhade ( 2014-07-21 12:13:26 -0800 )edit

Yes, the sessionId is initialized to 0. Do you think that is correct the XML service's interface?

spark86 ( 2014-07-21 23:56:48 -0800 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-07-23 13:43:45 -0800

bspencer gravatar image

Why not use the AllJoyn Notification Service (iOS SDK) and make the sending of the string interoperable with other devices and applications?

Here is the Usage Guide for iOS.

That being said I believe the issue is that the FLAG you are using is 0 or not set when you use the C++ Signal call that is used in the CodeGenerator. You will need to modify the C++ code to add the FLAG of ALLJOYN_FLAG_SESSIONLESS. If you want to see how this is done in the Notification Service you can find it here.

edit flag offensive delete publish link more

Comments

Thank you for your answer. I will try the Notification Service as you suggested.

spark86 ( 2014-08-05 00:12:05 -0800 )edit

If after looking through the Notification Service or modifying the FLAG value solves your problem could you please mark this as answered. Thank you.

bspencer ( 2014-08-05 12:38:47 -0800 )edit

I have not tried to modify the C++ code adding the flag ALLJOYN_FLAG_SESSIONLESS but I used the Notification Service successfully

spark86 ( 2014-08-06 00:09:24 -0800 )edit

All links in this answer are now 404 not found.

alljoyn_ios_user ( 2016-01-14 15:02:42 -0800 )edit

I had the same issue - but there are some issues with combining signals with authentication that weren't documented anywhere. To receive a signal with authentication enabled - you must call a secure method on the remote object and authenticate first before receiving signals is possible. OR rem auth.

alljoyn_ios_user ( 2016-01-15 13:30:59 -0800 )edit
Login/Signup to Answer

Question Tools

Follow
1 follower

Stats

Asked: 2014-07-21 08:12:06 -0800

Seen: 194 times

Last updated: Jan 14 '16