Binding an interface that conforms to multiple protocols

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

Binding an interface that conforms to multiple protocols

tkacem
Hi All,

I have this question that nobody cared to answer so far !! How can I bind an interface that conforms to many protocols in monotouch.

Example: in objective-c it would look like @interface XX : BaseClass <Delegate1,Delegate2>

Any help would be greatly appreciated.

Thanks,
Thabet
Reply | Threaded
Open this post in threaded view
|

Re: Binding an interface that conforms to multiple protocols

Nic Wise
Have you had a read through this?

http://docs.xamarin.com/ios/tutorials/Events,_Protocols_and_Delegates
http://docs.xamarin.com/ios/advanced_topics/binding_objective-c_types

(otherwise, can you provide a bit more code as an example?)

On Fri, Jun 29, 2012 at 3:21 PM, tkacem <[hidden email]> wrote:

> Hi All,
>
> I have this question that nobody cared to answer so far !! How can I bind an
> interface that conforms to many protocols in monotouch.
>
> Example: in objective-c it would look like @interface XX : BaseClass
> <Delegate1,Delegate2>
>
> Any help would be greatly appreciated.
>
> Thanks,
> Thabet
>
> --
> View this message in context: http://monotouch.2284126.n4.nabble.com/Binding-an-interface-that-conforms-to-multiple-protocols-tp4655661.html
> Sent from the MonoTouch mailing list archive at Nabble.com.
> _______________________________________________
> MonoTouch mailing list
> [hidden email]
> http://lists.ximian.com/mailman/listinfo/monotouch



--
Nic Wise
t.  +44 7788 592 806 | @fastchicken | http://www.linkedin.com/in/nicwise
b. http://www.fastchicken.co.nz/

Earnest: Self-employed? Track your business expenses and income.
http://earnestapp.com
Nearest Bus: find when the next bus is coming to your stop. http://goo.gl/Vcz1p
mobileAgent (for FreeAgent): get your accounts in your pocket.
http://goo.gl/IuBU
Trip Wallet: Keep track of your budget on the go: http://goo.gl/ePhKa
London Bike App: Find the nearest Boris Bike, and get riding! http://goo.gl/Icp2
_______________________________________________
MonoTouch mailing list
[hidden email]
http://lists.ximian.com/mailman/listinfo/monotouch
Reply | Threaded
Open this post in threaded view
|

Re: Binding an interface that conforms to multiple protocols

tkacem
Hi Nic,

Thanks for your reply. The interface definition is as follows:

@interface GDExtended : NSObject <UIApplicationDelegate,GDiOSDelegate>

- (void) handleEvent:(GDAppEvent *)anEvent;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;

@end



@implementation GDExtended

- (id)init
{
    self = [super init];
    if (self) {
        // Initialization code here.
    }
   
    return self;
}

- (void) handleEvent:(GDAppEvent *)anEvent
{
   
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    return YES;
}

@end


I am trying to wrap this in c# knowing that c# does not allow multiple implementation. I wrote the wrapper for this interface in c# (I need the GDiOSDelegate in order to create the event handler method which should communicate with components from UIApplicationDelegate class).
The problem is that when I inherit GDExtended in a sample monotouch application that uses the created Dll, I get an error that my class does not implement UIApplicationDelegate.

Your prompt attention to this message is highly appreciated.
Thanks,
Thabet
Reply | Threaded
Open this post in threaded view
|

Re: Binding an interface that conforms to multiple protocols

Nic Wise
could you:

Make one wrapper for GDiOSDelegate
Make one wrapper for UIApplicationDelegate (you have this already)

Use the delegate pattern to make a new GDiOSDelegate, have whatever
you are using call THAT object, and relay the calls back to your main
class?

On Tue, Jul 10, 2012 at 4:23 PM, tkacem <[hidden email]> wrote:

