summaryrefslogtreecommitdiff
path: root/communicate.c
blob: 0fbebaeef7407a86e25d4d4734eeab2d464a9257 (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
/**
 *
 * Compiz Nintendo(R) Wii(TM) Remote Interface Plugin
 *
 * Copyright : (C) 2008 by Sam Spilsbury
 * E-mail    : smspillaz@gmail.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 2
 * 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.
 *
 */

#include "wiimote-internal.h"

/* Inter-Plugin Communication --------------------------------------------------- */

Bool
sendInfoToPlugin (CompDisplay *d, CompOption *argument, int nArgument, char *pluginName, char *actionName)
{
	Bool pluginExists = FALSE;
	CompOption *options, *option;
	CompPlugin *p;
	CompObject *o;
	int nOptions;

	p = findActivePlugin (pluginName);
	o = compObjectFind (&core.base, COMP_OBJECT_TYPE_DISPLAY, NULL);

	if (!o)
		return FALSE;

	if (!p || !p->vTable->getObjectOptions)
	{
		compLogMessage ("wiimote", CompLogLevelError,
		"Reporting plugin '%s' does not exist!", pluginName);
		return FALSE;
	}

	if (p && p->vTable->getObjectOptions)
	{
		options = (*p->vTable->getObjectOptions) (p, o, &nOptions);
		option = compFindOption (options, nOptions, actionName, 0);
		pluginExists = TRUE;
	}

	if (pluginExists)
	{
		if (option && option->value.action.initiate)
		{
			(*option->value.action.initiate)  (d,
		                           &option->value.action,
		                           0,
		                           argument,
		                           nArgument);
		}
		else
		{
			compLogMessage ("wiimote", CompLogLevelError,
			"Plugin '%s' does exist, but no option named '%s' was found!", pluginName, actionName);
			return FALSE;
		}
	}

	return TRUE;
}