librpc
Macros | Typedefs | Enumerations | Functions
typing.h File Reference
#include <rpc/object.h>
Include dependency graph for typing.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define RPCT_TYPING_INTERFACE   "com.twoporeguys.librpc.Typing"
 
#define RPCT_TYPE_FIELD   "%type"
 
#define RPCT_VALUE_FIELD   "%value"
 
#define RPCT_TYPE_APPLIER(_fn, _arg)
 
#define RPCT_INTERFACE_APPLIER(_fn, _arg)
 
#define RPCT_MEMBER_APPLIER(_fn, _arg)
 
#define RPCT_IF_MEMBER_APPLIER(_fn, _arg)
 

Typedefs

typedef struct rpct_type * rpct_type_t
 
typedef struct rpct_typei * rpct_typei_t
 
typedef struct rpct_member * rpct_member_t
 
typedef struct rpct_interface * rpct_interface_t
 
typedef struct rpct_argument * rpct_argument_t
 
typedef struct rpct_if_member * rpct_if_member_t
 
typedef bool(^ rpct_type_applier_t) (rpct_type_t)
 
typedef bool(^ rpct_member_applier_t) (rpct_member_t)
 
typedef bool(^ rpct_interface_applier_t) (rpct_interface_t)
 
typedef bool(^ rpct_if_member_applier_t) (rpct_if_member_t)
 

Enumerations

enum  rpct_class_t {
  RPC_TYPING_STRUCT, RPC_TYPING_UNION, RPC_TYPING_ENUM, RPC_TYPING_TYPEDEF,
  RPC_TYPING_CONTAINER, RPC_TYPING_BUILTIN
}
 

Functions

int rpct_init (bool load_system_types)
 
void rpct_free (void)
 
int rpct_read_file (const char *path)
 
int rpct_read_idl (const char *name, rpc_object_t idl)
 
int rpct_load_types (const char *path)
 
int rpct_load_types_dir (const char *path)
 
int rpct_load_types_stream (int fd)
 
int rpct_load_types_cached (void)
 
const char * rpct_type_get_name (rpct_type_t type)
 
const char * rpct_type_get_origin (rpct_type_t iface)
 
const char * rpct_type_get_module (rpct_type_t type)
 
const char * rpct_type_get_description (rpct_type_t type)
 
rpct_type_t rpct_type_get_parent (rpct_type_t type)
 
rpct_class_t rpct_type_get_class (rpct_type_t type)
 
rpct_typei_t rpct_type_get_definition (rpct_type_t type)
 
int rpct_type_get_generic_vars_count (rpct_type_t type)
 
const char * rpct_type_get_generic_var (rpct_type_t type, int index)
 
rpct_member_t rpct_type_get_member (rpct_type_t type, const char *name)
 
rpct_typei_t rpct_typei_retain (rpct_typei_t typei)
 
void rpct_typei_release (rpct_typei_t typei)
 
bool rpct_typei_get_proxy (rpct_typei_t typei)
 
const char * rpct_typei_get_proxy_variable (rpct_typei_t typei)
 
rpct_type_t rpct_typei_get_type (rpct_typei_t typei)
 
rpct_typei_t rpct_typei_get_generic_var (rpct_typei_t typei, const char *name)
 
const char * rpct_typei_get_canonical_form (rpct_typei_t typei)
 
rpct_typei_t rpct_typei_get_member_type (rpct_typei_t typei, rpct_member_t member)
 
bool rpct_typei_is_compatible (rpct_typei_t decl, rpct_typei_t type)
 
const char * rpct_member_get_name (rpct_member_t member)
 
const char * rpct_member_get_description (rpct_member_t member)
 
rpct_typei_t rpct_member_get_typei (rpct_member_t member)
 
const char * rpct_interface_get_name (rpct_interface_t iface)
 
const char * rpct_interface_get_origin (rpct_interface_t iface)
 
const char * rpct_interface_get_description (rpct_interface_t iface)
 
enum rpc_if_member_type rpct_if_member_get_type (rpct_if_member_t member)
 
const char * rpct_if_member_get_name (rpct_if_member_t member)
 
const char * rpct_if_member_get_description (rpct_if_member_t member)
 
