File: bonobo-moniker-query.c

package info (click to toggle)
bonobo 1.0.22-2.2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 13,412 kB
  • ctags: 5,445
  • sloc: ansic: 51,714; sh: 7,733; makefile: 1,425; yacc: 318; xml: 266; sed: 16
file content (150 lines) | stat: -rw-r--r-- 3,600 bytes parent folder | download | duplicates (2)
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
149
150
/*
 * gnome-moniker-query.c: Sample query-activation based Moniker implementation
 *
 * This is the Oaf query based Moniker implementation.
 *
 * Author:
 *	Michael Meeks (michael@helixcode.com)
 */
#include <config.h>
#include <bonobo/bonobo-moniker.h>
#include <bonobo/bonobo-moniker-util.h>
#include <liboaf/liboaf.h>

#include "bonobo-moniker-query.h"

#define PREFIX_LEN (sizeof ("query:") - 1)

static BonoboMonikerClass *bonobo_moniker_query_parent_class;

static Bonobo_Moniker 
query_parse_display_name (BonoboMoniker     *moniker,
			  Bonobo_Moniker     parent,
			  const CORBA_char  *name,
			  CORBA_Environment *ev)
{
	BonoboMonikerQuery *m_query = BONOBO_MONIKER_QUERY (moniker);
	int      i, brackets;
	gboolean in_string;

	g_return_val_if_fail (m_query != NULL, CORBA_OBJECT_NIL);
	g_return_val_if_fail (strlen (name) >= PREFIX_LEN, CORBA_OBJECT_NIL);

	bonobo_moniker_set_parent (moniker, parent, ev);

	brackets = 0;
	in_string = FALSE;
	for (i = PREFIX_LEN; name [i]; i++) {
		switch (name [i]) {
		case '(':
			if (!in_string)
				brackets++;
			break;
		case ')':
			if (!in_string)
				brackets--;
			break;
		case '\'':
			if (name [i - 1] != '\\')
				in_string = !in_string;
			break;
		}
		if (brackets == 0) {
			i++;
			break;
		}
	}
	
	if (in_string || brackets != 0) {
		CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
				     ex_Bonobo_Moniker_InvalidSyntax, NULL);
		return CORBA_OBJECT_NIL;
	}
	
	bonobo_moniker_set_name (moniker, name, i);

	return bonobo_moniker_util_new_from_name_full (BONOBO_OBJREF (m_query),
						       &name [i], ev);
}

static Bonobo_Unknown
query_resolve (BonoboMoniker               *moniker,
	      const Bonobo_ResolveOptions *options,
	      const CORBA_char            *requested_interface,
	      CORBA_Environment           *ev)
{
	Bonobo_Moniker       parent;
	Bonobo_Unknown       object;
	char                *query;
	
	parent = bonobo_moniker_get_parent (moniker, ev);

	if (ev->_major != CORBA_NO_EXCEPTION)
		return CORBA_OBJECT_NIL;
	
	if (parent != CORBA_OBJECT_NIL) {
		bonobo_object_release_unref (parent, ev);

		g_warning ("wierd; queryied moniker with a parent; strange");
		CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
				     ex_Bonobo_Moniker_InterfaceNotFound, NULL);
		return CORBA_OBJECT_NIL;
	}

	query = g_strdup_printf ("%s AND repo_ids.has ('%s')",
				 bonobo_moniker_get_name (moniker),
				 requested_interface);

	object = oaf_activate (query, NULL, 0, NULL, ev);

	g_free (query);

	return bonobo_moniker_util_qi_return (object, requested_interface, ev);
}

static void
bonobo_moniker_query_class_init (BonoboMonikerQueryClass *klass)
{
	BonoboMonikerClass *mclass = (BonoboMonikerClass *) klass;
	
	bonobo_moniker_query_parent_class = gtk_type_class (
		bonobo_moniker_get_type ());

	mclass->parse_display_name = query_parse_display_name;
	mclass->resolve            = query_resolve;
}

/**
 * bonobo_moniker_query_get_type:
 *
 * Returns the GtkType for the BonoboMonikerQuery class.
 */
GtkType
bonobo_moniker_query_get_type (void)
{
	static GtkType type = 0;

	if (!type) {
		GtkTypeInfo info = {
			"BonoboMonikerQuery",
			sizeof (BonoboMonikerQuery),
			sizeof (BonoboMonikerQueryClass),
			(GtkClassInitFunc) bonobo_moniker_query_class_init,
			(GtkObjectInitFunc) NULL,
			NULL, /* reserved 1 */
			NULL, /* reserved 2 */
			(GtkClassInitFunc) NULL
		};

		type = gtk_type_unique (bonobo_moniker_get_type (), &info);
	}

	return type;
}

BonoboMoniker *
bonobo_moniker_query_new (void)
{
	return bonobo_moniker_construct (
		gtk_type_new (bonobo_moniker_query_get_type ()), "query:(");
}