> Hi Nic,
>
> Thanks for your reply. The interface definition is as follows:
>
> *@interface GDExtended : NSObject <UIApplicationDelegate,GDiOSDelegate>
>
> - (void) handleEvent:(GDAppEvent *)anEvent;
> - (BOOL)application:(UIApplication *)application
> didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;
>
> @end*
>
>
> *@implementation GDExtended
>
> - (id)init
> {
>     self = [super init];
>     if (self) {
>         // Initialization code here.
>     }
>
>     return self;
> }
>
> - (void) handleEvent:(GDAppEvent *)anEvent
> {
>
> }
>
> - (BOOL)application:(UIApplication *)application
> didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
> {
>     return YES;
> }
>
> @end
> *
>
> I am trying to wrap this in c# knowing that c# does not allow multiple
> implementation. I wrote the wrapper for this interface in c# (I need the
> GDiOSDelegate in order to create the event handler method which should
> communicate with components from UIApplicationDelegate class).
> The problem is that when I inherit GDExtended in a sample monotouch
> application that uses the created Dll, I get an error that my class does not
> implement UIApplicationDelegate.
>
> Your prompt attention to this message is highly appreciated.
> Thanks,
> Thabet
>
> --
> View this message in context: http://monotouch.2284126.n4.nabble.com/Binding-an-interface-that-conforms-to-multiple-protocols-tp4655661p4655901.html
> Sent from the MonoTouch mailing list archive at Nabble.com.
> _______________________________________________
> MonoTouch mailing list
> [hidden email]
> http://lists.ximian.com/mailman/listinfo/monotouch



--
Nic Wise
t.  +44 7788 592 806 | @fastchicken | http://www.linkedin.com/in/nicwise
b. http://www.fastchicken.co.nz/

Earnest: Self-employed? Track your business expenses and income.
http://earnestapp.com
Nearest Bus: find when the next bus is coming to your stop. http://goo.gl/Vcz1p
mobileAgent (for FreeAgent): get your accounts in your pocket.
http://goo.gl/IuBU
Trip Wallet: Keep track of your budget on the go: http://goo.gl/ePhKa
London Bike App: Find the nearest Boris Bike, and get riding! http://goo.gl/Icp2
_______________________________________________
MonoTouch mailing list
[hidden email]
http://lists.ximian.com/mailman/listinfo/monotouch
Reply | Threaded
Open this post in threaded view
|

Re: Binding an interface that conforms to multiple protocols

Jeff Stedfast
In reply to this post by tkacem
The easiest way to bind these types of classes is to subclass one of them and then manually bind the other class's methods.

Hope that helps,

Jeff

On Tue, Jul 10, 2012 at 11:23 AM, tkacem <[hidden email]> wrote:
Hi Nic,

Thanks for your reply. The interface definition is as follows:

*@interface GDExtended : NSObject <UIApplicationDelegate,GDiOSDelegate>

- (void) handleEvent:(GDAppEvent *)anEvent;
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;

@end*


*@implementation GDExtended

- (id)init
{
    self = [super init];
    if (self) {
        // Initialization code here.
    }

    return self;
}

- (void) handleEvent:(GDAppEvent *)anEvent
{

}

- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    return YES;
}

@end
*

I am trying to wrap this in c# knowing that c# does not allow multiple
implementation. I wrote the wrapper for this interface in c# (I need the
GDiOSDelegate in order to create the event handler method which should
communicate with components from UIApplicationDelegate class).
The problem is that when I inherit GDExtended in a sample monotouch
application that uses the created Dll, I get an error that my class does not
implement UIApplicationDelegate.

Your prompt attention to this message is highly appreciated.
Thanks,
Thabet

--
View this message in context: http://monotouch.2284126.n4.nabble.com/Binding-an-interface-that-conforms-to-multiple-protocols-tp4655661p4655901.html
Sent from the MonoTouch mailing list archive at Nabble.com.
_______________________________________________
MonoTouch mailing list
[hidden email]
http://lists.ximian.com/mailman/listinfo/monotouch


_______________________________________________
MonoTouch mailing list
[hidden email]
http://lists.ximian.com/mailman/listinfo/monotouch
Reply | Threaded
Open this post in threaded view
|

Re: Binding an interface that conforms to multiple protocols

tkacem
Yes. That's what I did and it worked. Meanwhile, I am having another kind of error. Many methods in the wrapped classes in the monotouch dll return null when used in a sample project. I debugged the issue and found that the classHandle of many of those classes is equal to 0x0 as well as the class_ptr.
Any idea why this is happening ?
Reply | Threaded
Open this post in threaded view
|

