Discussion:
[Swig-user] C# directors from C++ with Xamarin iOS (repost)
StephenJStarkie
2015-10-01 15:36:28 UTC
Permalink
Hi, (this is a repost after subscribing to the list properly! sorry)

We have a body of code already using SWIG for Java (for Android mainly) from
a common C++ code base. This uses a IXXXXListener 'interface' (pure
abstract class in C++) to call back up to Java from the C++. This all works
well. However, I am now trying to make this work with C# in order to work
with Xamarin for iOS (and Android) and am having a problem with the
delegates that the SWIG director creates for C#. When I run I get an error:

Attempting to JIT compile method '(wrapper native-to-managed)
XXXXXX.IXXXXListener:SwigDirectoronXXXXX ()' while running with --aot-only.
See http://docs.xamarin.com/ios/about/limitations for more information.

The Xamarin documentation talks about applying the MonoPInvokeCallback
attribute wherever a delegate is provided to the native code (which I
understand; there can be no JIT on iOS). It also says that these need to be
static. I have done this as necessary and documented elsewhere for the
exceptions
(http://blog.reblochon.org/2013/01/c-bindings-for-monotouch-using-swig.html),
but it's not obvious how to do this with the director code that SWIG
generates.

Does anyone have any ideas? Can I make SWIG produce more Java-like wrappers
for C# directors? Or how would I go about turning the generated code into
statics that could be decorated with the appropriate attribute?

Thanks,

Steve



--
View this message in context: http://swig.10945.n7.nabble.com/C-directors-from-C-with-Xamarin-iOS-repost-tp14534.html
Sent from the swig-user mailing list archive at Nabble.com.

------------------------------------------------------------------------------
William S Fulton
2015-10-06 21:17:23 UTC
Permalink
Hi Stephen

Please take a look at the monotouch branch:
https://github.com/swig/swig/commits/monotouch. I put in these changes
after talking to Stephane Delcroix and Miguel de Icaza in Feb 2013,
but never received the final thumbs up for merging it into master. In
particular, this commit for director support needs testing:
https://github.com/swig/swig/commit/8b3a13129a3976c586f99c93dd8766e93c1211cf.
I suggest you try it out. I would like to know if the
Examples/csharp/extend and Examples/csharp/callback work. The testing
on Travis seem to fail at the time and that'll need investigation -
https://travis-ci.org/swig/swig/swig/jobs/11613887.

William

On 1 October 2015 at 16:36, StephenJStarkie
Post by StephenJStarkie
Hi, (this is a repost after subscribing to the list properly! sorry)
We have a body of code already using SWIG for Java (for Android mainly) from
a common C++ code base. This uses a IXXXXListener 'interface' (pure
abstract class in C++) to call back up to Java from the C++. This all works
well. However, I am now trying to make this work with C# in order to work
with Xamarin for iOS (and Android) and am having a problem with the
Attempting to JIT compile method '(wrapper native-to-managed)
XXXXXX.IXXXXListener:SwigDirectoronXXXXX ()' while running with --aot-only.
See http://docs.xamarin.com/ios/about/limitations for more information.
The Xamarin documentation talks about applying the MonoPInvokeCallback
attribute wherever a delegate is provided to the native code (which I
understand; there can be no JIT on iOS). It also says that these need to be
static. I have done this as necessary and documented elsewhere for the
exceptions
(http://blog.reblochon.org/2013/01/c-bindings-for-monotouch-using-swig.html),
but it's not obvious how to do this with the director code that SWIG
generates.
Does anyone have any ideas? Can I make SWIG produce more Java-like wrappers
for C# directors? Or how would I go about turning the generated code into
statics that could be decorated with the appropriate attribute?
Thanks,
Steve
--
View this message in context: http://swig.10945.n7.nabble.com/C-directors-from-C-with-Xamarin-iOS-repost-tp14534.html
Sent from the swig-user mailing list archive at Nabble.com.
------------------------------------------------------------------------------
_______________________________________________
Swig-user mailing list
https://lists.sourceforge.net/lists/listinfo/swig-user
------------------------------------------------------------------------------
Stephen Starkie
2015-10-07 09:08:31 UTC
Permalink
Thanks William,

I will try it out and let you know

Stephen
Post by William S Fulton
Hi Stephen
https://github.com/swig/swig/commits/monotouch. I put in these changes
after talking to Stephane Delcroix and Miguel de Icaza in Feb 2013,
but never received the final thumbs up for merging it into master. In
https://github.com/swig/swig/commit/8b3a13129a3976c586f99c93dd8766e93c1211cf.
I suggest you try it out. I would like to know if the
Examples/csharp/extend and Examples/csharp/callback work. The testing
on Travis seem to fail at the time and that'll need investigation -
https://travis-ci.org/swig/swig/swig/jobs/11613887.
William
On 1 October 2015 at 16:36, StephenJStarkie
Post by StephenJStarkie
Hi, (this is a repost after subscribing to the list properly! sorry)
We have a body of code already using SWIG for Java (for Android mainly) from
a common C++ code base. This uses a IXXXXListener 'interface' (pure
abstract class in C++) to call back up to Java from the C++. This all works
well. However, I am now trying to make this work with C# in order to work
with Xamarin for iOS (and Android) and am having a problem with the
Attempting to JIT compile method '(wrapper native-to-managed)
XXXXXX.IXXXXListener:SwigDirectoronXXXXX ()' while running with --aot-only.
See http://docs.xamarin.com/ios/about/limitations for more information.
The Xamarin documentation talks about applying the MonoPInvokeCallback
attribute wherever a delegate is provided to the native code (which I
understand; there can be no JIT on iOS). It also says that these need to be
static. I have done this as necessary and documented elsewhere for the
exceptions
(http://blog.reblochon.org/2013/01/c-bindings-for-monotouch-using-swig.html),
but it's not obvious how to do this with the director code that SWIG
generates.
Does anyone have any ideas? Can I make SWIG produce more Java-like wrappers
for C# directors? Or how would I go about turning the generated code into
statics that could be decorated with the appropriate attribute?
Thanks,
Steve
--
View this message in context: http://swig.10945.n7.nabble.com/C-directors-from-C-with-Xamarin-iOS-repost-tp14534.html
Sent from the swig-user mailing list archive at Nabble.com.
------------------------------------------------------------------------------
_______________________________________________
Swig-user mailing list
https://lists.sourceforge.net/lists/listinfo/swig-user
CaseySL
2017-05-18 19:47:34 UTC
Permalink
Hi William & Stephen:

I am hoping you have made progress or have advice on the following:


I am using PJSIP (PJSUA2) in Xamarin.Android and Xamarin.iOS projects using
C#. PJSIP (PJSUA2) utilizes SWIG to generate the Java and C# bindings for
the C++ library.

I am new to SWIG and am having difficulties understanding how to best use
SWIG on C++ Callbacks to generate appropriate SWIG C# for iOS which is AOT
only. ( SWIG C# for java/Android works great since JIT is allowed )

I have resolved the pjsua2PINVOKE.SWIGExceptionHelper class:
1. Added the [ObjCRuntime.MonoNativeFunctionWrapper] descriptor to the
delegates
2. Added the [ObjCRuntime.MonoPInvokeCallback(typeof(ExceptionDelegate))]
descriptor to the static functions.

Now I have encountered issues with callbacks using directors, how do I
resolve?

Call.cs SWIG generated code:

[ObjCRuntime.MonoNativeFunctionWrapper]
public delegate void SwigDelegateCall_0(global::System.IntPtr prm);

[ObjCRuntime.MonoPInvokeCallback(typeof(SwigDelegateCall_0))]
private void SwigDirectoronCallState(global::System.IntPtr prm) {
onCallState(new OnCallStateParam(prm, false));
}

1. Added [ObjCRuntime.MonoNativeFunctionWrapper] descriptor to the delgates
2. Attempted to add
[ObjCRuntime.MonoPInvokeCallback(typeof(SwigDelegateCall_0))] descriptor,
but it won't work on non-static functions.

What is the best practice for having SWIG generate the appropriate
Callbacks?

Thank you for your time and assistance,
~Casey
Post by William S Fulton
Hi Stephen
https://github.com/swig/swig/commits/monotouch. I put in these changes
after talking to Stephane Delcroix and Miguel de Icaza in Feb 2013,
but never received the final thumbs up for merging it into master. In
https://github.com/swig/swig/commit/8b3a13129a3976c586f99c93dd8766e93c1211cf.
I suggest you try it out. I would like to know if the
Examples/csharp/extend and Examples/csharp/callback work. The testing
on Travis seem to fail at the time and that'll need investigation -
https://travis-ci.org/swig/swig/swig/jobs/11613887.
William
On 1 October 2015 at 16:36, StephenJStarkie
<
Post by StephenJStarkie
Hi, (this is a repost after subscribing to the list properly! sorry)
We have a body of code already using SWIG for Java (for Android mainly) from
a common C++ code base. This uses a IXXXXListener 'interface' (pure
abstract class in C++) to call back up to Java from the C++. This all works
well. However, I am now trying to make this work with C# in order to work
with Xamarin for iOS (and Android) and am having a problem with the
Attempting to JIT compile method '(wrapper native-to-managed)
XXXXXX.IXXXXListener:SwigDirectoronXXXXX ()' while running with --aot-only.
See http://docs.xamarin.com/ios/about/limitations for more information.
The Xamarin documentation talks about applying the MonoPInvokeCallback
attribute wherever a delegate is provided to the native code (which I
understand; there can be no JIT on iOS). It also says that these need to be
static. I have done this as necessary and documented elsewhere for the
exceptions
(http://blog.reblochon.org/2013/01/c-bindings-for-monotouch-using-swig.html),
but it's not obvious how to do this with the director code that SWIG
generates.
Does anyone have any ideas? Can I make SWIG produce more Java-like wrappers
for C# directors? Or how would I go about turning the generated code into
statics that could be decorated with the appropriate attribute?
Thanks,
Steve
--
http://swig.10945.n7.nabble.com/C-directors-from-C-with-Xamarin-iOS-repost-tp14534.html
Sent from the swig-user mailing list archive at Nabble.com.
------------------------------------------------------------------------------
_______________________________________________
Swig-user mailing list
https://lists.sourceforge.net/lists/listinfo/swig-user
------------------------------------------------------------------------------
_______________________________________________
Swig-user mailing list
https://lists.sourceforge.net/lists/listinfo/swig-user
--
View this message in context: http://swig.10945.n7.nabble.com/C-directors-from-C-with-Xamarin-iOS-repost-tp14534p15166.html
Sent from the swig-user mailing list archive at Nabble.com.

Loading...