qulogic/gplugin
Clone
Summary
Browse
Changes
Graph
flow: Promoted <develop> 'trunk' (22bf185b75f0) to 'feature/mono'.
feature/mono
2015-06-29, Gary Kramlich
ef531afbb1c6
flow: Promoted
'trunk' (22bf185b75f0) to 'feature/mono'.
/*
* Copyright (C) 2011-2014 Gary Kramlich <grim@reaperworld.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include
"gplugin-mono-plugin.h"
#include
<mono/jit/jit.h>
#include
<mono/metadata/assembly.h>
#define GPLUGIN_MONO_PLUGIN_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE((obj), GPLUGIN_TYPE_MONO_PLUGIN, GPluginMonoPluginPrivate))
/******************************************************************************
* Typedefs
*****************************************************************************/
typedef
struct
{
MonoDomain
*
domain
;
MonoAssembly
*
assembly
;
}
GPluginMonoPluginPrivate
;
/******************************************************************************
* Enums
*****************************************************************************/
enum
{
PROP_ZERO
,
PROP_DOMAIN
,
PROP_ASSEMBLY
,
PROP_LAST
,
};
/******************************************************************************
* Globals
*****************************************************************************/
static
GObjectClass
*
parent_class
=
NULL
;
static
GType
type_real
=
0
;
/******************************************************************************
* Private Stuff
*****************************************************************************/
static
void
gplugin_mono_plugin_set_domain
(
GPluginMonoPlugin
*
plugin
,
MonoDomain
*
domain
)
{
GPluginMonoPluginPrivate
*
priv
=
GPLUGIN_MONO_PLUGIN_GET_PRIVATE
(
plugin
);
priv
->
domain
=
domain
;
}
static
void
gplugin_mono_plugin_set_assembly
(
GPluginMonoPlugin
*
plugin
,
MonoAssembly
*
assembly
)
{
GPluginMonoPluginPrivate
*
priv
=
GPLUGIN_MONO_PLUGIN_GET_PRIVATE
(
plugin
);
priv
->
assembly
=
assembly
;
}
/******************************************************************************
* Object Stuff
*****************************************************************************/
static
void
gplugin_mono_plugin_get_property
(
GObject
*
obj
,
guint
param_id
,
GValue
*
value
,
GParamSpec
*
pspec
)
{
GPluginMonoPlugin
*
plugin
=
GPLUGIN_MONO_PLUGIN
(
obj
);
switch
(
param_id
)
{
case
PROP_DOMAIN
:
g_value_set_pointer
(
value
,
gplugin_mono_plugin_get_domain
(
plugin
));
break
;
case
PROP_ASSEMBLY
:
g_value_set_pointer
(
value
,
gplugin_mono_plugin_get_assembly
(
plugin
));
break
;
default
:
G_OBJECT_WARN_INVALID_PROPERTY_ID
(
obj
,
param_id
,
pspec
);
break
;
}
}
static
void
gplugin_mono_plugin_set_property
(
GObject
*
obj
,
guint
param_id
,
const
GValue
*
value
,
GParamSpec
*
pspec
)
{
GPluginMonoPlugin
*
plugin
=
GPLUGIN_MONO_PLUGIN
(
obj
);
switch
(
param_id
)
{
case
PROP_DOMAIN
:
gplugin_mono_plugin_set_domain
(
plugin
,
g_value_get_pointer
(
value
));
break
;
case
PROP_ASSEMBLY
:
gplugin_mono_plugin_set_assembly
(
plugin
,
g_value_get_pointer
(
value
));
break
;
default
:
G_OBJECT_WARN_INVALID_PROPERTY_ID
(
obj
,
param_id
,
pspec
);
break
;
}
}
static
void
gplugin_mono_plugin_finalize
(
GObject
*
obj
)
{
GPluginMonoPluginPrivate
*
priv
=
GPLUGIN_MONO_PLUGIN_GET_PRIVATE
(
obj
);
if
(
priv
->
domain
)
mono_jit_cleanup
(
priv
->
domain
);
G_OBJECT_CLASS
(
parent_class
)
->
finalize
(
obj
);
}
static
void
gplugin_mono_plugin_class_init
(
GPluginMonoPluginClass
*
klass
)
{
GObjectClass
*
obj_class
=
G_OBJECT_CLASS
(
klass
);
parent_class
=
g_type_class_peek_parent
(
klass
);
g_type_class_add_private
(
klass
,
sizeof
(
GPluginMonoPluginPrivate
));
obj_class
->
get_property
=
gplugin_mono_plugin_get_property
;
obj_class
->
set_property
=
gplugin_mono_plugin_set_property
;
obj_class
->
finalize
=
gplugin_mono_plugin_finalize
;
g_object_class_install_property
(
obj_class
,
PROP_DOMAIN
,
g_param_spec_pointer
(
"domain"
,
"domain"
,
"The mono domain of the plugin"
,
G_PARAM_READWRITE
|
G_PARAM_CONSTRUCT_ONLY
));
g_object_class_install_property
(
obj_class
,
PROP_ASSEMBLY
,
g_param_spec_pointer
(
"assembly"
,
"assembly"
,
"The mono assembly of the plugin"
,
G_PARAM_READWRITE
|
G_PARAM_CONSTRUCT_ONLY
));
}
/******************************************************************************
* API
*****************************************************************************/
void
gplugin_mono_plugin_register
(
GPluginNativePlugin
*
plugin
)
{
if
(
g_once_init_enter
(
&
type_real
))
{
GType
type
=
0
;
static
const
GTypeInfo
info
=
{
.
class_size
=
sizeof
(
GPluginMonoPluginClass
),
.
class_init
=
(
GClassInitFunc
)
gplugin_mono_plugin_class_init
,
.
instance_size
=
sizeof
(
GPluginMonoPlugin
),
};
type
=
gplugin_native_plugin_register_type
(
plugin
,
GPLUGIN_TYPE_PLUGIN
,
"GPluginMonoPlugin"
,
&
info
,
0
);
g_once_init_leave
(
&
type_real
,
type
);
}
}
GType
gplugin_mono_plugin_get_type
(
void
)
{
if
(
G_UNLIKELY
(
type_real
==
0
))
{
g_warning
(
"gplugin_mono_plugin_get_type was called before "
"the type was registered!
\n
"
);
}
return
type_real
;
}
MonoDomain
*
gplugin_mono_plugin_get_domain
(
const
GPluginMonoPlugin
*
plugin
)
{
GPluginMonoPluginPrivate
*
priv
=
GPLUGIN_MONO_PLUGIN_GET_PRIVATE
(
plugin
);
return
priv
->
domain
;
}
MonoAssembly
*
gplugin_mono_plugin_get_assembly
(
const
GPluginMonoPlugin
*
plugin
)
{
GPluginMonoPluginPrivate
*
priv
=
GPLUGIN_MONO_PLUGIN_GET_PRIVATE
(
plugin
);
return
priv
->
assembly
;
}