rpct_typei_t rpct_method_get_return_type (rpct_if_member_t method)
 
int rpct_method_get_arguments_count (rpct_if_member_t method)
 
rpct_argument_t rpct_method_get_argument (rpct_if_member_t method, int index)
 
rpct_typei_t rpct_property_get_type (rpct_if_member_t prop)
 
const char * rpct_argument_get_name (rpct_argument_t arg)
 
const char * rpct_argument_get_description (rpct_argument_t arg)
 
rpct_typei_t rpct_argument_get_typei (rpct_argument_t arg)
 
bool rpct_types_apply (rpct_type_applier_t applier)
 
bool rpct_members_apply (rpct_type_t type, rpct_member_applier_t applier)
 
bool rpct_interface_apply (rpct_interface_applier_t applier)
 
bool rpct_if_member_apply (rpct_interface_t iface, rpct_if_member_applier_t applier)
 
rpct_interface_t rpct_find_interface (const char *name)
 
rpct_if_member_t rpct_find_if_member (const char *interface, const char *member)
 
rpct_typei_t rpct_new_typei (const char *decl)
 
rpc_object_t rpct_new (const char *decl, rpc_object_t object)
 
rpc_object_t rpct_newi (rpct_typei_t typei, rpc_object_t object)
 
rpc_object_t rpct_set_typei (rpct_typei_t typei, rpc_object_t object)
 
rpct_type_t rpct_get_type (const char *name)
 
rpct_typei_t rpct_get_typei (rpc_object_t instance)
 
rpc_object_t rpct_get_value (rpc_object_t instance)
 
void rpct_set_value (rpc_object_t object, const char *value)
 
rpc_object_t rpct_serialize (rpc_object_t object)
 
rpc_object_t rpct_deserialize (rpc_object_t object)
 
bool rpct_validate_args (struct rpct_if_member *func, rpc_object_t args, rpc_object_t *errors)
 
bool rpct_validate_return (struct rpct_if_member *func, rpc_object_t result, rpc_object_t *errors)
 
bool rpct_validate (rpct_typei_t typei, rpc_object_t obj, rpc_object_t *errors)
 
rpc_object_t rpct_pre_call_hook (void *cookie, rpc_object_t args)
 
rpc_object_t rpct_post_call_hook (void *cookie, rpc_object_t args)
 
void rpct_allow_idl_download (rpc_context_t context)
 
int rpct_download_idl (rpc_connection_t conn)
 

Macro Definition Documentation

◆ RPCT_IF_MEMBER_APPLIER

#define RPCT_IF_MEMBER_APPLIER (   _fn,
  _arg 
)
Value:
^(rpct_if_member_t _if_member) { \
return ((bool)_fn(_arg, _if_member)); \
}
struct rpct_if_member * rpct_if_member_t
Definition: typing.h:110

Definition at line 159 of file typing.h.

◆ RPCT_INTERFACE_APPLIER

#define RPCT_INTERFACE_APPLIER (   _fn,
  _arg 
)
Value:
^(rpct_interface_t _iface) { \
return ((bool)_fn(_arg, _iface)); \
}
struct rpct_interface * rpct_interface_t
Definition: typing.h:100

Definition at line 149 of file typing.h.

◆ RPCT_MEMBER_APPLIER

#define RPCT_MEMBER_APPLIER (   _fn,
  _arg 
)
Value:
^(rpct_member_t _member) { \
return ((bool)_fn(_arg, _member)); \
}
struct rpct_member * rpct_member_t
Definition: typing.h:95

Definition at line 154 of file typing.h.

◆ RPCT_TYPE_APPLIER

#define RPCT_TYPE_APPLIER (   _fn,
  _arg 
)
Value:
^(rpct_type_t _type) { \
return ((bool)_fn(_arg, _type)); \
}
struct rpct_type * rpct_type_t
Definition: typing.h:65

Definition at line 144 of file typing.h.

Typedef Documentation

◆ rpct_argument_t

typedef struct rpct_argument* rpct_argument_t

Represents a function argument.

Definition at line 105 of file typing.h.

◆ rpct_if_member_applier_t

typedef bool(^ rpct_if_member_applier_t) (rpct_if_member_t)

Block type used as a callback in rpct_if_member_apply.