Re: Binding an interface that conforms to multiple protocols

Jeff Stedfast
That makes me think that the native library isn't being linked into the final app.

1. Make sure that the binding dll is larger than the size of the native library (this is just a quick & easy way of determining if the dll has the native library embedded in it)

2. Make sure that you are targeting a device that is supported by the native library & that the LinkWith attribute includes that LinkTarget.

3. Browse over the build log and make sure that the native library is being pulled in (will be one of the gcc lines)

Hope that helps,

Jeff

On Fri, Jul 13, 2012 at 12:53 PM, tkacem <[hidden email]> wrote:
Yes. That's what I did and it worked. Meanwhile, I am having another kind of
error. Many methods in the wrapped classes in the monotouch dll return null
when used in a sample project. I debugged the issue and found that the
classHandle of many of those classes is equal to 0x0 as well as the
class_ptr.
Any idea why this is happening ?

--
View this message in context: http://monotouch.2284126.n4.nabble.com/Binding-an-interface-that-conforms-to-multiple-protocols-tp4655661p4655964.html
Sent from the MonoTouch mailing list archive at Nabble.com.
_______________________________________________
MonoTouch mailing list
[hidden email]
http://lists.ximian.com/mailman/listinfo/monotouch


_______________________________________________
MonoTouch mailing list
[hidden email]
http://lists.ximian.com/mailman/listinfo/monotouch
Reply | Threaded
Open this post in threaded view
|

Re: Binding an interface that conforms to multiple protocols

tkacem
Jeff,

Thanks for your reply.

1. The Dll's size (on disk) is bit over the native library size (30.6 MB vs 30.5 MB) but when I reference it in the new project the window finder shows it has 29.1 MB which is a bit bizarre.

2. I include the library by using --link-with options in btouch (I use btouch to generate the bindings not MonoDevelop's Monotouch binding Library. (I can't find a way to mention the link target)

3. I did not see any reference of the native library in the build log (by using -v -v -v with btouch)

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Binding an interface that conforms to multiple protocols

tkacem
when I create the Dll by:

/Developer/MonoTouch/usr/bin/btouch -e GDBinding.cs AssemblyInfo.cs -s:StructsAndEnums.cs -x:Extra.cs

then when I reference it in the sample project, I add these options to mtouch extra arguments:

cxx -gcc_flags "-L${ProjectDir} -lGD -force_load ${ProjectDir}/libGD.a"

But then it brings me back the exception saying the AppDelegate does not implement UIApplicationDelegate

Just to remind you, I solved that the multiple protocol issue by having the GDiOS kind of implement UIApplicationDelegate in the binding

        [BaseType (typeof (UIApplicationDelegate))]
        [Model]
        interface GDiOSDelegate {
                [Abstract]
                [Export ("handleEvent:")]
                void HandleEvent (GDAppEvent anEvent);

        }


Thank you very much for your help.
Reply | Threaded
Open this post in threaded view
|

Re: Binding an interface that conforms to multiple protocols

tkacem
Some of the native library code and the c# binding can be found at

http://stackoverflow.com/questions/11456092/classhandle-of-wrapped-monotouch-class-returns-null
Reply | Threaded
Open this post in threaded view
|

Re: Binding an interface that conforms to multiple protocols

Jeff Stedfast
In reply to this post by tkacem
Hi,

On Fri, Jul 13, 2012 at 3:30 PM, tkacem <[hidden email]> wrote:
Jeff,

Thanks for your reply.

1. The Dll's size (on disk) is bit over the native library size (30.6 MB vs
30.5 MB) but when I reference it in the new project the window finder shows
it has 29.1 MB which is a bit bizarre.

Probably just the different programs have different ways of calculating the size on disk.
 

