Giter Site home page Giter Site logo

msgpack-rpc-c's Introduction

MessagePack-RPC for C

C wrapper of MessagePack-RPC for C+

Motive

Call client methods of MessagePack-RPC for C++ from C application.

Requirements

Following programs are required to build:

And following build tool is required to build:

  • waf >= 1.6.11

Restrictions

This wrapper laid under some restrictions.

First, a prefix string of all methods name are mrc_.

Because we can't use the namespaces in C.

Therefore, messagepack::rpc::client->call() is called from mrc_call(). And messagepack::rpc::client->notify() is called from mrc_notify().

Second, types of all arguments of mrc_call() are limited to char*. And types of all arguments of mrc_notify() are limited to char* too.

Because type check of argument values is make complex the API of methods.

const char* mrc_call(mrclient* client, char* NAME_OF_METHOD, char* argv1, char* argv2, ....);
void mrc_notify(mrclient* client, char* NAME_OF_METHOD, char* argv1, char* argv2, ....);

If you want to use the type expect the char*, you should formatted value(JSON, YAML...) as first argument.

const char* mrc_call(mrclient* client, char* NAME_OF_METHOD, char* JSON_FORMAT_VALUE);

Finaly, the number of arguments of methods(call(), notify()) after NAME_OF_METHOD is limited to value from 0 to 16.

It is same as API of MessagePack-RPC for C++.

OK : mrc_call(mrclient* client, char* NAME_OF_METHOD);
OK : mrc_call(mrclient* client, char* NAME_OF_METHOD, char* argv1, ...,  char* argv16);
NG : mrc_call(mrclient* client, char* NAME_OF_METHOD, char* argv1, ...,  char* argv17);

When you call mrc_notify(), it's better to call mrc_flush_loop() after processing to call all mrc_notify() lines.

mrc_flush_loop() flush implicitly the notify requests which are buffered in msgpack::rpc::loop.

 mrc_notify(mrclient* client, char* NAME_OF_METHOD, ....);
 mrc_notify(mrclient* client, char* NAME_OF_METHOD, ....);
 ...
 mrc_notify(mrclient* client, char* NAME_OF_METHOD, ....);
 mrc_flush_loop(mrclient* client);

Before installation

You should install above shared libraries and waf(https://code.google.com/p/waf/).

If you use CentOS 6.x

Configure and install in this way:

$ ./sh/make_centos_env.sh

Installation

You should be able to build it on most systems with waf(https://code.google.com/p/waf/).

Configure and install in this way:

$ ./sh/compile.sh

Example

Client Sample code

msgpack-rpc-c/src/msgpack_rpc_client_clang.c is one of sample code.

#include "msgpack_rpc_client.h"
#include <stdio.h>

int main(void) {
  mrclient* client = mrc_create("127.0.0.1", 9090);
  const char *result = mrc_call(client, "distance", "STAR WARS");
  printf("%s\n", result);
  mrc_destroy(client);
  return 1;
}

Compile a client sample code

$ cd msgpack-rpc-c/src
$ gcc -c ./msgpack_rpc_client_clang.c
$ g++ -O3 -o c_test_client msgpack_rpc_client_clang.o -lmsgpack_rpc_client -lmsgpack-rpc -lmpio -lmsgpack

Execute a client sample code

In this case, you should run MessagePack RPC server on 127.0.0.1:9090.

$ LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib ./c_test_client

License

Copyright (C) 2014 Toshinori SATO <overlasting _attt_ gmail _dottt_ com>

Licensed under the Apache License, Version 2.0 (the "License");
You may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

See also NOTICE file.

msgpack-rpc-c's People

Contributors

overlast avatar

Stargazers

 avatar  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.