Definition at line 142 of file typing.h.

◆ rpct_if_member_t

typedef struct rpct_if_member* rpct_if_member_t

Represents an interface member (method, property or event).

Definition at line 110 of file typing.h.

◆ rpct_interface_applier_t

typedef bool(^ rpct_interface_applier_t) (rpct_interface_t)

Block type used as a callback in rpct_interface_apply.

Definition at line 137 of file typing.h.

◆ rpct_interface_t

typedef struct rpct_interface* rpct_interface_t

Represents an interface.

Definition at line 100 of file typing.h.

◆ rpct_member_applier_t

typedef bool(^ rpct_member_applier_t) (rpct_member_t)

Block type used as a callback in rpct_members_apply.

Definition at line 132 of file typing.h.

◆ rpct_member_t

typedef struct rpct_member* rpct_member_t

Represents a structure member or a union branch.

Definition at line 95 of file typing.h.

◆ rpct_type_applier_t

typedef bool(^ rpct_type_applier_t) (rpct_type_t)

Block type used as a callback in rpct_types_apply.

Definition at line 127 of file typing.h.

◆ rpct_type_t

typedef struct rpct_type* rpct_type_t

Represents a type, as defined in the interface definition file.

rpct_type_t represents a defined type, that is - an unspecialized type. Unspecialized means that if a type has any generic variables (eg. Type<A, B>), A and B are type placeholders.

Examples of unspecialized types:

  • string
  • NonGenericStructOne
  • GenericStructTwo<T>
  • GenericTypedef<V>
  • HashMap<K, V>

Definition at line 65 of file typing.h.

◆ rpct_typei_t

typedef struct rpct_typei* rpct_typei_t

Represents a specialized type.

rpct_typei_t represents a specialized type, that is - a possibly generic type with its generic variables specialized with actual types.

One special case here is a partially specialized type. A partially specialized type may be present as a structure member, union branch or typedef body. "partially" means that some of the type variables might be specialized, but some others might not.

Examples of specialized types:

  • string
  • NonGenericStructOne
  • GenericStructTwo<int64>
  • GenericTypedef<string>
  • HashMap<string, double>

Examples of partially specialized types:

  • GenericStructTwo<T>
  • HashMap<K, V>
  • HashMap<K, double>

Definition at line 90 of file typing.h.

Enumeration Type Documentation

◆ rpct_class_t

A type class.

Enumerator
RPC_TYPING_STRUCT 

A structure

RPC_TYPING_UNION 

A union

RPC_TYPING_ENUM 

An enum

RPC_TYPING_TYPEDEF 

A type alias

RPC_TYPING_CONTAINER 

A container type

RPC_TYPING_BUILTIN 

A builtin type

Definition at line 115 of file typing.h.

Function Documentation

◆ rpct_allow_idl_download()

void rpct_allow_idl_download ( rpc_context_t  context)

XXX

Parameters
context
Examples:
validation.c.

◆ rpct_argument_get_description()

const char* rpct_argument_get_description ( rpct_argument_t  arg)

Returns description string associated with the argument.

Parameters
argArgument handle
Returns
Description string or NULL

◆ rpct_argument_get_name()

const char* rpct_argument_get_name ( rpct_argument_t  arg)

Returns name associated with the argument.

Parameters
argArgument handle
Returns
Argument name

◆ rpct_argument_get_typei()

rpct_typei_t rpct_argument_get_typei ( rpct_argument_t  arg)

Returns type instance of the argument.

Parameters
argArgument handle
Returns
Type instance handle

◆ rpct_deserialize()

rpc_object_t rpct_deserialize ( rpc_object_t  object)

Deserializes object hierarchy previously serialized with rpct_serialize()

Parameters
object
Returns

◆ rpct_download_idl()

int rpct_download_idl ( rpc_connection_t  conn)

XXX

Parameters
connConnection handle
Returns
0 on success, -1 on error

◆ rpct_find_if_member()

rpct_if_member_t rpct_find_if_member ( const char *  interface,
const char *  member 
)

Finds the member member of interface interface.

Parameters
interfaceInterface name
memberMember name
Returns
Interface member handle

◆ rpct_find_interface()

rpct_interface_t rpct_find_interface ( const char *  name)

Finds interface name.

