GithubHelp home page GithubHelp logo

sipcdemo's Introduction

SIpcDemo is a ipc demo using SIpcObject. this demo depends on soui. Soui is a direct UI library and can be found from https://github.com/soui2/soui.git.

SIpcObject is a IPC component. Related headers were placed in soui.src/soui/include/interface, where soui.src is the folder you had cloned soui repository. Actually, SIpcObject does not depend on SOUI, and you can extract it from soui without any trouble.

After you had finished constructing the IPC framework, using IpcObject, making a IPC call will be as simple as calling a normal function.

To make a IPC call, we need deine a struct which delieved from SOUI::IFunParams at first as demo.


struct FunParams_Base : SOUI::IFunParams
{
	virtual void ToStream4Input(SOUI::SParamStream &  ps) {}
	virtual void ToStream4Output(SOUI::SParamStream &  ps) {}
	virtual void FromStream4Input(SOUI::SParamStream &  ps) {}
	virtual void FromStream4Output(SOUI::SParamStream &  ps) {}
};

struct Param_AddInt : FunParams_Base
{
	int a, b;
	int ret;
	FUNID(CID_AddInt)
		PARAMS2(Input, a,b)
		PARAMS1(Output,ret)
};

Here, FunParams_Base is used to provide a empty implementation for all of interfaces of IFunParams, and Param_AddInt is the actual IPC call parameters object.

We defined a serial of macro to simplify implementing interfaces of IFunParams. FUNID is used to define the IPC call id.
PARAMx is used to implement serailize of parameters, where x can be from 1 to 5, and you can extend it to any number as you need. The first parameter must be "input" or "output". "input" means the parameter is input parameter and "output" means the parameter is used to save returns. A parameter can be both "input" and "output".

OK, you can call the IPC function from client by using IIpcHandle->CallFun(&Param_AddInt) now.

Now let us have a look of SOUI::IIpcConnection
struct IIpcConnection : IObjRef
	{
		virtual IIpcHandle * GetIpcHandle() = 0;
		virtual bool HandleFun(UINT uFunID, SParamStream & ps) = 0;
		virtual void BuildShareBufferName(ULONG_PTR idLocal, ULONG_PTR idRemote, TCHAR szBuf[MAX_PATH]) const = 0;
	};
  
To response for client call, at server endpoint, we implement virtual function HandleFun by using macro FUN_BEGIN and FUN_END as used in demo.

  void OnAddInt(Param_AddInt & param)
  {
  	param.ret = param.a + param.b;
  }
  
	FUN_BEGIN
		FUN_HANDLER(Param_AddInt, OnAddInt)
	FUN_END

It's all. Wish it be useful to you!

2019.2.26
  
  

sipcdemo's People

Contributors

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