Giter Site home page Giter Site logo

phyunsj / oncrpc-api-design Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 68 KB

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

Home Page: https://phyunsj.github.io

Makefile 0.84% C 78.36% RPC 4.46% Python 16.34%
oncrpc python rpc c pycparser ast astvisitor sunrpc

oncrpc-api-design's Introduction

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)

oncrpc-api-design's People

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.