1 /* Copyright (C) 2021 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
44 #define RESPONSE_TYPE_ACK 0
45 #define RESPONSE_TYPE_PROGRESS 1
46 #define RESPONSE_TYPE_COMPLETE 2
47 #define RESPONSE_TYPE_HANDSHAKE 3
48 #define HEADER_MARKER 0xff
50 #define REQUEST_TYPE_DEFAULT 0
51 #define REQUEST_TYPE_CANCEL 1
52 #define REQUEST_TYPE_HANDSHAKE 2
54 #define IPC_PROTOCOL_STR "IPC_PROTOCOL_38"
55 #define IPC_VERSION_NUMBER 38
82 IPCrequestStatus status;
85 IPCrequest (int, int, int);
87 IPCrequestStatus getStatus ();
88 void setStatus (IPCrequestStatus);
91 int getRequestID () { return requestID; }
92 int getChannelID () { return channelID; }
93 bool isCancelImmediate () { return cancelImmediate; }
94 void setCancelImmediate () { cancelImmediate = true; }
95 char rgetc () { return buf[idx++]; }
101 IPCresponse (int sz);
104 int getRequestID () { return requestID; }
105 int getChannelID () { return channelID; }
106 void setRequestID (int r) { requestID = r; }
107 void setChannelID (int c) { channelID = c; }
108 void setResponseType (int r) { responseType = r; }
109 void setResponseStatus (int s) { responseStatus = s; }
110 int getCurBufSize () { return sb->capacity (); }
113 void sendLVal (long long);
114 void sendDVal (double);
115 void sendSVal (const char *);
116 void sendBVal (bool);
117 void sendCVal (char);
118 void sendAVal (void*);
136 IPCresponse* getNewResponse (int);
137 void recycle (IPCresponse *);
139 pthread_mutex_t p_mutex;
140 IPCresponse *smallBuf;
141 IPCresponse *largeBuf;
144 // Read from the wire
145 int readInt (IPCrequest*);
146 bool readBoolean (IPCrequest*);
147 long long readLong (IPCrequest*);
148 DbeObj readObject (IPCrequest*);
149 Object readArray (IPCrequest*);
150 String readString (IPCrequest*);
151 void readRequestHeader ();
154 void writeString (const char *, IPCrequest*);
155 void writeBoolean (bool, IPCrequest*);
156 void writeInt (int, IPCrequest*);
157 void writeChar (char, IPCrequest*);
158 void writeLong (long long, IPCrequest*);
159 void writeDouble (double, IPCrequest*);
160 void writeArray (void *, IPCrequest*);
161 void writeObject (DbeObj, IPCrequest*);
162 void writeResponseGeneric (int, int, int);
163 int setProgress (int, const char *); // Update the progress bar
164 int ipc_doWork (void *); // The argument is an IPCrequest
166 extern int ipc_flags;
167 extern int ipc_single_threaded_mode;
168 extern DbeThreadPool *responseThreadPool;
169 extern DbeThreadPool *ipcThreadPool;
170 extern int cancelRequestedChannelID;
172 void ipc_default_log (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
173 void ipc_response_log (IPCTraceLevel, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
174 void ipc_request_log (IPCTraceLevel, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));