OpenHiva::Node::CreateServer

Table 1 Description of OpenHiva::Node::CreateServer

Prototype

template <typename ReqType, typename ResType> std::shared_ptr<OpenHiva::ServiceServer> CreateServer(const std::string &serviceName, const OpenHiva::ServiceOptions &serviceOptions, const std::function<bool(ReqType, ResType)> &serviceCallback)

Description

Creates a server for Service.

Parameter (IN)

serviceName

Service name.

serviceOptions

Service attribute configuration. For details, see OpenHiva::ServiceOptions.

serviceCallback

Callback function invoked by Server to process messages published by Client.

Parameter (OUT)

None

Return

std::shared_ptr<OpenHiva::ServiceServer>

The OpenHiva::ServiceServer object is returned. This object can be used to initialize the server and release resources.

Usage

None

Precautions

  • The service name must be globally unique.
  • For the same service, the serviceName and serviceOptions parameters on the client must be the same as those on the server.
  • Ensure that the input parameters are correct and used based on constraints. The callback function must check the length, which cannot exceed the threshold.
  • The name of the shared memory file that is created by concatenating serviceName with other character strings must comply with the file naming rule.
  • Only one thread is started on a server. The callback processing is serial, and the callback processing of different services is parallel.
  • If the processing speed of the server is too slow, the client may time out.
  • The server process and client process must have the same user permission because shared memory file read and write are involved.
  • The request message type described by ReqType must be a subclass of HivaMessage.
  • The response message type described by ResType must be a subclass of HivaMessage.