mirror of
git://git.psyc.eu/libpsyc
synced 2024-08-15 03:19:02 +00:00
psyc_method_family()
This commit is contained in:
parent
d0b3b85924
commit
efd58428a9
4 changed files with 104 additions and 3 deletions
|
@ -94,6 +94,14 @@ typedef enum {
|
||||||
PSYC_LIST_BINARY = 2,
|
PSYC_LIST_BINARY = 2,
|
||||||
} PsycListType;
|
} PsycListType;
|
||||||
|
|
||||||
|
typedef enum PsycMessageFlag {
|
||||||
|
PSYC_MESSAGE_TEMPLATE = 1 << 0,
|
||||||
|
PSYC_MESSAGE_REPLY = 1 << 1,
|
||||||
|
PSYC_MESSAGE_VISIBLE = 1 << 2,
|
||||||
|
PSYC_MESSAGE_LOGGABLE = 1 << 3,
|
||||||
|
PSYC_MESSAGE_MANUAL = 1 << 4,
|
||||||
|
} PsycMessageFlag;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* String struct.
|
* String struct.
|
||||||
*
|
*
|
||||||
|
|
|
@ -67,6 +67,21 @@ typedef enum {
|
||||||
PSYC_STATE_RESYNC = '?',
|
PSYC_STATE_RESYNC = '?',
|
||||||
} PsycStateOp;
|
} PsycStateOp;
|
||||||
|
|
||||||
|
typedef enum PsycMethod {
|
||||||
|
PSYC_METHOD_UNKNOWN,
|
||||||
|
PSYC_METHOD_DATA,
|
||||||
|
PSYC_METHOD_ECHO,
|
||||||
|
PSYC_METHOD_ERROR,
|
||||||
|
PSYC_METHOD_FAILURE,
|
||||||
|
PSYC_METHOD_INFO,
|
||||||
|
PSYC_METHOD_MESSAGE,
|
||||||
|
PSYC_METHOD_MESSAGE_ECHO,
|
||||||
|
PSYC_METHOD_NOTICE,
|
||||||
|
PSYC_METHOD_REQUEST,
|
||||||
|
PSYC_METHOD_STATUS,
|
||||||
|
PSYC_METHOD_WARNING,
|
||||||
|
} PsycMethod;
|
||||||
|
|
||||||
/** Structure for a modifier. */
|
/** Structure for a modifier. */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char oper;
|
char oper;
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
#ifndef PSYC_VARIABLE_H
|
|
||||||
#define PSYC_VARIABLE_H
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file psyc/variable.h
|
* @file psyc/variable.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef PSYC_VARIABLE_H
|
||||||
|
#define PSYC_VARIABLE_H
|
||||||
|
|
||||||
|
#include "packet.h"
|
||||||
|
|
||||||
/// Routing variables in alphabetical order.
|
/// Routing variables in alphabetical order.
|
||||||
extern const PsycString psyc_routing_vars[];
|
extern const PsycString psyc_routing_vars[];
|
||||||
|
|
||||||
|
@ -36,4 +38,7 @@ psyc_var_is_list (const char *name, size_t len)
|
||||||
? PSYC_FALSE : PSYC_TRUE;
|
? PSYC_FALSE : PSYC_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PsycMethod
|
||||||
|
psyc_method_family (char *method, size_t methodlen, unsigned int *flag);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#include "lib.h"
|
#include "lib.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include <psyc/packet.h>
|
||||||
|
|
||||||
|
|
||||||
/// Routing variables in alphabetical order.
|
/// Routing variables in alphabetical order.
|
||||||
const PsycString psyc_routing_vars[] = {
|
const PsycString psyc_routing_vars[] = {
|
||||||
|
@ -44,8 +46,22 @@ const PsycDictInt psyc_var_types[] = {
|
||||||
{PSYC_C2STRI("_uniform"), PSYC_TYPE_UNIFORM},
|
{PSYC_C2STRI("_uniform"), PSYC_TYPE_UNIFORM},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const PsycDictInt psyc_method_families[] = {
|
||||||
|
{PSYC_C2STRI("_data"), PSYC_METHOD_DATA},
|
||||||
|
{PSYC_C2STRI("_echo"), PSYC_METHOD_ECHO},
|
||||||
|
{PSYC_C2STRI("_failure"), PSYC_METHOD_FAILURE},
|
||||||
|
{PSYC_C2STRI("_info"), PSYC_METHOD_INFO},
|
||||||
|
{PSYC_C2STRI("_message"), PSYC_METHOD_MESSAGE},
|
||||||
|
{PSYC_C2STRI("_message_echo"), PSYC_METHOD_MESSAGE_ECHO},
|
||||||
|
{PSYC_C2STRI("_notice"), PSYC_METHOD_NOTICE},
|
||||||
|
{PSYC_C2STRI("_request"), PSYC_METHOD_REQUEST},
|
||||||
|
{PSYC_C2STRI("_status"), PSYC_METHOD_STATUS},
|
||||||
|
{PSYC_C2STRI("_warning"), PSYC_METHOD_WARNING},
|
||||||
|
};
|
||||||
|
|
||||||
const size_t psyc_routing_vars_num = PSYC_NUM_ELEM(psyc_routing_vars);
|
const size_t psyc_routing_vars_num = PSYC_NUM_ELEM(psyc_routing_vars);
|
||||||
const size_t psyc_var_types_num = PSYC_NUM_ELEM(psyc_var_types);
|
const size_t psyc_var_types_num = PSYC_NUM_ELEM(psyc_var_types);
|
||||||
|
const size_t psyc_method_families_num = PSYC_NUM_ELEM(psyc_method_families);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the type of variable name.
|
* Get the type of variable name.
|
||||||
|
@ -97,3 +113,60 @@ psyc_var_type (const char *name, size_t len)
|
||||||
psyc_var_types_num, name, len, PSYC_YES,
|
psyc_var_types_num, name, len, PSYC_YES,
|
||||||
(int8_t *) &m);
|
(int8_t *) &m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the family and flags for a method.
|
||||||
|
*/
|
||||||
|
PsycMethod
|
||||||
|
psyc_method_family (char *method, size_t methodlen, unsigned int *flag)
|
||||||
|
{
|
||||||
|
int8_t tmp[PSYC_NUM_ELEM(psyc_method_families)];
|
||||||
|
int mc = psyc_dict_lookup_int(psyc_method_families, psyc_method_families_num,
|
||||||
|
method, methodlen, PSYC_YES, tmp);
|
||||||
|
|
||||||
|
if (!flag)
|
||||||
|
return mc;
|
||||||
|
|
||||||
|
switch (mc) {
|
||||||
|
case PSYC_METHOD_DATA:
|
||||||
|
break;
|
||||||
|
case PSYC_METHOD_ECHO:
|
||||||
|
*flag = PSYC_MESSAGE_TEMPLATE | PSYC_MESSAGE_REPLY | PSYC_MESSAGE_VISIBLE;
|
||||||
|
break;
|
||||||
|
case PSYC_METHOD_ERROR:
|
||||||
|
*flag = PSYC_MESSAGE_TEMPLATE | PSYC_MESSAGE_REPLY | PSYC_MESSAGE_VISIBLE
|
||||||
|
| PSYC_MESSAGE_LOGGABLE;
|
||||||
|
break;
|
||||||
|
case PSYC_METHOD_FAILURE:
|
||||||
|
*flag = PSYC_MESSAGE_TEMPLATE | PSYC_MESSAGE_REPLY | PSYC_MESSAGE_VISIBLE
|
||||||
|
| PSYC_MESSAGE_LOGGABLE;
|
||||||
|
break;
|
||||||
|
case PSYC_METHOD_INFO:
|
||||||
|
*flag = PSYC_MESSAGE_TEMPLATE | PSYC_MESSAGE_REPLY | PSYC_MESSAGE_VISIBLE
|
||||||
|
| PSYC_MESSAGE_LOGGABLE;
|
||||||
|
break;
|
||||||
|
case PSYC_METHOD_MESSAGE:
|
||||||
|
*flag = PSYC_MESSAGE_VISIBLE | PSYC_MESSAGE_LOGGABLE | PSYC_MESSAGE_MANUAL;
|
||||||
|
break;
|
||||||
|
case PSYC_METHOD_MESSAGE_ECHO:
|
||||||
|
*flag = PSYC_MESSAGE_REPLY | PSYC_MESSAGE_VISIBLE | PSYC_MESSAGE_LOGGABLE
|
||||||
|
| PSYC_MESSAGE_MANUAL;
|
||||||
|
break;
|
||||||
|
case PSYC_METHOD_NOTICE:
|
||||||
|
*flag = PSYC_MESSAGE_TEMPLATE | PSYC_MESSAGE_VISIBLE | PSYC_MESSAGE_LOGGABLE;
|
||||||
|
break;
|
||||||
|
case PSYC_METHOD_REQUEST:
|
||||||
|
*flag = PSYC_MESSAGE_TEMPLATE | PSYC_MESSAGE_VISIBLE | PSYC_MESSAGE_LOGGABLE;
|
||||||
|
break;
|
||||||
|
case PSYC_METHOD_STATUS:
|
||||||
|
*flag = PSYC_MESSAGE_TEMPLATE | PSYC_MESSAGE_REPLY | PSYC_MESSAGE_VISIBLE
|
||||||
|
| PSYC_MESSAGE_LOGGABLE;
|
||||||
|
break;
|
||||||
|
case PSYC_METHOD_WARNING:
|
||||||
|
*flag = PSYC_MESSAGE_TEMPLATE | PSYC_MESSAGE_REPLY | PSYC_MESSAGE_VISIBLE
|
||||||
|
| PSYC_MESSAGE_LOGGABLE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return mc;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue