    

 ## On this page

  

 

 # shared\_memory\_image\_client\_priv

 Last update: 16.07.2025 

[Go to the documentation of this file.](shared__memory__image__client__priv_8h.xhtml)<a id="l00001" name="l00001"></a> 1 /\* \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

<a id="l00002" name="l00002"></a> 2  \* Copyright 2017-2020 ANSYS, Inc.

<a id="l00003" name="l00003"></a> 3  \* All Rights Reserved.

<a id="l00004" name="l00004"></a> 4  \*

<a id="l00005" name="l00005"></a> 5  \* Restricted Rights Legend

<a id="l00006" name="l00006"></a> 6  \*

<a id="l00007" name="l00007"></a> 7  \* Use, duplication, or disclosure of this

<a id="l00008" name="l00008"></a> 8  \* software and its documentation by the

<a id="l00009" name="l00009"></a> 9  \* Government is subject to restrictions as

<a id="l00010" name="l00010"></a> 10  \* set forth in subdivision \[(b)(3)(ii)\] of

<a id="l00011" name="l00011"></a> 11  \* the Rights in Technical Data and Computer

<a id="l00012" name="l00012"></a> 12  \* Software clause at 52.227-7013.

<a id="l00013" name="l00013"></a> 13  \* \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

<a id="l00014" name="l00014"></a> 14  \*/

<a id="l00015" name="l00015"></a> 15 

<a id="l00016" name="l00016"></a> 16 \#ifndef \_\_\_ENSIGHT\_GRPC\_SHMEM\_CLIENT\_PRIV\_H\_\_\_

<a id="l00017" name="l00017"></a> 17 \#define \_\_\_ENSIGHT\_GRPC\_SHMEM\_CLIENT\_PRIV\_H\_\_\_

<a id="l00018" name="l00018"></a> 18 

<a id="l00109" name="l00109"></a> 109 \#include &lt;stdio.h&gt;

<a id="l00110" name="l00110"></a> 110 \#include &lt;stdlib.h&gt;

<a id="l00111" name="l00111"></a> 111 \#include &lt;string.h&gt;

<a id="l00112" name="l00112"></a> 112 

<a id="l00113" name="l00113"></a> 113 \#include "[shared\_memory\_image\_client.h](shared__memory__image__client_8h.xhtml)"

<a id="l00114" name="l00114"></a> 114 

<a id="l00115" name="l00115"></a> 115 \#ifdef WIN32

<a id="l00116" name="l00116"></a> 116 \#include &lt;windows.h&gt;

<a id="l00117" name="l00117"></a> 117 \#else

<a id="l00118" name="l00118"></a> 118 \#include &lt;sys/types.h&gt;

<a id="l00119" name="l00119"></a> 119 \#include &lt;sys/stat.h&gt;

<a id="l00120" name="l00120"></a> 120 \#include &lt;fcntl.h&gt;

<a id="l00121" name="l00121"></a> 121 \#include &lt;sys/mman.h&gt;

<a id="l00122" name="l00122"></a> 122 \#include &lt;pthread.h&gt;

<a id="l00123" name="l00123"></a> 123 \#include &lt;unistd.h&gt;

<a id="l00124" name="l00124"></a> 124 \#endif

<a id="l00125" name="l00125"></a> 125 

<a id="l00126" name="l00126"></a> 126 \#ifdef \_\_cplusplus

