summaryrefslogtreecommitdiff
path: root/libpeas/peas-plugin-loader.c
blob: 880810bc092bc8a35e7d5aa041cb9cc97df8853c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
 * peas-plugin-loader.c
 * This file is part of libpeas
 *
 * Copyright (C) 2008 - Jesse van den Kieboom
 *
 * libpeas is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * libpeas 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA.
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#include "config.h"

#include "peas-plugin-loader.h"

G_DEFINE_ABSTRACT_TYPE (PeasPluginLoader, peas_plugin_loader, G_TYPE_OBJECT)

static void
peas_plugin_loader_finalize (GObject *object)
{
  g_debug ("Plugin Loader '%s' Finalized", G_OBJECT_TYPE_NAME (object));

  G_OBJECT_CLASS (peas_plugin_loader_parent_class)->finalize (object);
}

static void
peas_plugin_loader_init (PeasPluginLoader *loader)
{
}

static void
peas_plugin_loader_class_init (PeasPluginLoaderClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->finalize = peas_plugin_loader_finalize;
}

gboolean
peas_plugin_loader_initialize (PeasPluginLoader *loader)
{
  PeasPluginLoaderClass *klass;

  g_return_val_if_fail (PEAS_IS_PLUGIN_LOADER (loader), FALSE);

  klass = PEAS_PLUGIN_LOADER_GET_CLASS (loader);

  /* Do this here instead of each time */
  g_return_val_if_fail (klass->load != NULL, FALSE);
  g_return_val_if_fail (klass->unload != NULL, FALSE);
  g_return_val_if_fail (klass->provides_extension != NULL, FALSE);
  g_return_val_if_fail (klass->create_extension != NULL, FALSE);

  if (klass->initialize != NULL)
    return klass->initialize (loader);

  return TRUE;
}

gboolean
peas_plugin_loader_is_global (PeasPluginLoader *loader)
{
  PeasPluginLoaderClass *klass;

  g_return_val_if_fail (PEAS_IS_PLUGIN_LOADER (loader), FALSE);

  klass = PEAS_PLUGIN_LOADER_GET_CLASS (loader);

  if (klass->is_global != NULL)
    return klass->is_global (loader);

  return TRUE;
}

gboolean
peas_plugin_loader_load (PeasPluginLoader *loader,
                         PeasPluginInfo   *info)
{

  g_return_val_if_fail (PEAS_IS_PLUGIN_LOADER (loader), FALSE);

  return PEAS_PLUGIN_LOADER_GET_CLASS (loader)->load (loader, info);
}

void
peas_plugin_loader_unload (PeasPluginLoader *loader,
                           PeasPluginInfo   *info)
{
  g_return_if_fail (PEAS_IS_PLUGIN_LOADER (loader));

  PEAS_PLUGIN_LOADER_GET_CLASS (loader)->unload (loader, info);
}

gboolean
peas_plugin_loader_provides_extension (PeasPluginLoader *loader,
                                       PeasPluginInfo   *info,
                                       GType             ext_type)
{
  PeasPluginLoaderClass *klass;

  g_return_val_if_fail (PEAS_IS_PLUGIN_LOADER (loader), FALSE);

  klass = PEAS_PLUGIN_LOADER_GET_CLASS (loader);
  return klass->provides_extension (loader, info, ext_type);
}

G_GNUC_BEGIN_IGNORE_DEPRECATIONS
GObject *
peas_plugin_loader_create_extension (PeasPluginLoader *loader,
                                     PeasPluginInfo   *info,
                                     GType             ext_type,
                                     guint             n_parameters,
                                     GParameter       *parameters)
{
  PeasPluginLoaderClass *klass;

  g_return_val_if_fail (PEAS_IS_PLUGIN_LOADER (loader), NULL);

  klass = PEAS_PLUGIN_LOADER_GET_CLASS (loader);
  return klass->create_extension (loader, info, ext_type,
                                  n_parameters, parameters);
}
G_GNUC_END_IGNORE_DEPRECATIONS

void
peas_plugin_loader_garbage_collect (PeasPluginLoader *loader)
{
  PeasPluginLoaderClass *klass;

  g_return_if_fail (PEAS_IS_PLUGIN_LOADER (loader));

  klass = PEAS_PLUGIN_LOADER_GET_CLASS (loader);

  if (klass->garbage_collect != NULL)
    klass->garbage_collect (loader);
}