Tools: acrn-manager: add lib with IPC helpers

Add lib to help IPC between components, including SOS lifecycle service,
acrn manager and devicemodule.
Following helper functions are included:
  int mngr_open_un() - create a descripter for vm management IPC
  void mngr_close() - close descripter and release the resouces
  int mngr_add_handler() - add a handler for message specified by msg
  int mngr_send_msg() - send a message and wait for ack

Reviewed-by: Kaige Fu <kaige.fu@intel.com>
Reviewed-by: Geoffroy Van Cutsem <geoffroy.vancutsem@intel.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Reviewed-by: Wang, Yu <yu1.wang@intel.com>
Sigbed-off-by: Yan Like <like.yan@intel.com>
Signed-off-by: Tao Yuhong <yuhong.tao@intel.com>
This commit is contained in:
yuhong.tao@intel.com
2018-05-29 23:44:30 +08:00
committed by lijinxia
parent c001911e19
commit 7d7cf309eb
3 changed files with 750 additions and 1 deletions

View File

@@ -0,0 +1,78 @@
/*
* Copyright (C)2018 Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef ACRN_MANAGER_H
#define ACRN_MANAGER_H
#include <stdlib.h>
/* Basic message format */
#define MNGR_MSG_MAGIC 0x67736d206d6d76 /* that is char[8] "vmm msg", on X86 */
#define VMNAME_LEN 16
struct mngr_msg {
unsigned long long magic; /* Make sure you get a vmm_msg */
unsigned int msgid;
unsigned long timestamp;
size_t len; /* vmm_msg + payload size */
char payload[0];
};
/* vmm_msg event types */
enum msgid {
MSG_MIN = 0,
MSG_STR, /* The message payload is a string, terminated with '\0' */
MSG_MAX,
};
/* helper functions */
#define MNGR_SERVER 1 /* create a server fd, which you can add handlers onto it */
#define MNGR_CLIENT 0 /* create a client, just send req and read ack */
/**
* @brief create a descripter for vm management IPC
*
* @param name: refer to a sock file under /run/acrn/mngr/[name].[pid].socket
* @param flags: MNGR_SERVER to create a server, MNGR_CLIENT to create a client
*
* @return descripter ID (> 1024) on success, errno (< 0) on error.
*/
int mngr_open_un(const char *name, int flags);
/**
* @brief close descripter and release the resouces
*
* @param desc: descripter to be closed
*/
void mngr_close(int desc);
/**
* @brief add a handler for message specified by msg
*
* @param desc: descripter to register handler to
* @param id: id of message to handle
* @param cb: handler callback
* @param param: param for the callback
* @return 0 on success, errno on error
*/
int mngr_add_handler(int desc, unsigned id,
void (*cb) (struct mngr_msg * msg, int client_fd,
void *param), void *param);
/**
* @brief send a message and wait for ack
*
* @param desc: descripter created using mngr_open_un
* @param req: pointer to message to send
* @param ack: pointer to ack struct, NULL if no ack required
* @param len: size in byte of the message to send
* @param timeout: time to wait for ack, zero to blocking waiting
* @return len of ack messsage (0 if ack is NULL) on succes, errno on error
*/
int mngr_send_msg(int desc, struct mngr_msg *req, struct mngr_msg *ack,
size_t len, unsigned timeout);
#endif /* ACRN_MANAGER_H */