Parameters
nameInterface name
Returns
Interface handle

◆ rpct_free()

void rpct_free ( void  )

Cleans up all the state associated with RPC type system.

◆ rpct_get_type()

rpct_type_t rpct_get_type ( const char *  name)

Looks up type by name.

Parameters
nameType name
Returns
Type handle or NULL if not found

◆ rpct_get_typei()

rpct_typei_t rpct_get_typei ( rpc_object_t  instance)

Returns type instance handle associated with an object.

Parameters
instanceRPC object instance
Returns
Type instance handle or NULL

◆ rpct_get_value()

rpc_object_t rpct_get_value ( rpc_object_t  instance)
Parameters
instance
Returns

◆ rpct_if_member_apply()

bool rpct_if_member_apply ( rpct_interface_t  iface,
rpct_if_member_applier_t  applier 
)

Iterates over members of an interface.

Parameters
applierCallback function
Returns
true if iteration was terminated, otherwise false

◆ rpct_if_member_get_description()

const char* rpct_if_member_get_description ( rpct_if_member_t  member)

Returns the interface member description.

Parameters
memberInterface member handle
Returns
Interface member description or NULL

◆ rpct_if_member_get_name()

const char* rpct_if_member_get_name ( rpct_if_member_t  member)

Returns the interface member name.

Parameters
memberInterface member handle
Returns
Interface member name

◆ rpct_if_member_get_type()

enum rpc_if_member_type rpct_if_member_get_type ( rpct_if_member_t  member)

Returns the interface member type.

Parameters
memberInterface member handle
Returns
Interface member type

◆ rpct_init()

int rpct_init ( bool  load_system_types)

Initializes RPC type system

Returns
0 on success, -1 on error
Examples:
pack-unpack.c, and validation.c.

◆ rpct_interface_apply()

bool rpct_interface_apply ( rpct_interface_applier_t  applier)

Iterates over the defined functions.

Parameters
applier
Returns
true if iteration was terminated, otherwise false

◆ rpct_interface_get_description()

const char* rpct_interface_get_description ( rpct_interface_t  iface)

Returns the interface description.

Parameters
ifaceInterface handle
Returns
Interface description or NULL

◆ rpct_interface_get_name()

const char* rpct_interface_get_name ( rpct_interface_t  iface)

Returns the interface name.

Parameters
ifaceInterface handle
Returns

◆ rpct_interface_get_origin()

const char* rpct_interface_get_origin ( rpct_interface_t  iface)

Returns the place where interface was defined.

Returned string is in form file.yaml:line_number

Parameters
ifaceInterface handle
Returns
Origin string

◆ rpct_load_types()

int rpct_load_types ( const char *  path)

Loads type information from an interface definition file.

Parameters
pathPath of the IDL file
Returns
0 on success, -1 on error
Examples:
validation.c.

◆ rpct_load_types_cached()

int rpct_load_types_cached ( void  )

Loads type information from files previously loaded by rpct_read_idl.

Returns
0 on success, -1 on error

◆ rpct_load_types_dir()

int rpct_load_types_dir ( const char *  path)
Parameters
path
Returns

◆ rpct_load_types_stream()

int rpct_load_types_stream ( int  fd)

Loads type information from an interface definition stream.

File descriptor is closed once all definitions have been read from it or error happened.

Parameters
fdIDL stream file descriptor
Returns
0 on success, -1 on error

◆ rpct_member_get_description()

const char* rpct_member_get_description ( rpct_member_t  member)

Returns the description of a member.

Parameters
memberMember handle
Returns
Description text or NULL.

◆ rpct_member_get_name()

const char* rpct_member_get_name ( rpct_member_t  member)

Returns the name of a member.

Parameters
memberMember handle
Returns
Member name

◆ rpct_member_get_typei()

rpct_typei_t rpct_member_get_typei ( rpct_member_t  member)

Returns the type of a member.

This functions returns NULL for enum members, because they're untyped.

Parameters
memberMember handle
Returns
Type instance handle representing member type or NULL

◆ rpct_members_apply()

bool rpct_members_apply ( rpct_type_t  type,
rpct_member_applier_t  applier 
)

Iterates over the members of a given type.

Parameters
type
applier
Returns
true if iteration was terminated, otherwise false

