Discussion:
Wrapping libmrproject: libmrproject-sharp
Alvaro
2003-02-14 12:52:01 UTC
Permalink
Hi guys!

Two weekends ago I tried to wrap libmrproject to use it from C#. I tried
the GAPI approach:

1. Put the source code in a directory
2. Use the gapi parser to generate a XML API version of libmrproject
3. Use the C# Generator to create the C# bindings from the XML API

Loading Image...

The results have been nice, very nice I will say. Yes, I have found some
problems like:

1. When gapi, a Perl parser, looks at the class contents it searchs for
the class init functions to find the signals and params. To find this
function it thinks that if the class name is MrpTask, the init class
function have to be:

mrp_task_init

Currently we have

task_init

so by default it doesn't find params and signals :(

Once you change that, the parser will find params and signals and will
map them to C# Properties and Events.


2. The gapi parser can't work with our specific params like:

g_object_class_install_property (
object_class,
PROP_LATEST_FINISH,
mrp_param_spec_time ("latest-finish",
"Latest task finish time",
NULL,
G_PARAM_READABLE));

It only works with g_param_spec_*

3. Tha gapi parser, the preprocessor, isn't very brilliant and the
comments in the
signals code make it fail. If you clean the comments, the signals are
mapped correctly
to C# Events.

The mapping I have now is very near to be complete. I only need to
modify the gapi parser
so it can work with our custom params.


I have made this code to work:

using System;
using MrProject;
using Gtk;
using GLib;

public class Test10 {
static int Main() {
MrpProject project;
MrpApplication app;
List tasks, resources;

Application.Init ();
app = new MrpApplication();
project = new MrpProject (app);

project.Loaded += new EventHandler (Project_Loaded);

project.Load ("test.mrproject");

// Project data
Console.WriteLine ("Project: " + project.Name);
Console.WriteLine ("Organization: " +
project.Organization);

tasks = project.AllTasks;
resources = project.Resources;

foreach (MrpTask task in project.AllTasks) {
Console.WriteLine ("Task: "+ task.Name);
}

foreach (MrpResource resource in project.Resources) {
Console.WriteLine ("Resource: "+ resource.Name);
}

return 0;
}

static void Project_Loaded (object o, EventArgs args) {
Console.WriteLine ("The project has been loaded correctly");
}
}

Cheers
--
Alvaro <***@barrapunto.com>
Barrapunto
Alvaro
2003-02-14 12:19:16 UTC
Permalink
Hi guys!

Two weekends ago I tried to wrap libmrproject to use it from C#. I tried
the GAPI approach:

1. Put the source code in a directory
2. Use the gapi parser to generate a XML API version of libmrproject
3. Use the C# Generator to create the C# bindings from the XML API

http://mono.es.gnome.org/tutoriales/enlaces-c/gapi.jpg

The results have been nice, very nice I will say. Yes, I have found some
problems like:

1. When gapi, a Perl parser, looks at the class contents it searchs for
the class init functions to find the signals and params. To find this
function it thinks that if the class name is MrpTask, the init class
function have to be:

mrp_task_init

Currently we have

task_init

so by default it doesn't find params and signals :(

Once you change that, the parser will find params and signals and will
map them to C# Properties and Events.


2. The gapi parser can't work with our specific params like:

g_object_class_install_property (
object_class,
PROP_LATEST_FINISH,
mrp_param_spec_time ("latest-finish",
"Latest task finish time",
NULL,
G_PARAM_READABLE));

It only works with g_param_spec_*

3. Tha gapi parser, the preprocessor, isn't very brilliant and the comments in the
signals code make it fail. If you clean the comments, the signals are mapped correctly
to C# Events.

The mapping I have now is very near to be complete. I only need to modify the gapi parser
so it can work with our custom params.


I have made this code to work:

using System;
using MrProject;
using Gtk;
using GLib;

public class Test10 {
static int Main() {
MrpProject project;
MrpApplication app;
List tasks, resources;

Application.Init ();
app = new MrpApplication();
project = new MrpProject (app);

project.Loaded += new EventHandler (Project_Loaded);

project.Load ("test.mrproject");

// Project data
Console.WriteLine ("Project: " + project.Name);
Console.WriteLine ("Organization: " + project.Organization);

tasks = project.AllTasks;
resources = project.Resources;

foreach (MrpTask task in project.AllTasks) {
Console.WriteLine ("Task: "+ task.Name);
}

foreach (MrpResource resource in project.Resources) {
Console.WriteLine ("Resource: "+ resource.Name);
}

return 0;
}

static void Project_Loaded (object o, EventArgs args) {
Console.WriteLine ("The project has been loaded correctly");
}
}

Cheers
--
Alvaro <***@andago.com>
Loading...