<a id="l00127" name="l00127"></a> 127 extern "C" {

<a id="l00128" name="l00128"></a> 128 \#endif

<a id="l00129" name="l00129"></a> 129 

<a id="l00130" name="l00130"></a> 130 /\* additional, private, creation options. These are normally used by EnSight, not clients \*/

<a id="l00131" name="l00131"></a> 131 /\* if set, the BufferHeader structures are initialized to IMAGESTREAM\_BUFFER\_STATE\_SERVER \*/

<a id="l00132" name="l00132"></a>[ 132](shared__memory__image__client__priv_8h.xhtml#a24ac2d665ce98370e25639bba2d992b6) \#define IMAGESTREAM\_OPTIONS\_INITBUFFERHEADERS 0x00000001 

<a id="l00133" name="l00133"></a>[ 133](shared__memory__image__client__priv_8h.xhtml#a673fd1d2f27007af83467699cb53614f) \#define IMAGESTREAM\_OPTIONS\_NOTHREADS 0x00000002 

<a id="l00134" name="l00134"></a> 134 /\* common server creation options \*/

<a id="l00135" name="l00135"></a>[ 135](shared__memory__image__client__priv_8h.xhtml#aa87740042e4f5882fa4c990a6528c2e3) \#define IMAGESTREAM\_OPTIONS\_SERVER IMAGESTREAM\_OPTIONS\_INITBUFFERHEADERS|IMAGESTREAM\_OPTIONS\_NOTHREADS 

<a id="l00138" name="l00138"></a> 138 

<a id="l00139" name="l00139"></a> 139 /\*

<a id="l00140" name="l00140"></a> 140  \* Shared memory layout:

<a id="l00141" name="l00141"></a> 141  \*

<a id="l00142" name="l00142"></a> 142  \* Note: all pixels are 3 bytes RGB byte ordering, no scanline gaps/alignment

<a id="l00143" name="l00143"></a> 143  \*

<a id="l00144" name="l00144"></a> 144  \* base memory mapped pointer

<a id="l00145" name="l00145"></a> 145  \* struct BufferHeader for buffer 0

<a id="l00146" name="l00146"></a> 146  \* uint\_8 data\[n\] image payload data

<a id="l00147" name="l00147"></a> 147  \* struct BufferHeader for buffer 1

<a id="l00148" name="l00148"></a> 148  \* uint\_8 data\[n\] image payload data

<a id="l00149" name="l00149"></a> 149  \*

<a id="l00150" name="l00150"></a> 150  \* BufferHeader

<a id="l00151" name="l00151"></a> 151  \* uint32\_t frame\_number

<a id="l00152" name="l00152"></a> 152  \* uint32\_t width in pixels of the entire frame

<a id="l00153" name="l00153"></a> 153  \* uint32\_t height in pixels of the entire frame

<a id="l00154" name="l00154"></a> 154  \* uint32\_t offset offset from the top of the image in scanlines for this block (0=end of frame)

<a id="l00155" name="l00155"></a> 155  \* uint32\_t num\_scanlines number of scanlines of data in the current payload

<a id="l00156" name="l00156"></a> 156  \* uint8\_t buffer\_state: 0=server owned, 1=server writing, 2=client owned, 3=client reading

<a id="l00157" name="l00157"></a> 157  \*

<a id="l00158" name="l00158"></a> 158  \* The server is responsible for initializing the shared memory header states.

<a id="l00159" name="l00159"></a> 159  \* 

<a id="l00160" name="l00160"></a> 160  \*

<a id="l00161" name="l00161"></a> 161  \* These are the values for 'buffer\_state' flag in the BufferHeader

<a id="l00162" name="l00162"></a> 162  \* structures. Only the process that has control over the buffer can

<a id="l00163" name="l00163"></a> 163  \* change its state. State progression:

<a id="l00164" name="l00164"></a> 164  \*

<a id="l00165" name="l00165"></a> 165  \* server sets to 4

<a id="l00166" name="l00166"></a> 166  \* client sets to 0

<a id="l00167" name="l00167"></a> 167  \* server sets to 1

<a id="l00168" name="l00168"></a> 168  \* server sets to 2

<a id="l00169" name="l00169"></a> 169  \* client sets to 3

<a id="l00170" name="l00170"></a> 170  \* client sets to 0

<a id="l00171" name="l00171"></a> 171  \*

<a id="l00172" name="l00172"></a> 172  \*/

<a id="l00173" name="l00173"></a> 173 

<a id="l00174" name="l00174"></a> 174 /\* 0=server has control over this buffer \*/

<a id="l00175" name="l00175"></a> 175 \#define IMAGESTREAM\_BUFFER\_STATE\_SERVER 0

<a id="l00176" name="l00176"></a> 176 /\* 1=server has control over this buffer and it actively writing to it \*/

<a id="l00177" name="l00177"></a> 177 \#define IMAGESTREAM\_BUFFER\_STATE\_SERVER\_LOCKED 1

<a id="l00178" name="l00178"></a> 178 /\* 2=client has control over this buffer and it has content written to by the server \*/

<a id="l00179" name="l00179"></a> 179 \#define IMAGESTREAM\_BUFFER\_STATE\_CLIENT 2

<a id="l00180" name="l00180"></a> 180 /\* 3=client has control over this buffer and has mapped it to a frame \*/

<a id="l00181" name="l00181"></a> 181 \#define IMAGESTREAM\_BUFFER\_STATE\_CLIENT\_LOCKED 3

<a id="l00182" name="l00182"></a> 182 /\* 4=(unconnected) client has control over the buffer. The server initializes the buffer

<a id="l00183" name="l00183"></a> 183  \* state to this value and waits for a client to connect. When a client connects, it 

<a id="l00184" name="l00184"></a> 184  \* changes the state to 0 \*/

<a id="l00185" name="l00185"></a> 185 \#define IMAGESTREAM\_BUFFER\_STATE\_INIT 4

<a id="l00186" name="l00186"></a> 186 

<a id="l00187" name="l00187"></a> 187 typedef struct {

<a id="l00188" name="l00188"></a> 188 uint32_t frame_number; 

<a id="l00189" name="l00189"></a> 189 uint32_t width; 

<a id="l00190" name="l00190"></a> 190 uint32_t height; 

<a id="l00191" name="l00191"></a> 191 uint32_t offset; 

<a id="l00192" name="l00192"></a> 192 uint32_t num_scanlines; 

<a id="l00193" name="l00193"></a> 193 uint8_t buffer_state; 

<a id="l00194" name="l00194"></a> 194 uint8_t pad[3]; 

<a id="l00195" name="l00195"></a> 195 } BufferHeader; 

<a id="l00196" name="l00196"></a> 196 

<a id="l00197" name="l00197"></a> 197 /\* 

<a id="l00198" name="l00198"></a> 198  \* These are the values for the 'frame\_state' flag in the \_SharedMemoryImageStream

<a id="l00199" name="l00199"></a> 199  \* structure. 

<a id="l00200" name="l00200"></a> 200  \* The frame starts in UNDEFINED state. The lcl\_thread\_process() thread will

<a id="l00201" name="l00201"></a> 201  \* transition the frame to the READY state. SharedMemoryImageStream\_lock() will

<a id="l00202" name="l00202"></a> 202  \* transition the frame to the LOCKED state. SharedMemoryImageStream\_unlock() will

<a id="l00203" name="l00203"></a> 203  \* transition the frame back to the UNDEFINED state.

<a id="l00204" name="l00204"></a> 204  \*

<a id="l00205" name="l00205"></a> 205  \* Note: if the image frame is locked, any associated buffer (frame\_buffer\_number),

<a id="l00206" name="l00206"></a> 206  \* will also be moved to IMAGESTREAM\_BUFFER\_STATE\_CLIENT\_LOCKED and then released to

<a id="l00207" name="l00207"></a> 207  \* IMAGESTREAM\_BUFFER\_STATE\_SERVER when the frame goes back to 

<a id="l00208" name="l00208"></a> 208  \* IMAGESTREAM\_FRAME\_STATE\_UNDEFINED.

<a id="l00209" name="l00209"></a> 209  \*/

<a id="l00210" name="l00210"></a> 210 \#define IMAGESTREAM\_FRAME\_STATE\_UNDEFINED 0

<a id="l00211" name="l00211"></a> 211 \#define IMAGESTREAM\_FRAME\_STATE\_IMAGE\_READY 1

<a id="l00212" name="l00212"></a> 212 \#define IMAGESTREAM\_FRAME\_STATE\_IMAGE\_LOCKED 2

<a id="l00213" name="l00213"></a> 213 

<a id="l00214" name="l00214"></a> 214 struct _SharedMemoryImageStream {

<a id="l00215" name="l00215"></a> 215 /\* memory mapped pointer and its length (note: this is not marked volatile as it is not

<a id="l00216" name="l00216"></a> 216  \* intended to be accessed directly, but the data it points to is volatile) \*/

<a id="l00217" name="l00217"></a> 217 uint8_t *ptr; 

<a id="l00218" name="l00218"></a> 218 size\_t length; 

<a id="l00219" name="l00219"></a> 219 uint8_t shutting_down; 

<a id="l00220" name="l00220"></a> 220 uint8_t frame_state; 

<a id="l00221" name="l00221"></a> 221 struct [\_SharedMemoryFrame](struct___shared_memory_frame.xhtml) frame; 

<a id="l00222" name="l00222"></a> 222 int32_t frame_buffer_number; 

<a id="l00223" name="l00223"></a> 223 /\* pointers into the memory mapped space (ptr) \*/

<a id="l00224" name="l00224"></a> 224 BufferHeader volatile *buffer_header[2]; 

<a id="l00225" name="l00225"></a> 225 uint8_t *buffer_data[2]; 

<a id="l00226" name="l00226"></a> 226 size\_t payload_length; 

<a id="l00227" name="l00227"></a> 227 

<a id="l00228" name="l00228"></a> 228 uint32_t options; 

<a id="l00229" name="l00229"></a> 229 /\* platform specific bits for memory mapped I/O, a thread and a mutex \*/

<a id="l00230" name="l00230"></a> 230 \#ifdef WIN32

<a id="l00231" name="l00231"></a> 231 HANDLE fd;

<a id="l00232" name="l00232"></a> 232 HANDLE file_map;

<a id="l00233" name="l00233"></a> 233 CRITICAL_SECTION mutex;

<a id="l00234" name="l00234"></a> 234 HANDLE thread;

<a id="l00235" name="l00235"></a> 235 \#else

<a id="l00236" name="l00236"></a> 236 int fd;

<a id="l00237" name="l00237"></a> 237 pthread_mutex_t mutex;

<a id="l00238" name="l00238"></a> 238 pthread_t thread;

<a id="l00239" name="l00239"></a> 239 \#endif

<a id="l00240" name="l00240"></a> 240 };

<a id="l00241" name="l00241"></a> 241 

<a id="l00243" name="l00243"></a> 243 

<a id="l00264" name="l00264"></a>[ 264](shared__memory__image__client__priv_8h.xhtml#abe3cb5374af97eeccf691864f6e2b2ad) [SharedMemoryImageError](shared__memory__image__client_8h.xhtml#a0496a9a3db499fa9145fe97d2e6dae9a) [SharedMemoryImageStream\_putframe](shared__memory__image__client__priv_8h.xhtml#abe3cb5374af97eeccf691864f6e2b2ad)([SharedMemoryImageStream](shared__memory__image__client_8h.xhtml#af5b8eb2ae90823f10e9a17698ea80749) stream,

<a id="l00265" name="l00265"></a> 265 [SharedMemoryFrame](struct___shared_memory_frame.xhtml) frame);

<a id="l00266" name="l00266"></a> 266 

<a id="l00267" name="l00267"></a> 267 \#ifdef \_\_cplusplus

<a id="l00268" name="l00268"></a> 268 }

<a id="l00269" name="l00269"></a> 269 \#endif

<a id="l00270" name="l00270"></a> 270 

<a id="l00271" name="l00271"></a> 271 \#endif

[shared\_memory\_image\_client.h](shared__memory__image__client_8h.xhtml)

C API for using the EnSight grpc shared memory image transport API.



[SharedMemoryImageError](shared__memory__image__client_8h.xhtml#a0496a9a3db499fa9145fe97d2e6dae9a)

int SharedMemoryImageError

common error codes see the non-hex, non-string IMAGESTREAM macros

**Definition:** [shared\_memory\_image\_client.h:109](shared__memory__image__client_8h_source.xhtml#l00109)



[SharedMemoryImageStream](shared__memory__image__client_8h.xhtml#af5b8eb2ae90823f10e9a17698ea80749)

struct _SharedMemoryImageStream * SharedMemoryImageStream

image transport stream pointer

**Definition:** [shared\_memory\_image\_client.h:111](shared__memory__image__client_8h_source.xhtml#l00111)



[SharedMemoryImageStream\_putframe](shared__memory__image__client__priv_8h.xhtml#abe3cb5374af97eeccf691864f6e2b2ad)

DEV SharedMemoryImageError SharedMemoryImageStream_putframe(SharedMemoryImageStream stream, SharedMemoryFrame frame)

SharedMemoryImageStream_putframe push a new image into a server image stream channel.



[\_SharedMemoryFrame](struct___shared_memory_frame.xhtml)

**Definition:** [shared\_memory\_image\_client.h:115](shared__memory__image__client_8h_source.xhtml#l00115)