◆ rpct_method_get_argument()

rpct_argument_t rpct_method_get_argument ( rpct_if_member_t  method,
int  index 
)

Returns argument handle for n-th argument of a function.

Parameters
funcFunction handle
indexArgument index
Returns
Argument handle or NULL if index is out of bounds

◆ rpct_method_get_arguments_count()

int rpct_method_get_arguments_count ( rpct_if_member_t  method)

Returns number of arguments a function takes.

Parameters
methodMethod handle
Returns
Number of arguments

◆ rpct_method_get_return_type()

rpct_typei_t rpct_method_get_return_type ( rpct_if_member_t  method)

Returns the type instance handle representing return type of a function.

Parameters
methodMethod handle
Returns
Return type instance handle

◆ rpct_new()

rpc_object_t rpct_new ( const char *  decl,
rpc_object_t  object 
)

Creates a new object of the specified type.

Parameters
declType declaration
objectContents
Returns
Typed object

◆ rpct_new_typei()

rpct_typei_t rpct_new_typei ( const char *  decl)

Creates a new type instance from provided declaration.

Parameters
declType declaration
Returns
Type instance handle or NULL in case of error

◆ rpct_newi()

rpc_object_t rpct_newi ( rpct_typei_t  typei,
rpc_object_t  object 
)

Creates a new object of the specified type.

Parameters
typeiType instance handle
objectContents
Returns
Typed object

◆ rpct_post_call_hook()

rpc_object_t rpct_post_call_hook ( void *  cookie,
rpc_object_t  args 
)
Parameters
cookie
args
Returns
Examples:
validation.c.

◆ rpct_pre_call_hook()

rpc_object_t rpct_pre_call_hook ( void *  cookie,
rpc_object_t  args 
)
Parameters
cookie
args
Returns
Examples:
validation.c.

◆ rpct_property_get_type()

rpct_typei_t rpct_property_get_type ( rpct_if_member_t  prop)

Returns type instance of the property.

Parameters
propProperty handle
Returns
Type instance handle of the property

◆ rpct_read_file()

int rpct_read_file ( const char *  path)

Reads IDL file without parsing it. rpct_load_types must be called on the same path again to load the associated types.

Parameters
pathPath to the IDL file
Returns
0 on success, -1 on error

◆ rpct_read_idl()

int rpct_read_idl ( const char *  name,
rpc_object_t  idl 
)

Reads IDL object without parsing it. rpct_load_types must be called on the same name again to load the associated types.

Parameters
nameName of the IDL blob
idlIDL blob contents
Returns
0 on success, -1 on error

◆ rpct_serialize()

rpc_object_t rpct_serialize ( rpc_object_t  object)

Serializes object hierarchy preserving type information.

Parameters
objectObject to serialize
Returns
Object with encoded type information

◆ rpct_set_typei()

rpc_object_t rpct_set_typei ( rpct_typei_t  typei,
rpc_object_t  object 
)

Binds specified type to an existing object.

Parameters
typeiType instance handle
objectObject to be typed
Returns
Typed object

◆ rpct_set_value()

void rpct_set_value ( rpc_object_t  object,
const char *  value 
)
Parameters
object
value

◆ rpct_type_get_class()

rpct_class_t rpct_type_get_class ( rpct_type_t  type)

Returns the type class.

Parameters
typeType handle
Returns
Type class

◆ rpct_type_get_definition()

rpct_typei_t rpct_type_get_definition ( rpct_type_t  type)

Returns the type definition (underlying type).

This function returns the underlying type definition of a typedef. Returns NULL for other type classes.

Parameters
typeType handle
Returns
Type definition handle or NULL.

◆ rpct_type_get_description()

const char* rpct_type_get_description ( rpct_type_t  type)

Returns the type description, as read from interface definition file.

Parameters
typeType handle
Returns
Description string (or empty string if not defined)

◆ rpct_type_get_generic_var()

const char* rpct_type_get_generic_var ( rpct_type_t  type,
int  index 
)

Returns name of n-th generic variable.

Returns NULL if index is out of the bounds.

Parameters
typeType handle
indexGeneric variable index
Returns
Generic variable name

◆ rpct_type_get_generic_vars_count()

