d187700ab06bcee8f089ca2e64fe71e21ac05554
[platform/upstream/csf-framework.git] / framework / IpcServer.h
1 /*
2     Copyright (c) 2014, McAfee, Inc.
3     
4     All rights reserved.
5     
6     Redistribution and use in source and binary forms, with or without modification,
7     are permitted provided that the following conditions are met:
8     
9     Redistributions of source code must retain the above copyright notice, this list
10     of conditions and the following disclaimer.
11     
12     Redistributions in binary form must reproduce the above copyright notice, this
13     list of conditions and the following disclaimer in the documentation and/or other
14     materials provided with the distribution.
15     
16     Neither the name of McAfee, Inc. nor the names of its contributors may be used
17     to endorse or promote products derived from this software without specific prior
18     written permission.
19     
20     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21     ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22     WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23     IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
24     INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25     BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27     LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
28     OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29     OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #ifndef IPCSERVER_H
33 #define IPCSERVER_H
34
35 #ifdef __cplusplus 
36 extern "C" {
37 #endif
38
39 /**
40  * \file IpcServer.h
41  * \brief Ipc Server Header File
42  *  
43  * This file provides the IPC Server API functions used by Security framework.
44  */
45
46 #include <dbus/dbus.h>
47 #include <stdbool.h>
48 #include "IpcMacros.h"
49
50
51 /*==================================================================================================
52                                  STRUCTURES AND OTHER TYPEDEFS
53 ==================================================================================================*/
54
55 /**
56  * Pointer to method requested by client module.
57  */
58 /*typedef int (*CALLBACKFUNC) (void *pHandle, TSC_METHOD_REASON_CODE iReason, void *user_data);*/
59 typedef int (*CALLBACKFUNC) (void *pHandle, int iReason, void *reason_params);
60
61 typedef int (*METHODFUNC) (void *pData, int argc, char **argv, char ***szReply, int *len, CALLBACKFUNC callback, void *pHandle);
62
63 /**
64  * Server side method to handle request from client module. All the requests 
65  * are managed in a list.
66  */
67 typedef struct _IpcServerMethod
68 {
69     char       szMethod[TSC_METHOD_NAME_LEN];
70     METHODFUNC method;
71     void       *pData; //when execute the method, the pData besides the data passed from client, also has methodHandle for this method
72 } IpcServerMethod;
73
74 #define TSC_NULL ((void *) 0)
75
76 #define TSCSERVERHANDLE(n) struct n##_struct {int iDummy;}; typedef struct n##_struct *n
77 TSCSERVERHANDLE(TSC_SERVER_HANDLE);
78
79 #define TSCMETHODHANDLE(n) struct n##_struct {int iDummy;}; typedef struct n##_struct *n
80 TSCMETHODHANDLE(TSC_METHOD_HANDLE);
81
82 #define INVALID_TSC_METHOD_HANDLE ((TSC_METHOD_HANDLE) TSC_NULL)
83
84 #define INVALID_TSC_SERVER_HANDLE ((TSC_SERVER_HANDLE) TSC_NULL)
85
86 /*==================================================================================================
87                                      FUNCTION PROTOTYPES
88 ==================================================================================================*/
89
90 /**
91  * \brief Adds a handler method to the list of methods at server, to process 
92  * request from the client.
93  *
94  * During initialisation, the server builds a list of handlers to process
95  * request coming from client-side IPC. Later the client side IPC sends request
96  * along with the name of the handler to use. The handlers are implemented
97  * in the module hosting the server-side IPC.
98  *
99  * This is a synchronous API.
100  *
101  * \param[in] pMethod Details of the handler method to be added at server-side.
102  *
103  * \return Return Type (void) \n
104  *
105  */
106 int IpcServerAddMethod(TSC_SERVER_HANDLE hServer, IpcServerMethod *pMethod);
107
108 /**
109  * \brief Removes a handler method from the list of methods at server.
110  *
111  * During initialisation, the server builds a list of handlers to process
112  * request coming from client-side IPC. Later the client side IPC sends request
113  * along with the name of the handler to use. The handlers are implemented
114  * in the module hosting the server-side IPC. As part of un-initialisation
115  * the handler should be removed from the list.
116  *
117  * This is a synchronous API.
118  *
119  * \param[in] pMethod Pointer to handler method to be removed.
120  *
121  * \return Return Type (void) \n
122  *
123  */
124 int IpcServerRemoveMethod(TSC_SERVER_HANDLE hServer, METHODFUNC pMethod);
125
126
127 /*
128 void IpcCancelMethod(TSC_SERVER_HANDLE hServer, char *method_unique_id);
129 char *IpcGetProgressMethod(TSC_SERVER_HANDLE hServer, char *method_unique_id);
130 */
131 /**
132  * \brief Initialises the server-side IPC to make it ready for request from
133  * client side IPC.
134  *
135  * The IPC has two parts - client and server. The server-side IPC processes the
136  * request sent from the client-side IPC. The server-side uses handlers provided
137  * by the hosting module. When server comes up, the IPC needs to be initialised
138  * and be ready for the requests.
139  *
140  * This is a synchronous API.
141  *
142  * \return Return Type (int) \n
143  * 0 - on send success. \n
144  * -1 - on send failure. \n
145  */
146 TSC_SERVER_HANDLE IpcServerOpen(char *servie_name);
147
148 /**
149  * \brief Close the server-side IPC and release the resources.
150  *
151  * This is a synchronous API.
152  *
153  * \return Return Type (void) \n
154  */
155 void IpcServerClose(TSC_SERVER_HANDLE*);
156
157 int IpcServerMainLoop(TSC_SERVER_HANDLE hServer);
158
159 /**
160  * Callback function for Server Stub in cancel the method, update method progress
161  */
162
163
164
165 #ifdef __cplusplus
166 }
167 #endif 
168
169 #endif  /* IPCSERVER_H */
170