2. I include the library by using --link-with options in btouch (I use
btouch to generate the bindings not MonoDevelop's Monotouch binding Library.
(I can't find a way to mention the link target)

The link target is specified in the AssemblyInfo.cs in the [LinkWith] attribute.
 

3. I did not see any reference of the native library in the build log (by
using -v -v -v with btouch)

I meant the MonoDevelop build log when building the app (not the binding). I should have been more explicit, sorry about that.

Jeff

_______________________________________________
MonoTouch mailing list
[hidden email]
http://lists.ximian.com/mailman/listinfo/monotouch
Reply | Threaded
Open this post in threaded view
|

Re: Binding an interface that conforms to multiple protocols

Jeff Stedfast
In reply to this post by tkacem


On Fri, Jul 13, 2012 at 4:39 PM, tkacem <[hidden email]> wrote:
when I create the Dll by:

*/Developer/MonoTouch/usr/bin/btouch -e GDBinding.cs AssemblyInfo.cs
-s:StructsAndEnums.cs -x:Extra.cs*

are you no longer using --link-with?
 

then when I reference it in the sample project, I add these options to
mtouch extra arguments:

*cxx -gcc_flags "-L${ProjectDir} -lGD -force_load ${ProjectDir}/libGD.a"*

This is only necessary if you are not embedding the native library into the binding dll.
 

But then it brings me back the exception saying the AppDelegate does not
implement UIApplicationDelegate

is it a c# exception or an objc exception? can you paste it?
 

Just to remind you, I solved that the multiple protocol issue by having the
GDiOS kind of implement UIApplicationDelegate in the binding

       * [BaseType (typeof (UIApplicationDelegate))]
        [Model]
        interface GDiOSDelegate {
                [Abstract]
                [Export ("handleEvent:")]
                void HandleEvent (GDAppEvent anEvent);

        }*

Thank you very much for your help.

Jeff 

_______________________________________________
MonoTouch mailing list
[hidden email]
http://lists.ximian.com/mailman/listinfo/monotouch
Reply | Threaded
Open this post in threaded view
|

Re: Binding an interface that conforms to multiple protocols

tkacem
Thanks Jeff. It worked by building the Dll from Monodevelop and it linked the native API correctly.
I am no longer getting the 0x0 for classHandle. I worked out a way that allowed me to avoid alling the method that throws the nasty exception. I will let you know if I need further help.
Thank you very much for all your help.
Reply | Threaded
Open this post in threaded view
|

Re: Binding an interface that conforms to multiple protocols

YARG
Hi guys,

I'm also trying to figure this out.  Initially I was using  GDiOS::Initialise() which seemed to work until I started trying to send files to the GFE.  Also delegation to GFE was turned off, as soon as it was turned on GFE and my App didn't want to play ball.  It transpired that I was calling a deprecated method :: Initialise()

It sounds exactly the same problem as I'm now calling
InitializeWithClassNameConformingToUIApplicationDelegate

This is the story so far:
https://community.good.com/message/18304?et=watches.email.thread#18304

The binding has been setup as the below, which I believe is correct.

    [BaseType (typeof (UIApplicationDelegate))]
    [Model]
    interface GDiOSDelegate {
            [Abstract]
            [Export ("handleEvent:")]
            void HandleEvent (GDAppEvent anEvent);

    }

and the AppDelegate.cs looks like this

[Register ("AppDelegate")]
public partial class AppDelegate : GDiOSDelegate
{ ... }


.. and the call in Main.cs looks like this

GDiOS.InitializeWithClassNameConformingToUIApplicationDelegate("AppDelegate");

.. and then when you run it it blows with

2014-02-04 09:26:25.880 XamarinGood[39491:80b] [4027.105MB] [064%] [8] + NSObject+UIApplicationDelegate::registerDelegateWithClass
2014-02-04 09:26:25.882 XamarinGood[39491:80b] *** Assertion failure in +[GDUIApplicationDelegate registerDelegateWithClass:], /Users/build-gd/jenkins_slave_node/workspace/Good_Apps_SDK_for_iOS_Release_Dave/dev/gd/dave-ios/msdk/platform/ios/NSObject+UIApplicationDelegate.mm:478

Or a call to GDiOS.InitializeWithClassConformingToUIApplicationDelegate(new MonoTouch.ObjCRuntime.Class(typeof(AppDelegate))); will do the same thing but these calls are essentially the same thing.

Can anyone confirm that they have got all this working?  At the moment, when calling the Initialise() method I can get it to download files via GD Http and also store files into the secure container.  However as mentioned this doesn't work with delegating authentication to GFE or allow me to post files to GFE.

I'd really appreciate any help on this as it's driving me nuts and I'm on borrowed time.  :-o

Thanks in advance.

Steve