[18310] | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ |
---|
| 2 | /* |
---|
| 3 | * oafd: OAF CORBA dameon. |
---|
| 4 | * |
---|
| 5 | * Copyright (C) 1999, 2000 Red Hat, Inc. |
---|
| 6 | * Copyright (C) 1999, 2000 Eazel, Inc. |
---|
| 7 | * |
---|
| 8 | * This library is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License as |
---|
| 10 | * published by the Free Software Foundation; either version 2 of the |
---|
| 11 | * License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This library is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 16 | * General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this library; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
| 21 | * |
---|
| 22 | * Authors: Elliot Lee <sopwith@redhat.com>, |
---|
| 23 | * |
---|
| 24 | */ |
---|
| 25 | |
---|
| 26 | #ifndef QUERY_EXPR_H |
---|
| 27 | #define QUERY_EXPR_H 1 |
---|
| 28 | |
---|
| 29 | #include <bonobo-activation/Bonobo_ActivationContext.h> |
---|
| 30 | |
---|
| 31 | #include <glib.h> |
---|
| 32 | |
---|
| 33 | typedef enum |
---|
| 34 | { EXPR_FUNCTION, EXPR_VARIABLE, EXPR_ID, EXPR_BINOP, EXPR_UNOP, EXPR_CONSTANT } |
---|
| 35 | QueryExprType; |
---|
| 36 | |
---|
| 37 | typedef enum |
---|
| 38 | { CONST_STRING, CONST_STRINGV, CONST_NUMBER, CONST_BOOLEAN } |
---|
| 39 | QueryExprConstType; |
---|
| 40 | |
---|
| 41 | typedef struct |
---|
| 42 | { |
---|
| 43 | QueryExprConstType type; |
---|
| 44 | union |
---|
| 45 | { |
---|
| 46 | char *v_string; |
---|
| 47 | char **v_stringv; |
---|
| 48 | gdouble v_number; |
---|
| 49 | gboolean v_boolean; |
---|
| 50 | } |
---|
| 51 | u; |
---|
| 52 | |
---|
| 53 | guchar value_known, needs_free; |
---|
| 54 | } |
---|
| 55 | QueryExprConst; |
---|
| 56 | |
---|
| 57 | typedef struct _QueryExpr QueryExpr; |
---|
| 58 | |
---|
| 59 | struct _QueryExpr |
---|
| 60 | { |
---|
| 61 | QueryExprType type; |
---|
| 62 | |
---|
| 63 | union |
---|
| 64 | { |
---|
| 65 | struct |
---|
| 66 | { |
---|
| 67 | char *func_name; |
---|
| 68 | GSList *arguments; |
---|
| 69 | } |
---|
| 70 | function_value; |
---|
| 71 | |
---|
| 72 | char *var_value; |
---|
| 73 | char *id_value; |
---|
| 74 | |
---|
| 75 | struct |
---|
| 76 | { |
---|
| 77 | enum |
---|
| 78 | { OP_EQ, OP_NEQ, OP_LEQ, OP_GEQ, OP_LT, OP_GT, OP_OR, |
---|
| 79 | OP_AND, OP_MULTIPLY, OP_DIVIDE, OP_ADD, |
---|
| 80 | OP_SUBTRACT, OP_XOR |
---|
| 81 | } |
---|
| 82 | type; |
---|
| 83 | |
---|
| 84 | QueryExpr *op1, *op2; |
---|
| 85 | } |
---|
| 86 | binop_value; |
---|
| 87 | |
---|
| 88 | struct |
---|
| 89 | { |
---|
| 90 | enum |
---|
| 91 | { OP_NOT, OP_NEGATE } |
---|
| 92 | type; |
---|
| 93 | QueryExpr *op; |
---|
| 94 | } |
---|
| 95 | unop_value; |
---|
| 96 | |
---|
| 97 | QueryExprConst constant_value; |
---|
| 98 | } |
---|
| 99 | u; |
---|
| 100 | |
---|
| 101 | QueryExprConst cached_value; |
---|
| 102 | guchar has_fields, have_cached_value; |
---|
| 103 | }; |
---|
| 104 | |
---|
| 105 | QueryExpr *qexp_binop_new (QueryExpr * op1, int operand, QueryExpr * op2); |
---|
| 106 | QueryExpr *qexp_unop_new (int operand, QueryExpr * op); |
---|
| 107 | QueryExpr *qexp_function_new (char *name, GSList * exprlist); |
---|
| 108 | QueryExpr *qexp_variable_new (char *name); |
---|
| 109 | QueryExpr *qexp_id_new (char *name); |
---|
| 110 | QueryExpr *qexp_constant_new (QueryExprConst setme); |
---|
| 111 | |
---|
| 112 | const char *qexp_parse (const char *_code, QueryExpr ** retme); /* Return value is a string describing any errors */ |
---|
| 113 | void qexp_free (QueryExpr * qexp); |
---|
| 114 | |
---|
| 115 | /* For debugging purposes */ |
---|
| 116 | void qexp_dump (QueryExpr * exp); |
---|
| 117 | void qexp_constant_dump (QueryExprConst * c); |
---|
| 118 | gint qexp_constant_compare (const QueryExprConst * c1, |
---|
| 119 | const QueryExprConst * c2); |
---|
| 120 | |
---|
| 121 | typedef struct _QueryContext QueryContext; |
---|
| 122 | |
---|
| 123 | typedef QueryExprConst (*QueryIDEvaluateFunc) (Bonobo_ServerInfo * si, |
---|
| 124 | const char *id, |
---|
| 125 | QueryContext * qctx); |
---|
| 126 | |
---|
| 127 | struct _QueryContext |
---|
| 128 | { |
---|
| 129 | Bonobo_ServerInfo **sil; |
---|
| 130 | int nservers; |
---|
| 131 | |
---|
| 132 | QueryIDEvaluateFunc id_evaluator; |
---|
| 133 | |
---|
| 134 | CORBA_Context cctx; |
---|
| 135 | |
---|
| 136 | gpointer user_data; |
---|
| 137 | }; |
---|
| 138 | |
---|
| 139 | QueryExprConst qexp_evaluate (Bonobo_ServerInfo * si, QueryExpr * e, |
---|
| 140 | QueryContext * qctx); |
---|
| 141 | gboolean qexp_matches (Bonobo_ServerInfo * si, QueryExpr * e, |
---|
| 142 | QueryContext * qctx); |
---|
| 143 | void qexp_sort (Bonobo_ServerInfo ** servers, int nservers, QueryExpr ** sexps, |
---|
| 144 | int nexps, QueryContext * qctx); |
---|
| 145 | |
---|
| 146 | #endif |
---|