Revert "Remove TPCS and TWPServer features"
[platform/upstream/csf-framework.git] / framework / IpcStructs.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 IPCSTRUCTS_H
33 #define IPCSTRUCTS_H
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38
39 /**
40  * \file IpcStructs.h
41  * \brief Header File for structures by Ipc.
42  *
43  * This file implements the structures needed by IPC Client, used by Security framework.
44  */
45
46 #include <dbus/dbus.h>
47 #include <pthread.h>
48
49 #include "IpcMacros.h"
50 #include "IpcTypes.h"
51
52 /*==================================================================================================
53                                  STRUCTURES AND OTHER TYPEDEFS
54 ==================================================================================================*/
55
56 /**
57  * Handle for message sent, to be used for future reference.
58  */
59 typedef struct _ClientCallHandle
60 {
61     char idUnique[MSGHANDLE_LEN];
62     DBusPendingCall *pPendingCall;
63     char service_name[TSC_SERVER_NAME_LEN + 1];
64 } ClientCallHandle;
65
66 /**
67  * IPC client connection info.
68  */
69 typedef struct _IpcClientInfo
70 {
71     DBusConnection *dbconn;
72     char req_name[TSC_REQ_STR_LEN];
73     char pid[TSC_REQ_STR_LEN];
74 } IpcClientInfo;
75
76 /**
77  * Data shared between the synchronized thread. It wraps the asynchronous call handle.
78  */
79 typedef struct _SharedData
80 {
81     int iSent;
82     ClientCallHandle *pCallHandle;
83     char szCallHandlePrefix[MSGHANDLE_LEN];
84     DBusMessage *pMsg;
85     pthread_mutex_t lock;
86     pthread_cond_t cond;
87 } SharedData;
88
89 /**
90  * Data passed to threads sending messages asynchronously.
91  * Owns only SharedData, rest are owned by 'parent thread'.
92  */
93 typedef struct _ThreadData
94 {
95     DBusConnection *pConn;
96     int timeout_milliseconds;
97     SharedData *pSharedData;
98     TSCCallback pCallBack;
99     void *pPrivate;
100 } ThreadData;
101
102 /*==================================================================================================
103                                      FUNCTION PROTOTYPES
104 ==================================================================================================*/
105
106 /**
107  * _ClientCallHandle related.
108  */
109 int _AssignToClientCallHandle(ClientCallHandle *pHandle, const char *szPrefix, dbus_uint32_t serial,
110                               DBusPendingCall *pPendingCall);
111
112 int _CreateClientCallHandle(ClientCallHandle **ppHandle, const char *szPrefix, dbus_uint32_t serial,
113                             DBusPendingCall *pPendingCall);
114
115 void _FreeClientCallHandle(ClientCallHandle *pHandle);
116
117 /**
118  * SharedData related.
119  */
120 void _FreeSharedData(SharedData *pSharedData);
121
122 // Create the handle to monitor send completion and receive sent message details.
123 // Maintains only reference of DBusMessage; Ownership is not changed.
124 SharedData *_CreateSharedData(const char *szCallHandlePrefix, DBusMessage *pMsg);
125
126 /**
127  * ThreadData related.
128  */
129 ThreadData *_AllocThreadData(DBusConnection *pConn, int timeout_milliseconds,
130                              SharedData *pSharedData, TSCCallback pCallback, void *pPrivate);
131
132 void _FreeThreadData(void *pThreadData);
133
134 #ifdef __cplusplus
135 }
136 #endif
137
138 #endif  /* IPCSTRUCTS_H */
139