1 /* Copyright (C) 2021-2024 Free Software Foundation, Inc.
4 This file is part of GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
21 /* Defines the external interface between er_ipc and the routines */
27 #include "StringBuilder.h"
30 typedef long long DbeObj
;
34 #define BUFFER_SIZE_SMALL 512
35 #define BUFFER_SIZE_MEDIUM 512
36 #define BUFFER_SIZE_LARGE 1024*1024
38 #define REQUEST_HAS_NO_BODY 0xFFFFFFFF
39 #define RESPONSE_STATUS_DEFAULT 0
40 #define RESPONSE_STATUS_SUCCESS 1
41 #define RESPONSE_STATUS_FAILURE 2
42 #define RESPONSE_STATUS_CANCELLED 3
43 #define RESPONSE_STATUS_ERROR 4
45 #define RESPONSE_TYPE_ACK 0
46 #define RESPONSE_TYPE_PROGRESS 1
47 #define RESPONSE_TYPE_COMPLETE 2
48 #define RESPONSE_TYPE_HANDSHAKE 3
49 #define HEADER_MARKER 0xff
51 #define REQUEST_TYPE_DEFAULT 0
52 #define REQUEST_TYPE_CANCEL 1
53 #define REQUEST_TYPE_HANDSHAKE 2
55 #define IPC_PROTOCOL_STR "IPC_PROTOCOL_38"
56 #define IPC_VERSION_NUMBER 38
84 IPCrequestStatus status
;
87 IPCrequest (int, int, int);
89 IPCrequestStatus
getStatus ();
90 void setStatus (IPCrequestStatus
);
93 int getRequestID () { return requestID
; }
94 int getChannelID () { return channelID
; }
95 bool isCancelImmediate () { return cancelImmediate
; }
96 void setCancelImmediate () { cancelImmediate
= true; }
97 char rgetc () { return buf
[idx
++]; }
103 IPCresponse (int sz
);
106 int getRequestID () { return requestID
; }
107 int getChannelID () { return channelID
; }
108 void setRequestID (int r
) { requestID
= r
; }
109 void setChannelID (int c
) { channelID
= c
; }
110 void setResponseType (int r
) { responseType
= r
; }
111 void setResponseStatus (int s
) { responseStatus
= s
; }
112 int getCurBufSize () { return sb
->capacity (); }
115 void sendLVal (long long);
116 void sendDVal (double);
117 void sendSVal (const char *);
118 void sendBVal (bool);
119 void sendCVal (char);
120 void sendAVal (void*);
138 IPCresponse
* getNewResponse (int);
139 void recycle (IPCresponse
*);
141 pthread_mutex_t p_mutex
;
142 IPCresponse
*smallBuf
;
143 IPCresponse
*largeBuf
;
146 // Read from the wire
147 int readInt (IPCrequest
*);
148 bool readBoolean (IPCrequest
*);
149 long long readLong (IPCrequest
*);
150 DbeObj
readObject (IPCrequest
*);
151 Object
readArray (IPCrequest
*);
152 String
readString (IPCrequest
*);
153 void readRequestHeader ();
156 void writeError (const char *, IPCrequest
*);
157 void writeString (const char *, IPCrequest
*);
158 void writeBoolean (bool, IPCrequest
*);
159 void writeInt (int, IPCrequest
*);
160 void writeChar (char, IPCrequest
*);
161 void writeLong (long long, IPCrequest
*);
162 void writeDouble (double, IPCrequest
*);
163 void writeArray (void *, IPCrequest
*);
164 void writeObject (DbeObj
, IPCrequest
*);
165 void writeResponseGeneric (int, int, int);
166 int setProgress (int, const char *); // Update the progress bar
167 int ipc_doWork (void *); // The argument is an IPCrequest
169 extern int ipc_flags
;
170 extern int ipc_single_threaded_mode
;
171 extern DbeThreadPool
*responseThreadPool
;
172 extern DbeThreadPool
*ipcThreadPool
;
173 extern int cancelRequestedChannelID
;
174 extern int cancellableChannelID
;
175 extern int error_flag
;
177 void ipc_default_log (const char *fmt
, ...) __attribute__ ((format (printf
, 1, 2)));
178 void ipc_response_log (IPCTraceLevel
, const char *fmt
, ...) __attribute__ ((format (printf
, 2, 3)));
179 void ipc_request_log (IPCTraceLevel
, const char *fmt
, ...) __attribute__ ((format (printf
, 2, 3)));