Skip to content
This repository has been archived by the owner on Nov 16, 2020. It is now read-only.
/ oncrpc-api-design Public archive

Generate ONCRPC middle-layer to simplify RPC application development (for my own reference)

Notifications You must be signed in to change notification settings

phyunsj/oncrpc-api-design

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ONC/RPC API Design

  • Example 1 rls (remote ls - original version)

  • Example 2 rls_v2 (revised)

  • Example 3 calc

Example 3 calc

ONCRPC restricted us to remote procedures that accept a single parameter and return a single parameter. (Might not be true now but stick to this restriction)

Instead of starting with IDL (like Example 1 & 2), start wtih API.h and generate ONCRPC middle-layer automatically. Keep (or share) the same local implementation between RPC server and RPC client.

Similar to non-RPC application, the below files are manaully created. Create RPC middle-layer to integrate the local APIs defined in cl_calc.h. Use the same API locally or remotely.

cl_calc.c/h : functions declaration, definition.

cl_client.c : client main program

cl_common.c/h : RPC Client handler

cl_return_t CL_CALC_WRITE ( HANDLER *remote , cl_msg_t in, cl_bus_t *out )  
{

  if ( remote != NULL && remote->clnt != (CLIENT *)NULL ) {

    ...    
    res = cl_calc_write_func_1( &req, remote->clnt );
    ...
    
    return ret;
  } else {

    return cl_calc_write( in,out );

  }

}

CL is an imaginary product name for example 3.

  1. cpp cl_calc.h -o cl_calc.i
  2. pycparser to generate AST
  3. AST visitor extracts typdef & *** fucntion declaration *** out of AST
  4. generate IDL & RPC middle-layer Interface

The following files are generated from cl_calc.h

  • CL.x (ONCRPC IDL)
  • CL_proc.c (Client Middlelayer)
  • CL_svc_proc.c (Server Middlelayer)
  • CL_proc.h

CL.x generates :

  • CL.h
  • CL_svc.c
  • CL_clnt.c
  • CL_xdr.c

Accessing AST

generated by pycparser ( Complete C99 parser in pure Python )

pycparser installation. ( powered by PLY )

pip install --index-url=https://pypi.python.org/simple/ pycparser

from pycparser import c_parser, c_ast, parse_file

class FuncCallVisitor(c_ast.NodeVisitor):
    def __init__(self):
        ...

    def visit_FuncDecl (self, node):
        ...

if __name__ == "__main__":

    ast = parse_file(args.filename, use_cpp=False)
    v = FuncCallVisitor()
    v.visit(ast)

About

Generate ONCRPC middle-layer to simplify RPC application development (for my own reference)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published