int rpct_type_get_generic_vars_count ( rpct_type_t  type)

Returns a number of generic variables a type defines.

Parameters
typeType handle
Returns
Number of generic variables (0 for non-generic types)

◆ rpct_type_get_member()

rpct_member_t rpct_type_get_member ( rpct_type_t  type,
const char *  name 
)

Looks up type member by name.

Parameters
typeType handle
nameMember name
Returns
Member handle or NULL if not found

◆ rpct_type_get_module()

const char* rpct_type_get_module ( rpct_type_t  type)

Returns the module name type belongs to.

Parameters
typeType handle
Returns
Module name

◆ rpct_type_get_name()

const char* rpct_type_get_name ( rpct_type_t  type)

Returns the type name.

Parameters
typeType handle
Returns
Type name

◆ rpct_type_get_origin()

const char* rpct_type_get_origin ( rpct_type_t  iface)

Returns the place where type was defined.

Returned string is in form file.yaml:line_number

Parameters
ifaceInterface handle
Returns
Origin string

◆ rpct_type_get_parent()

rpct_type_t rpct_type_get_parent ( rpct_type_t  type)

Returns the type "parent" in the inheritance chain.

Parameters
typeType handle
Returns
Base type or NULL

◆ rpct_typei_get_canonical_form()

const char* rpct_typei_get_canonical_form ( rpct_typei_t  typei)

Returns the type declaration string ("canonical form").

Parameters
typeiType instance handle
Returns
Canonical type declaration string

◆ rpct_typei_get_generic_var()

rpct_typei_t rpct_typei_get_generic_var ( rpct_typei_t  typei,
const char *  name 
)

Returns the type instance passed as a generic variable to the typei.

Parameters
typeiType instance handle
nameGeneric variable name
Returns
Type instance handle or NULL

◆ rpct_typei_get_member_type()

rpct_typei_t rpct_typei_get_member_type ( rpct_typei_t  typei,
rpct_member_t  member 
)

Returns type instance handler of a structure or union member.

Parameters
typeiType instance handle
memberMember handle
Returns
Type instance handle or NULL in case of error

◆ rpct_typei_get_proxy()

bool rpct_typei_get_proxy ( rpct_typei_t  typei)
Parameters
typei
Returns

◆ rpct_typei_get_proxy_variable()

const char* rpct_typei_get_proxy_variable ( rpct_typei_t  typei)
Parameters
typei
Returns

◆ rpct_typei_get_type()

rpct_type_t rpct_typei_get_type ( rpct_typei_t  typei)

Returns base type of a type instance typei.

Parameters
typeiType instance handle
Returns
Type handle

◆ rpct_typei_is_compatible()

bool rpct_typei_is_compatible ( rpct_typei_t  decl,
rpct_typei_t  type 
)

Returns true if decl and type are compatible types.

Parameters
declFirst type
typeSecond type
Returns
true if compatible, otherwise false

◆ rpct_typei_release()

void rpct_typei_release ( rpct_typei_t  typei)

Decrements reference count of a type instance handle.

If the reference count reaches 0, type instance handle is freed.

Parameters
typeiType instance handle

◆ rpct_typei_retain()

rpct_typei_t rpct_typei_retain ( rpct_typei_t  typei)

Increments reference count of a type instance handle.

Parameters
typeiType instance handle
Returns
Same as the passed argument

◆ rpct_types_apply()

bool rpct_types_apply ( rpct_type_applier_t  applier)

Iterates over the defined types.

Parameters
applier
Returns
true if iteration was terminated, otherwise false

◆ rpct_validate()

bool rpct_validate ( rpct_typei_t  typei,
rpc_object_t  obj,
rpc_object_t errors 
)

Validates object against given type instance.

Parameters
typei
obj
errors
Returns

◆ rpct_validate_args()

bool rpct_validate_args ( struct rpct_if_member *  func,
rpc_object_t  args,
rpc_object_t errors 
)

Validates set of arguments for a given function.

Parameters
func
args
errors
Returns

◆ rpct_validate_return()

bool rpct_validate_return ( struct rpct_if_member *  func,
rpc_object_t  result,
rpc_object_t errors 
)

Validates a return value from a given function.

Parameters
func
result
errors
Returns