cristy | e80f9cb | 2013-01-09 01:09:31 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % DDDD IIIII SSSSS TTTTT RRRR IIIII BBBB U U TTTTT EEEEE % |
| 6 | % D D I SS T R R I B B U U T E % |
| 7 | % D D I SSS T RRRR I BBBB U U T EEE % |
| 8 | % D D I SS T R R I B B U U T E % |
| 9 | % DDDDA IIIII SSSSS T R R IIIII BBBB UUU T EEEEE % |
| 10 | % % |
| 11 | % CCCC AAA CCCC H H EEEEE % |
| 12 | % C A A C H H E % |
| 13 | % C AAAAA C HHHHH EEE % |
| 14 | % C A A C H H E % |
| 15 | % CCCC A A CCCC H H EEEEE % |
| 16 | % % |
| 17 | % % |
| 18 | % MagickCore Distributed Pixel Cache Methods % |
| 19 | % % |
| 20 | % Software Design % |
| 21 | % John Cristy % |
| 22 | % January 2013 % |
| 23 | % % |
| 24 | % % |
| 25 | % Copyright 1999-2013 ImageMagick Studio LLC, a non-profit organization % |
| 26 | % dedicated to making software imaging solutions freely available. % |
| 27 | % % |
| 28 | % You may not use this file except in compliance with the License. You may % |
| 29 | % obtain a copy of the License at % |
| 30 | % % |
| 31 | % http://www.imagemagick.org/script/license.php % |
| 32 | % % |
| 33 | % Unless required by applicable law or agreed to in writing, software % |
| 34 | % distributed under the License is distributed on an "AS IS" BASIS, % |
| 35 | % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % |
| 36 | % See the License for the specific language governing permissions and % |
| 37 | % limitations under the License. % |
| 38 | % % |
| 39 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 40 | % |
| 41 | % A distributed pixel cache is an extension of the traditional pixel cache |
| 42 | % available on a single host. The distributed pixel cache may span multiple |
| 43 | % servers so that it can grow in size and transactional capacity to support |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 44 | % very large images. Start up the pixel cache server on one or more machines. |
cristy | e80f9cb | 2013-01-09 01:09:31 +0000 | [diff] [blame] | 45 | % When you read or operate on an image and the local pixel cache resources are |
| 46 | % exhausted, ImageMagick contacts one or more of these remote pixel servers to |
| 47 | % store or retrieve pixels. |
| 48 | % |
| 49 | */ |
| 50 | |
| 51 | /* |
| 52 | Include declarations. |
| 53 | */ |
| 54 | #include "MagickCore/studio.h" |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 55 | #include "MagickCore/cache.h" |
| 56 | #include "MagickCore/cache-private.h" |
cristy | 1cbaf97 | 2013-01-09 02:13:23 +0000 | [diff] [blame] | 57 | #include "MagickCore/distribute-cache.h" |
| 58 | #include "MagickCore/distribute-cache-private.h" |
| 59 | #include "MagickCore/exception.h" |
| 60 | #include "MagickCore/exception-private.h" |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 61 | #include "MagickCore/geometry.h" |
| 62 | #include "MagickCore/image.h" |
cristy | 4b4a07e | 2013-01-22 17:07:56 +0000 | [diff] [blame] | 63 | #include "MagickCore/list.h" |
cristy | 0838a03 | 2013-01-11 02:25:29 +0000 | [diff] [blame] | 64 | #include "MagickCore/locale_.h" |
cristy | e80f9cb | 2013-01-09 01:09:31 +0000 | [diff] [blame] | 65 | #include "MagickCore/memory_.h" |
cristy | 8155c10 | 2013-02-06 16:39:01 +0000 | [diff] [blame] | 66 | #include "MagickCore/nt-base-private.h" |
cristy | 766c2f1 | 2013-01-25 02:46:26 +0000 | [diff] [blame] | 67 | #include "MagickCore/pixel.h" |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 68 | #include "MagickCore/policy.h" |
| 69 | #include "MagickCore/random_.h" |
cristy | 7edca2b | 2013-01-10 01:55:05 +0000 | [diff] [blame] | 70 | #include "MagickCore/registry.h" |
cristy | e34745c | 2013-01-16 02:27:04 +0000 | [diff] [blame] | 71 | #include "MagickCore/splay-tree.h" |
cristy | 0838a03 | 2013-01-11 02:25:29 +0000 | [diff] [blame] | 72 | #include "MagickCore/string_.h" |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 73 | #include "MagickCore/string-private.h" |
cristy | 8cca92e | 2013-01-23 21:00:51 +0000 | [diff] [blame] | 74 | #include "MagickCore/version.h" |
cristy | a371edf | 2013-02-06 13:42:17 +0000 | [diff] [blame] | 75 | #include "MagickCore/version-private.h" |
cristy | 80b9501 | 2013-04-23 16:29:17 +0000 | [diff] [blame] | 76 | #if defined(MAGICKCORE_HAVE_SOCKET) && defined(MAGICKCORE_HAVE_PTHREAD) |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 77 | #include <netinet/in.h> |
cristy | 0838a03 | 2013-01-11 02:25:29 +0000 | [diff] [blame] | 78 | #include <netdb.h> |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 79 | #include <sys/socket.h> |
| 80 | #include <arpa/inet.h> |
cristy | 9d570f0 | 2013-03-31 01:08:49 +0000 | [diff] [blame] | 81 | #else |
| 82 | #undef send |
| 83 | #undef recv |
| 84 | #define send(file,buffer,length,flags) 0 |
| 85 | #define recv(file,buffer,length,flags) 0 |
cristy | e80f9cb | 2013-01-09 01:09:31 +0000 | [diff] [blame] | 86 | #endif |
| 87 | |
| 88 | /* |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 89 | Define declarations. |
| 90 | */ |
| 91 | #define DPCHostname "127.0.0.1" |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 92 | #define DPCPendingConnections 10 |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 93 | #define DPCPort 6668 |
| 94 | #define DPCSessionKeyLength 8 |
cristy | 7fc1b85 | 2013-01-27 16:47:26 +0000 | [diff] [blame] | 95 | #ifndef MSG_NOSIGNAL |
| 96 | # define MSG_NOSIGNAL 0 |
| 97 | #endif |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 98 | |
| 99 | /* |
cristy | e80f9cb | 2013-01-09 01:09:31 +0000 | [diff] [blame] | 100 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 101 | % % |
| 102 | % % |
| 103 | % % |
cristy | 43940f4 | 2013-01-17 00:24:06 +0000 | [diff] [blame] | 104 | + A c q u i r e D i s t r i b u t e C a c h e I n f o % |
cristy | 1cbaf97 | 2013-01-09 02:13:23 +0000 | [diff] [blame] | 105 | % % |
| 106 | % % |
| 107 | % % |
| 108 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 109 | % |
| 110 | % AcquireDistributeCacheInfo() allocates the DistributeCacheInfo structure. |
| 111 | % |
| 112 | % The format of the AcquireDistributeCacheInfo method is: |
| 113 | % |
cristy | 7edca2b | 2013-01-10 01:55:05 +0000 | [diff] [blame] | 114 | % DistributeCacheInfo *AcquireDistributeCacheInfo(ExceptionInfo *exception) |
| 115 | % |
| 116 | % A description of each parameter follows: |
| 117 | % |
| 118 | % o exception: return any errors or warnings in this structure. |
cristy | 1cbaf97 | 2013-01-09 02:13:23 +0000 | [diff] [blame] | 119 | % |
| 120 | */ |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 121 | |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 122 | static inline MagickSizeType MagickMin(const MagickSizeType x, |
| 123 | const MagickSizeType y) |
| 124 | { |
| 125 | if (x < y) |
| 126 | return(x); |
| 127 | return(y); |
| 128 | } |
| 129 | |
| 130 | static inline MagickOffsetType dpc_read(int file,const MagickSizeType length, |
| 131 | unsigned char *restrict message) |
| 132 | { |
cristy | 3c92804 | 2013-01-26 00:11:04 +0000 | [diff] [blame] | 133 | register MagickOffsetType |
| 134 | i; |
| 135 | |
| 136 | ssize_t |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 137 | count; |
| 138 | |
cristy | 3c92804 | 2013-01-26 00:11:04 +0000 | [diff] [blame] | 139 | count=0; |
| 140 | for (i=0; i < (MagickOffsetType) length; i+=count) |
| 141 | { |
| 142 | count=recv(file,message+i,(size_t) MagickMin(length-i,(MagickSizeType) |
| 143 | SSIZE_MAX),0); |
| 144 | if (count <= 0) |
| 145 | { |
| 146 | count=0; |
| 147 | if (errno != EINTR) |
| 148 | break; |
| 149 | } |
| 150 | } |
| 151 | return(i); |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 152 | } |
| 153 | |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 154 | static int ConnectPixelCacheServer(const char *hostname,const int port, |
cristy | 2330a75 | 2013-01-28 13:19:51 +0000 | [diff] [blame] | 155 | size_t *session_key,ExceptionInfo *exception) |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 156 | { |
cristy | 80b9501 | 2013-04-23 16:29:17 +0000 | [diff] [blame] | 157 | #if defined(MAGICKCORE_HAVE_SOCKET) && defined(MAGICKCORE_HAVE_PTHREAD) |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 158 | char |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 159 | service[MaxTextExtent]; |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 160 | |
| 161 | const char |
| 162 | *shared_secret; |
| 163 | |
| 164 | int |
| 165 | client_socket, |
| 166 | status; |
| 167 | |
cristy | 90b1093 | 2013-01-28 13:26:57 +0000 | [diff] [blame] | 168 | ssize_t |
cristy | 5067ec2 | 2013-01-27 23:35:56 +0000 | [diff] [blame] | 169 | count; |
| 170 | |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 171 | struct addrinfo |
| 172 | hint, |
| 173 | *result; |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 174 | |
| 175 | unsigned char |
cristy | 410133d | 2013-02-05 20:06:52 +0000 | [diff] [blame] | 176 | secret[MaxTextExtent]; |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 177 | |
| 178 | /* |
| 179 | Connect to distributed pixel cache and get session key. |
| 180 | */ |
| 181 | *session_key=0; |
| 182 | shared_secret=GetPolicyValue("shared-secret"); |
| 183 | if (shared_secret == (const char *) NULL) |
| 184 | { |
| 185 | (void) ThrowMagickException(exception,GetMagickModule(),CacheError, |
| 186 | "DistributedPixelCache","'%s'","shared secret expected"); |
| 187 | return(-1); |
| 188 | } |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 189 | (void) ResetMagickMemory(&hint,0,sizeof(hint)); |
| 190 | hint.ai_family=AF_INET; |
| 191 | hint.ai_socktype=SOCK_STREAM; |
| 192 | hint.ai_flags=AI_PASSIVE; |
| 193 | (void) FormatLocaleString(service,MaxTextExtent,"%d",port); |
| 194 | status=getaddrinfo(hostname,service,&hint,&result); |
| 195 | if (status != 0) |
| 196 | { |
| 197 | (void) ThrowMagickException(exception,GetMagickModule(),CacheError, |
| 198 | "DistributedPixelCache","'%s'",hostname); |
| 199 | return(-1); |
| 200 | } |
| 201 | client_socket=socket(result->ai_family,result->ai_socktype, |
| 202 | result->ai_protocol); |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 203 | if (client_socket == -1) |
| 204 | { |
| 205 | (void) ThrowMagickException(exception,GetMagickModule(),CacheError, |
| 206 | "DistributedPixelCache","'%s'",hostname); |
| 207 | return(-1); |
| 208 | } |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 209 | status=connect(client_socket,result->ai_addr,result->ai_addrlen); |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 210 | if (status == -1) |
| 211 | { |
| 212 | (void) ThrowMagickException(exception,GetMagickModule(),CacheError, |
| 213 | "DistributedPixelCache","'%s'",hostname); |
| 214 | return(-1); |
| 215 | } |
cristy | 3c92804 | 2013-01-26 00:11:04 +0000 | [diff] [blame] | 216 | count=recv(client_socket,secret,MaxTextExtent,0); |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 217 | if (count != -1) |
| 218 | { |
cristy | 410133d | 2013-02-05 20:06:52 +0000 | [diff] [blame] | 219 | StringInfo |
| 220 | *nonce; |
cristy | c6c7684 | 2013-01-23 18:32:26 +0000 | [diff] [blame] | 221 | |
cristy | 410133d | 2013-02-05 20:06:52 +0000 | [diff] [blame] | 222 | nonce=AcquireStringInfo(count); |
| 223 | (void) memcpy(GetStringInfoDatum(nonce),secret,(size_t) count); |
| 224 | *session_key=GetMagickSignature(nonce); |
| 225 | nonce=DestroyStringInfo(nonce); |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 226 | } |
| 227 | if (*session_key == 0) |
| 228 | { |
| 229 | close(client_socket); |
| 230 | client_socket=(-1); |
| 231 | } |
| 232 | return(client_socket); |
| 233 | #else |
| 234 | (void) ThrowMagickException(exception,GetMagickModule(),MissingDelegateError, |
| 235 | "DelegateLibrarySupportNotBuiltIn","distributed pixel cache"); |
| 236 | return(MagickFalse); |
| 237 | #endif |
| 238 | } |
| 239 | |
| 240 | static char *GetHostname(int *port,ExceptionInfo *exception) |
| 241 | { |
| 242 | char |
| 243 | *host, |
| 244 | *hosts, |
| 245 | **hostlist; |
| 246 | |
| 247 | int |
| 248 | argc; |
| 249 | |
| 250 | register ssize_t |
| 251 | i; |
| 252 | |
| 253 | static size_t |
| 254 | id = 0; |
| 255 | |
| 256 | /* |
| 257 | Parse host list (e.g. 192.168.100.1:6668,192.168.100.2:6668). |
| 258 | */ |
| 259 | hosts=(char *) GetImageRegistry(StringRegistryType,"cache:hosts", |
| 260 | exception); |
| 261 | if (hosts == (char *) NULL) |
| 262 | { |
| 263 | *port=DPCPort; |
| 264 | return(AcquireString(DPCHostname)); |
| 265 | } |
| 266 | (void) SubstituteString(&hosts,","," "); |
| 267 | hostlist=StringToArgv(hosts,&argc); |
| 268 | hosts=DestroyString(hosts); |
| 269 | if (hostlist == (char **) NULL) |
| 270 | { |
| 271 | *port=DPCPort; |
| 272 | return(AcquireString(DPCHostname)); |
| 273 | } |
| 274 | hosts=AcquireString(hostlist[(id++ % (argc-1))+1]); |
| 275 | for (i=0; i < (ssize_t) argc; i++) |
| 276 | hostlist[i]=DestroyString(hostlist[i]); |
| 277 | hostlist=(char **) RelinquishMagickMemory(hostlist); |
| 278 | (void) SubstituteString(&hosts,":"," "); |
| 279 | hostlist=StringToArgv(hosts,&argc); |
| 280 | if (hostlist == (char **) NULL) |
| 281 | { |
| 282 | *port=DPCPort; |
| 283 | return(AcquireString(DPCHostname)); |
| 284 | } |
| 285 | host=AcquireString(hostlist[1]); |
| 286 | if (hostlist[2] == (char *) NULL) |
| 287 | *port=DPCPort; |
| 288 | else |
| 289 | *port=StringToLong(hostlist[2]); |
| 290 | for (i=0; i < (ssize_t) argc; i++) |
| 291 | hostlist[i]=DestroyString(hostlist[i]); |
| 292 | hostlist=(char **) RelinquishMagickMemory(hostlist); |
| 293 | return(host); |
| 294 | } |
| 295 | |
cristy | 7edca2b | 2013-01-10 01:55:05 +0000 | [diff] [blame] | 296 | MagickPrivate DistributeCacheInfo *AcquireDistributeCacheInfo( |
| 297 | ExceptionInfo *exception) |
cristy | 1cbaf97 | 2013-01-09 02:13:23 +0000 | [diff] [blame] | 298 | { |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 299 | char |
| 300 | *hostname; |
| 301 | |
cristy | 1cbaf97 | 2013-01-09 02:13:23 +0000 | [diff] [blame] | 302 | DistributeCacheInfo |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 303 | *server_info; |
cristy | 1cbaf97 | 2013-01-09 02:13:23 +0000 | [diff] [blame] | 304 | |
cristy | 2330a75 | 2013-01-28 13:19:51 +0000 | [diff] [blame] | 305 | size_t |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 306 | session_key; |
| 307 | |
cristy | feb2167 | 2013-01-23 00:12:55 +0000 | [diff] [blame] | 308 | /* |
| 309 | Connect to the distributed pixel cache server. |
| 310 | */ |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 311 | server_info=(DistributeCacheInfo *) AcquireMagickMemory(sizeof(*server_info)); |
| 312 | if (server_info == (DistributeCacheInfo *) NULL) |
cristy | 1cbaf97 | 2013-01-09 02:13:23 +0000 | [diff] [blame] | 313 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 314 | (void) ResetMagickMemory(server_info,0,sizeof(*server_info)); |
| 315 | server_info->signature=MagickSignature; |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 316 | server_info->port=0; |
| 317 | hostname=GetHostname(&server_info->port,exception); |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 318 | session_key=0; |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 319 | server_info->file=ConnectPixelCacheServer(hostname,server_info->port, |
| 320 | &session_key,exception); |
| 321 | server_info->session_key=session_key; |
| 322 | (void) CopyMagickString(server_info->hostname,hostname,MaxTextExtent); |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 323 | hostname=DestroyString(hostname); |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 324 | if (server_info->file == -1) |
| 325 | server_info=DestroyDistributeCacheInfo(server_info); |
| 326 | return(server_info); |
cristy | 1cbaf97 | 2013-01-09 02:13:23 +0000 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | /* |
| 330 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 331 | % % |
| 332 | % % |
| 333 | % % |
cristy | 43940f4 | 2013-01-17 00:24:06 +0000 | [diff] [blame] | 334 | + D e s t r o y D i s t r i b u t e C a c h e I n f o % |
cristy | 1cbaf97 | 2013-01-09 02:13:23 +0000 | [diff] [blame] | 335 | % % |
| 336 | % % |
| 337 | % % |
| 338 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 339 | % |
| 340 | % DestroyDistributeCacheInfo() deallocates memory associated with an |
| 341 | % DistributeCacheInfo structure. |
| 342 | % |
| 343 | % The format of the DestroyDistributeCacheInfo method is: |
| 344 | % |
| 345 | % DistributeCacheInfo *DestroyDistributeCacheInfo( |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 346 | % DistributeCacheInfo *server_info) |
cristy | 1cbaf97 | 2013-01-09 02:13:23 +0000 | [diff] [blame] | 347 | % |
| 348 | % A description of each parameter follows: |
| 349 | % |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 350 | % o server_info: the distributed cache info. |
cristy | 1cbaf97 | 2013-01-09 02:13:23 +0000 | [diff] [blame] | 351 | % |
| 352 | */ |
| 353 | MagickPrivate DistributeCacheInfo *DestroyDistributeCacheInfo( |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 354 | DistributeCacheInfo *server_info) |
cristy | 1cbaf97 | 2013-01-09 02:13:23 +0000 | [diff] [blame] | 355 | { |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 356 | assert(server_info != (DistributeCacheInfo *) NULL); |
| 357 | assert(server_info->signature == MagickSignature); |
cristy | 066c4fb | 2013-01-19 02:36:14 +0000 | [diff] [blame] | 358 | if (server_info->file > 0) |
| 359 | (void) close(server_info->file); |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 360 | server_info->signature=(~MagickSignature); |
| 361 | server_info=(DistributeCacheInfo *) RelinquishMagickMemory(server_info); |
| 362 | return(server_info); |
cristy | 1cbaf97 | 2013-01-09 02:13:23 +0000 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | /* |
| 366 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 367 | % % |
| 368 | % % |
| 369 | % % |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 370 | + D i s t r i b u t e P i x e l C a c h e S e r v e r % |
cristy | e80f9cb | 2013-01-09 01:09:31 +0000 | [diff] [blame] | 371 | % % |
| 372 | % % |
| 373 | % % |
| 374 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 375 | % |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 376 | % DistributePixelCacheServer() waits on the specified port for commands to |
| 377 | % create, read, update, or destroy a pixel cache. |
cristy | e80f9cb | 2013-01-09 01:09:31 +0000 | [diff] [blame] | 378 | % |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 379 | % The format of the DistributePixelCacheServer() method is: |
cristy | e80f9cb | 2013-01-09 01:09:31 +0000 | [diff] [blame] | 380 | % |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 381 | % void DistributePixelCacheServer(const int port) |
cristy | e80f9cb | 2013-01-09 01:09:31 +0000 | [diff] [blame] | 382 | % |
| 383 | % A description of each parameter follows: |
| 384 | % |
| 385 | % o port: connect the distributed pixel cache at this port. |
| 386 | % |
cristy | 7675e60 | 2013-01-11 12:14:51 +0000 | [diff] [blame] | 387 | % o exception: return any errors or warnings in this structure. |
| 388 | % |
cristy | e80f9cb | 2013-01-09 01:09:31 +0000 | [diff] [blame] | 389 | */ |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 390 | |
cristy | 066c4fb | 2013-01-19 02:36:14 +0000 | [diff] [blame] | 391 | static MagickBooleanType DestroyDistributeCache(SplayTreeInfo *registry, |
cristy | 2330a75 | 2013-01-28 13:19:51 +0000 | [diff] [blame] | 392 | int file,const size_t session_key) |
cristy | 9c3f05b | 2013-01-17 18:51:14 +0000 | [diff] [blame] | 393 | { |
cristy | feb2167 | 2013-01-23 00:12:55 +0000 | [diff] [blame] | 394 | /* |
| 395 | Destroy distributed pixel cache. |
| 396 | */ |
cristy | b0de93f | 2013-05-03 13:39:25 +0000 | [diff] [blame] | 397 | (void) file; |
cristy | 066c4fb | 2013-01-19 02:36:14 +0000 | [diff] [blame] | 398 | return(DeleteNodeFromSplayTree(registry,(const void *) session_key)); |
cristy | 9c3f05b | 2013-01-17 18:51:14 +0000 | [diff] [blame] | 399 | } |
| 400 | |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 401 | static inline MagickOffsetType dpc_send(int file,const MagickSizeType length, |
cristy | fc7a24a | 2013-01-22 17:38:31 +0000 | [diff] [blame] | 402 | const unsigned char *restrict message) |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 403 | { |
| 404 | MagickOffsetType |
| 405 | count; |
| 406 | |
| 407 | register MagickOffsetType |
| 408 | i; |
| 409 | |
cristy | feb2167 | 2013-01-23 00:12:55 +0000 | [diff] [blame] | 410 | /* |
| 411 | Ensure a complete message is sent. |
| 412 | */ |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 413 | count=0; |
| 414 | for (i=0; i < (MagickOffsetType) length; i+=count) |
| 415 | { |
cristy | fc7a24a | 2013-01-22 17:38:31 +0000 | [diff] [blame] | 416 | count=(MagickOffsetType) send(file,message+i,(size_t) MagickMin(length-i, |
cristy | be5d52d | 2013-01-25 19:40:42 +0000 | [diff] [blame] | 417 | (MagickSizeType) SSIZE_MAX),MSG_NOSIGNAL); |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 418 | if (count <= 0) |
| 419 | { |
| 420 | count=0; |
| 421 | if (errno != EINTR) |
| 422 | break; |
| 423 | } |
| 424 | } |
| 425 | return(i); |
| 426 | } |
| 427 | |
cristy | 066c4fb | 2013-01-19 02:36:14 +0000 | [diff] [blame] | 428 | static MagickBooleanType OpenDistributeCache(SplayTreeInfo *registry, |
cristy | 2330a75 | 2013-01-28 13:19:51 +0000 | [diff] [blame] | 429 | int file,const size_t session_key,ExceptionInfo *exception) |
cristy | e80f9cb | 2013-01-09 01:09:31 +0000 | [diff] [blame] | 430 | { |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 431 | Image |
| 432 | *image; |
| 433 | |
| 434 | MagickBooleanType |
cristy | e80f9cb | 2013-01-09 01:09:31 +0000 | [diff] [blame] | 435 | status; |
| 436 | |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 437 | MagickOffsetType |
| 438 | count; |
| 439 | |
| 440 | MagickSizeType |
| 441 | length; |
| 442 | |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 443 | register unsigned char |
| 444 | *p; |
| 445 | |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 446 | unsigned char |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 447 | message[MaxTextExtent]; |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 448 | |
cristy | feb2167 | 2013-01-23 00:12:55 +0000 | [diff] [blame] | 449 | /* |
| 450 | Open distributed pixel cache. |
| 451 | */ |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 452 | image=AcquireImage((ImageInfo *) NULL,exception); |
cristy | e27c196 | 2013-01-17 20:16:29 +0000 | [diff] [blame] | 453 | if (image == (Image *) NULL) |
| 454 | return(MagickFalse); |
cristy | 766c2f1 | 2013-01-25 02:46:26 +0000 | [diff] [blame] | 455 | length=sizeof(image->storage_class)+sizeof(image->colorspace)+ |
cristy | 883fde1 | 2013-04-08 00:50:13 +0000 | [diff] [blame] | 456 | sizeof(image->alpha_trait)+sizeof(image->read_mask)+ |
| 457 | sizeof(image->write_mask)+sizeof(image->columns)+sizeof(image->rows)+ |
| 458 | sizeof(image->number_channels)+MaxPixelChannels*sizeof(*image->channel_map)+ |
| 459 | sizeof(image->metacontent_extent); |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 460 | count=dpc_read(file,length,message); |
| 461 | if (count != (MagickOffsetType) length) |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 462 | return(MagickFalse); |
cristy | 766c2f1 | 2013-01-25 02:46:26 +0000 | [diff] [blame] | 463 | /* |
cristy | 90b1093 | 2013-01-28 13:26:57 +0000 | [diff] [blame] | 464 | Deserialize the image attributes. |
cristy | 766c2f1 | 2013-01-25 02:46:26 +0000 | [diff] [blame] | 465 | */ |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 466 | p=message; |
cristy | 766c2f1 | 2013-01-25 02:46:26 +0000 | [diff] [blame] | 467 | (void) memcpy(&image->storage_class,p,sizeof(image->storage_class)); |
| 468 | p+=sizeof(image->storage_class); |
| 469 | (void) memcpy(&image->colorspace,p,sizeof(image->colorspace)); |
| 470 | p+=sizeof(image->colorspace); |
| 471 | (void) memcpy(&image->alpha_trait,p,sizeof(image->alpha_trait)); |
| 472 | p+=sizeof(image->alpha_trait); |
cristy | 883fde1 | 2013-04-08 00:50:13 +0000 | [diff] [blame] | 473 | (void) memcpy(&image->read_mask,p,sizeof(image->read_mask)); |
| 474 | p+=sizeof(image->read_mask); |
| 475 | (void) memcpy(&image->write_mask,p,sizeof(image->write_mask)); |
| 476 | p+=sizeof(image->write_mask); |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 477 | (void) memcpy(&image->columns,p,sizeof(image->columns)); |
| 478 | p+=sizeof(image->columns); |
| 479 | (void) memcpy(&image->rows,p,sizeof(image->rows)); |
| 480 | p+=sizeof(image->rows); |
| 481 | (void) memcpy(&image->number_channels,p,sizeof(image->number_channels)); |
| 482 | p+=sizeof(image->number_channels); |
cristy | 766c2f1 | 2013-01-25 02:46:26 +0000 | [diff] [blame] | 483 | (void) memcpy(image->channel_map,p,MaxPixelChannels* |
| 484 | sizeof(*image->channel_map)); |
| 485 | p+=MaxPixelChannels*sizeof(*image->channel_map); |
| 486 | (void) memcpy(&image->metacontent_extent,p,sizeof(image->metacontent_extent)); |
| 487 | p+=sizeof(image->metacontent_extent); |
cristy | 6c3bc85 | 2013-01-26 13:00:45 +0000 | [diff] [blame] | 488 | if (SyncImagePixelCache(image,exception) == MagickFalse) |
| 489 | return(MagickFalse); |
cristy | 066c4fb | 2013-01-19 02:36:14 +0000 | [diff] [blame] | 490 | status=AddValueToSplayTree(registry,(const void *) session_key,image); |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 491 | return(status); |
| 492 | } |
| 493 | |
cristy | 066c4fb | 2013-01-19 02:36:14 +0000 | [diff] [blame] | 494 | static MagickBooleanType ReadDistributeCacheMetacontent(SplayTreeInfo *registry, |
cristy | 2330a75 | 2013-01-28 13:19:51 +0000 | [diff] [blame] | 495 | int file,const size_t session_key,ExceptionInfo *exception) |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 496 | { |
cristy | b54f26e | 2013-01-17 01:44:39 +0000 | [diff] [blame] | 497 | const unsigned char |
| 498 | *metacontent; |
| 499 | |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 500 | Image |
| 501 | *image; |
| 502 | |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 503 | MagickOffsetType |
| 504 | count; |
| 505 | |
| 506 | MagickSizeType |
| 507 | length; |
| 508 | |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 509 | RectangleInfo |
| 510 | region; |
| 511 | |
| 512 | register const Quantum |
| 513 | *p; |
| 514 | |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 515 | register unsigned char |
| 516 | *q; |
| 517 | |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 518 | unsigned char |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 519 | message[MaxTextExtent]; |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 520 | |
cristy | feb2167 | 2013-01-23 00:12:55 +0000 | [diff] [blame] | 521 | /* |
| 522 | Read distributed pixel cache metacontent. |
| 523 | */ |
cristy | 066c4fb | 2013-01-19 02:36:14 +0000 | [diff] [blame] | 524 | image=(Image *) GetValueFromSplayTree(registry,(const void *) session_key); |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 525 | if (image == (Image *) NULL) |
| 526 | return(MagickFalse); |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 527 | length=sizeof(region.width)+sizeof(region.height)+sizeof(region.x)+ |
| 528 | sizeof(region.y)+sizeof(length); |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 529 | count=dpc_read(file,length,message); |
| 530 | if (count != (MagickOffsetType) length) |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 531 | return(MagickFalse); |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 532 | q=message; |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 533 | (void) memcpy(®ion.width,q,sizeof(region.width)); |
| 534 | q+=sizeof(region.width); |
| 535 | (void) memcpy(®ion.height,q,sizeof(region.height)); |
cristy | ffcb601 | 2013-01-26 02:16:19 +0000 | [diff] [blame] | 536 | q+=sizeof(region.height); |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 537 | (void) memcpy(®ion.x,q,sizeof(region.x)); |
cristy | ffcb601 | 2013-01-26 02:16:19 +0000 | [diff] [blame] | 538 | q+=sizeof(region.x); |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 539 | (void) memcpy(®ion.y,q,sizeof(region.y)); |
cristy | ffcb601 | 2013-01-26 02:16:19 +0000 | [diff] [blame] | 540 | q+=sizeof(region.y); |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 541 | (void) memcpy(&length,q,sizeof(length)); |
| 542 | q+=sizeof(length); |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 543 | p=GetVirtualPixels(image,region.x,region.y,region.width,region.height, |
| 544 | exception); |
cristy | e34745c | 2013-01-16 02:27:04 +0000 | [diff] [blame] | 545 | if (p == (const Quantum *) NULL) |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 546 | return(MagickFalse); |
cristy | 6d50170 | 2013-02-08 13:55:27 +0000 | [diff] [blame] | 547 | metacontent=(const unsigned char *) GetVirtualMetacontent(image); |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 548 | count=dpc_send(file,length,metacontent); |
| 549 | if (count != (MagickOffsetType) length) |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 550 | return(MagickFalse); |
| 551 | return(MagickTrue); |
| 552 | } |
cristy | e80f9cb | 2013-01-09 01:09:31 +0000 | [diff] [blame] | 553 | |
cristy | 066c4fb | 2013-01-19 02:36:14 +0000 | [diff] [blame] | 554 | static MagickBooleanType ReadDistributeCachePixels(SplayTreeInfo *registry, |
cristy | 2330a75 | 2013-01-28 13:19:51 +0000 | [diff] [blame] | 555 | int file,const size_t session_key,ExceptionInfo *exception) |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 556 | { |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 557 | Image |
| 558 | *image; |
| 559 | |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 560 | MagickOffsetType |
| 561 | count; |
| 562 | |
| 563 | MagickSizeType |
| 564 | length; |
| 565 | |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 566 | RectangleInfo |
| 567 | region; |
| 568 | |
| 569 | register const Quantum |
| 570 | *p; |
| 571 | |
| 572 | register unsigned char |
| 573 | *q; |
| 574 | |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 575 | unsigned char |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 576 | message[MaxTextExtent]; |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 577 | |
cristy | feb2167 | 2013-01-23 00:12:55 +0000 | [diff] [blame] | 578 | /* |
| 579 | Read distributed pixel cache pixels. |
| 580 | */ |
cristy | 066c4fb | 2013-01-19 02:36:14 +0000 | [diff] [blame] | 581 | image=(Image *) GetValueFromSplayTree(registry,(const void *) session_key); |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 582 | if (image == (Image *) NULL) |
| 583 | return(MagickFalse); |
| 584 | length=sizeof(region.width)+sizeof(region.height)+sizeof(region.x)+ |
| 585 | sizeof(region.y)+sizeof(length); |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 586 | count=dpc_read(file,length,message); |
| 587 | if (count != (MagickOffsetType) length) |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 588 | return(MagickFalse); |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 589 | q=message; |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 590 | (void) memcpy(®ion.width,q,sizeof(region.width)); |
| 591 | q+=sizeof(region.width); |
| 592 | (void) memcpy(®ion.height,q,sizeof(region.height)); |
cristy | ffcb601 | 2013-01-26 02:16:19 +0000 | [diff] [blame] | 593 | q+=sizeof(region.height); |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 594 | (void) memcpy(®ion.x,q,sizeof(region.x)); |
cristy | ffcb601 | 2013-01-26 02:16:19 +0000 | [diff] [blame] | 595 | q+=sizeof(region.x); |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 596 | (void) memcpy(®ion.y,q,sizeof(region.y)); |
cristy | ffcb601 | 2013-01-26 02:16:19 +0000 | [diff] [blame] | 597 | q+=sizeof(region.y); |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 598 | (void) memcpy(&length,q,sizeof(length)); |
| 599 | q+=sizeof(length); |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 600 | p=GetVirtualPixels(image,region.x,region.y,region.width,region.height, |
| 601 | exception); |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 602 | if (p == (const Quantum *) NULL) |
| 603 | return(MagickFalse); |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 604 | count=dpc_send(file,length,(unsigned char *) p); |
| 605 | if (count != (MagickOffsetType) length) |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 606 | return(MagickFalse); |
| 607 | return(MagickTrue); |
| 608 | } |
| 609 | |
cristy | 4b4a07e | 2013-01-22 17:07:56 +0000 | [diff] [blame] | 610 | static void *RelinquishImageRegistry(void *image) |
| 611 | { |
| 612 | return((void *) DestroyImageList((Image *) image)); |
| 613 | } |
| 614 | |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 615 | static MagickBooleanType WriteDistributeCacheMetacontent( |
cristy | 2330a75 | 2013-01-28 13:19:51 +0000 | [diff] [blame] | 616 | SplayTreeInfo *registry,int file,const size_t session_key, |
cristy | 81aa849 | 2013-01-18 19:12:43 +0000 | [diff] [blame] | 617 | ExceptionInfo *exception) |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 618 | { |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 619 | Image |
| 620 | *image; |
| 621 | |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 622 | MagickOffsetType |
| 623 | count; |
| 624 | |
| 625 | MagickSizeType |
| 626 | length; |
| 627 | |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 628 | RectangleInfo |
| 629 | region; |
| 630 | |
| 631 | register Quantum |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 632 | *q; |
| 633 | |
| 634 | register unsigned char |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 635 | *p; |
| 636 | |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 637 | unsigned char |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 638 | message[MaxTextExtent], |
cristy | b54f26e | 2013-01-17 01:44:39 +0000 | [diff] [blame] | 639 | *metacontent; |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 640 | |
cristy | feb2167 | 2013-01-23 00:12:55 +0000 | [diff] [blame] | 641 | /* |
| 642 | Write distributed pixel cache metacontent. |
| 643 | */ |
| 644 | image=(Image *) GetValueFromSplayTree(registry,(const void *) session_key); |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 645 | if (image == (Image *) NULL) |
| 646 | return(MagickFalse); |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 647 | length=sizeof(region.width)+sizeof(region.height)+sizeof(region.x)+ |
| 648 | sizeof(region.y)+sizeof(length); |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 649 | count=dpc_read(file,length,message); |
| 650 | if (count != (MagickOffsetType) length) |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 651 | return(MagickFalse); |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 652 | p=message; |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 653 | (void) memcpy(®ion.width,p,sizeof(region.width)); |
| 654 | p+=sizeof(region.width); |
| 655 | (void) memcpy(®ion.height,p,sizeof(region.height)); |
cristy | ffcb601 | 2013-01-26 02:16:19 +0000 | [diff] [blame] | 656 | p+=sizeof(region.height); |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 657 | (void) memcpy(®ion.x,p,sizeof(region.x)); |
cristy | ffcb601 | 2013-01-26 02:16:19 +0000 | [diff] [blame] | 658 | p+=sizeof(region.x); |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 659 | (void) memcpy(®ion.y,p,sizeof(region.y)); |
cristy | ffcb601 | 2013-01-26 02:16:19 +0000 | [diff] [blame] | 660 | p+=sizeof(region.y); |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 661 | (void) memcpy(&length,p,sizeof(length)); |
| 662 | p+=sizeof(length); |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 663 | q=GetAuthenticPixels(image,region.x,region.y,region.width,region.height, |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 664 | exception); |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 665 | if (q == (Quantum *) NULL) |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 666 | return(MagickFalse); |
cristy | 6d50170 | 2013-02-08 13:55:27 +0000 | [diff] [blame] | 667 | metacontent=(unsigned char *) GetAuthenticMetacontent(image); |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 668 | count=dpc_read(file,length,metacontent); |
| 669 | if (count != (MagickOffsetType) length) |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 670 | return(MagickFalse); |
cristy | 7708b0b | 2013-01-26 03:03:29 +0000 | [diff] [blame] | 671 | return(SyncAuthenticPixels(image,exception)); |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 672 | } |
| 673 | |
cristy | 066c4fb | 2013-01-19 02:36:14 +0000 | [diff] [blame] | 674 | static MagickBooleanType WriteDistributeCachePixels(SplayTreeInfo *registry, |
cristy | 2330a75 | 2013-01-28 13:19:51 +0000 | [diff] [blame] | 675 | int file,const size_t session_key,ExceptionInfo *exception) |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 676 | { |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 677 | Image |
| 678 | *image; |
| 679 | |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 680 | MagickOffsetType |
| 681 | count; |
| 682 | |
| 683 | MagickSizeType |
| 684 | length; |
| 685 | |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 686 | RectangleInfo |
| 687 | region; |
| 688 | |
| 689 | register Quantum |
| 690 | *q; |
| 691 | |
| 692 | register unsigned char |
| 693 | *p; |
| 694 | |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 695 | unsigned char |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 696 | message[MaxTextExtent]; |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 697 | |
cristy | feb2167 | 2013-01-23 00:12:55 +0000 | [diff] [blame] | 698 | /* |
| 699 | Write distributed pixel cache pixels. |
| 700 | */ |
cristy | 066c4fb | 2013-01-19 02:36:14 +0000 | [diff] [blame] | 701 | image=(Image *) GetValueFromSplayTree(registry,(const void *) session_key); |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 702 | if (image == (Image *) NULL) |
| 703 | return(MagickFalse); |
| 704 | length=sizeof(region.width)+sizeof(region.height)+sizeof(region.x)+ |
| 705 | sizeof(region.y)+sizeof(length); |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 706 | count=dpc_read(file,length,message); |
| 707 | if (count != (MagickOffsetType) length) |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 708 | return(MagickFalse); |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 709 | p=message; |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 710 | (void) memcpy(®ion.width,p,sizeof(region.width)); |
| 711 | p+=sizeof(region.width); |
| 712 | (void) memcpy(®ion.height,p,sizeof(region.height)); |
cristy | ffcb601 | 2013-01-26 02:16:19 +0000 | [diff] [blame] | 713 | p+=sizeof(region.height); |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 714 | (void) memcpy(®ion.x,p,sizeof(region.x)); |
cristy | ffcb601 | 2013-01-26 02:16:19 +0000 | [diff] [blame] | 715 | p+=sizeof(region.x); |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 716 | (void) memcpy(®ion.y,p,sizeof(region.y)); |
cristy | ffcb601 | 2013-01-26 02:16:19 +0000 | [diff] [blame] | 717 | p+=sizeof(region.y); |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 718 | (void) memcpy(&length,p,sizeof(length)); |
| 719 | p+=sizeof(length); |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 720 | q=GetAuthenticPixels(image,region.x,region.y,region.width,region.height, |
| 721 | exception); |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 722 | if (q == (Quantum *) NULL) |
| 723 | return(MagickFalse); |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 724 | count=dpc_read(file,length,(unsigned char *) q); |
| 725 | if (count != (MagickOffsetType) length) |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 726 | return(MagickFalse); |
cristy | 7708b0b | 2013-01-26 03:03:29 +0000 | [diff] [blame] | 727 | return(SyncAuthenticPixels(image,exception)); |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 728 | } |
| 729 | |
cristy | 81aa849 | 2013-01-18 19:12:43 +0000 | [diff] [blame] | 730 | static void *DistributePixelCacheClient(void *socket) |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 731 | { |
| 732 | const char |
| 733 | *shared_secret; |
| 734 | |
cristy | 81aa849 | 2013-01-18 19:12:43 +0000 | [diff] [blame] | 735 | ExceptionInfo |
| 736 | *exception; |
| 737 | |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 738 | int |
cristy | e34745c | 2013-01-16 02:27:04 +0000 | [diff] [blame] | 739 | client_socket; |
| 740 | |
| 741 | MagickBooleanType |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 742 | status; |
| 743 | |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 744 | MagickOffsetType |
| 745 | count; |
| 746 | |
cristy | c6c7684 | 2013-01-23 18:32:26 +0000 | [diff] [blame] | 747 | register unsigned char |
| 748 | *p; |
| 749 | |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 750 | RandomInfo |
| 751 | *random_info; |
| 752 | |
cristy | 2330a75 | 2013-01-28 13:19:51 +0000 | [diff] [blame] | 753 | size_t |
| 754 | key, |
cristy | 410133d | 2013-02-05 20:06:52 +0000 | [diff] [blame] | 755 | session_key; |
cristy | 2330a75 | 2013-01-28 13:19:51 +0000 | [diff] [blame] | 756 | |
cristy | e34745c | 2013-01-16 02:27:04 +0000 | [diff] [blame] | 757 | SplayTreeInfo |
cristy | 066c4fb | 2013-01-19 02:36:14 +0000 | [diff] [blame] | 758 | *registry; |
cristy | e34745c | 2013-01-16 02:27:04 +0000 | [diff] [blame] | 759 | |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 760 | StringInfo |
| 761 | *secret; |
| 762 | |
| 763 | unsigned char |
| 764 | command, |
cristy | c6c7684 | 2013-01-23 18:32:26 +0000 | [diff] [blame] | 765 | session[2*MaxTextExtent]; |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 766 | |
| 767 | /* |
cristy | feb2167 | 2013-01-23 00:12:55 +0000 | [diff] [blame] | 768 | Distributed pixel cache client. |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 769 | */ |
| 770 | shared_secret=GetPolicyValue("shared-secret"); |
| 771 | if (shared_secret == (const char *) NULL) |
| 772 | ThrowFatalException(CacheFatalError,"shared secret expected"); |
cristy | c6c7684 | 2013-01-23 18:32:26 +0000 | [diff] [blame] | 773 | p=session; |
| 774 | (void) CopyMagickString((char *) p,shared_secret,MaxTextExtent); |
| 775 | p+=strlen(shared_secret); |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 776 | random_info=AcquireRandomInfo(); |
| 777 | secret=GetRandomKey(random_info,DPCSessionKeyLength); |
cristy | c6c7684 | 2013-01-23 18:32:26 +0000 | [diff] [blame] | 778 | (void) memcpy(p,GetStringInfoDatum(secret),DPCSessionKeyLength); |
cristy | 410133d | 2013-02-05 20:06:52 +0000 | [diff] [blame] | 779 | session_key=GetMagickSignature(secret); |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 780 | random_info=DestroyRandomInfo(random_info); |
cristy | 81aa849 | 2013-01-18 19:12:43 +0000 | [diff] [blame] | 781 | exception=AcquireExceptionInfo(); |
cristy | 066c4fb | 2013-01-19 02:36:14 +0000 | [diff] [blame] | 782 | registry=NewSplayTree((int (*)(const void *,const void *)) NULL, |
cristy | 4b4a07e | 2013-01-22 17:07:56 +0000 | [diff] [blame] | 783 | (void *(*)(void *)) NULL,RelinquishImageRegistry); |
cristy | 81aa849 | 2013-01-18 19:12:43 +0000 | [diff] [blame] | 784 | client_socket=(*(int *) socket); |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 785 | count=dpc_send(client_socket,DPCSessionKeyLength,GetStringInfoDatum(secret)); |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 786 | secret=DestroyStringInfo(secret); |
cristy | e80f9cb | 2013-01-09 01:09:31 +0000 | [diff] [blame] | 787 | for ( ; ; ) |
| 788 | { |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 789 | count=dpc_read(client_socket,1,(unsigned char *) &command); |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 790 | if (count <= 0) |
| 791 | break; |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 792 | count=dpc_read(client_socket,sizeof(key),(unsigned char *) &key); |
cristy | c6c7684 | 2013-01-23 18:32:26 +0000 | [diff] [blame] | 793 | if ((count != (MagickOffsetType) sizeof(key)) || (key != session_key)) |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 794 | break; |
| 795 | status=MagickFalse; |
| 796 | switch (command) |
| 797 | { |
cristy | 9c3f05b | 2013-01-17 18:51:14 +0000 | [diff] [blame] | 798 | case 'o': |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 799 | { |
cristy | 066c4fb | 2013-01-19 02:36:14 +0000 | [diff] [blame] | 800 | status=OpenDistributeCache(registry,client_socket,session_key, |
cristy | 81aa849 | 2013-01-18 19:12:43 +0000 | [diff] [blame] | 801 | exception); |
cristy | 8cca92e | 2013-01-23 21:00:51 +0000 | [diff] [blame] | 802 | count=dpc_send(client_socket,sizeof(status),(unsigned char *) &status); |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 803 | break; |
| 804 | } |
| 805 | case 'r': |
| 806 | { |
cristy | 066c4fb | 2013-01-19 02:36:14 +0000 | [diff] [blame] | 807 | status=ReadDistributeCachePixels(registry,client_socket,session_key, |
| 808 | exception); |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 809 | break; |
| 810 | } |
cristy | 9c3f05b | 2013-01-17 18:51:14 +0000 | [diff] [blame] | 811 | case 'R': |
| 812 | { |
cristy | 066c4fb | 2013-01-19 02:36:14 +0000 | [diff] [blame] | 813 | status=ReadDistributeCacheMetacontent(registry,client_socket, |
cristy | 81aa849 | 2013-01-18 19:12:43 +0000 | [diff] [blame] | 814 | session_key,exception); |
cristy | 9c3f05b | 2013-01-17 18:51:14 +0000 | [diff] [blame] | 815 | break; |
| 816 | } |
| 817 | case 'w': |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 818 | { |
cristy | 066c4fb | 2013-01-19 02:36:14 +0000 | [diff] [blame] | 819 | status=WriteDistributeCachePixels(registry,client_socket,session_key, |
| 820 | exception); |
cristy | e34745c | 2013-01-16 02:27:04 +0000 | [diff] [blame] | 821 | break; |
| 822 | } |
cristy | 9c3f05b | 2013-01-17 18:51:14 +0000 | [diff] [blame] | 823 | case 'W': |
| 824 | { |
cristy | 066c4fb | 2013-01-19 02:36:14 +0000 | [diff] [blame] | 825 | status=WriteDistributeCacheMetacontent(registry,client_socket, |
cristy | 81aa849 | 2013-01-18 19:12:43 +0000 | [diff] [blame] | 826 | session_key,exception); |
cristy | 9c3f05b | 2013-01-17 18:51:14 +0000 | [diff] [blame] | 827 | break; |
| 828 | } |
cristy | e34745c | 2013-01-16 02:27:04 +0000 | [diff] [blame] | 829 | case 'd': |
| 830 | { |
cristy | 066c4fb | 2013-01-19 02:36:14 +0000 | [diff] [blame] | 831 | status=DestroyDistributeCache(registry,client_socket,session_key); |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 832 | break; |
| 833 | } |
| 834 | default: |
| 835 | break; |
| 836 | } |
cristy | feb2167 | 2013-01-23 00:12:55 +0000 | [diff] [blame] | 837 | if (status == MagickFalse) |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 838 | break; |
cristy | 2f0c1f9 | 2013-01-18 14:45:19 +0000 | [diff] [blame] | 839 | if (command == 'd') |
| 840 | break; |
cristy | e80f9cb | 2013-01-09 01:09:31 +0000 | [diff] [blame] | 841 | } |
cristy | 8cca92e | 2013-01-23 21:00:51 +0000 | [diff] [blame] | 842 | count=dpc_send(client_socket,sizeof(status),(unsigned char *) &status); |
cristy | 194e886 | 2013-01-17 01:54:39 +0000 | [diff] [blame] | 843 | (void) close(client_socket); |
cristy | 81aa849 | 2013-01-18 19:12:43 +0000 | [diff] [blame] | 844 | exception=DestroyExceptionInfo(exception); |
cristy | 066c4fb | 2013-01-19 02:36:14 +0000 | [diff] [blame] | 845 | registry=DestroySplayTree(registry); |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 846 | return((void *) NULL); |
| 847 | } |
| 848 | |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 849 | MagickExport void DistributePixelCacheServer(const int port, |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 850 | ExceptionInfo *exception) |
| 851 | { |
cristy | 80b9501 | 2013-04-23 16:29:17 +0000 | [diff] [blame] | 852 | #if defined(MAGICKCORE_HAVE_SOCKET) && defined(MAGICKCORE_HAVE_PTHREAD) |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 853 | char |
| 854 | service[MaxTextExtent]; |
| 855 | |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 856 | int |
| 857 | server_socket, |
| 858 | status; |
| 859 | |
| 860 | pthread_attr_t |
| 861 | attributes; |
| 862 | |
| 863 | pthread_t |
cristy | 81aa849 | 2013-01-18 19:12:43 +0000 | [diff] [blame] | 864 | threads; |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 865 | |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 866 | register struct addrinfo |
| 867 | *p; |
| 868 | |
| 869 | struct addrinfo |
| 870 | hint, |
| 871 | *result; |
| 872 | |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 873 | struct sockaddr_in |
| 874 | address; |
| 875 | |
| 876 | /* |
| 877 | Launch distributed pixel cache server. |
| 878 | */ |
cristy | b0de93f | 2013-05-03 13:39:25 +0000 | [diff] [blame] | 879 | assert(exception != (ExceptionInfo *) NULL); |
| 880 | assert(exception->signature == MagickSignature); |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 881 | (void) ResetMagickMemory(&hint,0,sizeof(hint)); |
| 882 | hint.ai_family=AF_INET; |
| 883 | hint.ai_socktype=SOCK_STREAM; |
| 884 | hint.ai_flags=AI_PASSIVE; |
| 885 | (void) FormatLocaleString(service,MaxTextExtent,"%d",port); |
| 886 | status=getaddrinfo((const char *) NULL,service,&hint,&result); |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 887 | if (status != 0) |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 888 | ThrowFatalException(CacheFatalError,"UnableToListen"); |
cristy | 6be6219 | 2013-01-29 17:24:22 +0000 | [diff] [blame] | 889 | server_socket=0; |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 890 | for (p=result; p != (struct addrinfo *) NULL; p=p->ai_next) |
| 891 | { |
| 892 | int |
| 893 | one; |
| 894 | |
| 895 | server_socket=socket(p->ai_family,p->ai_socktype,p->ai_protocol); |
| 896 | if (server_socket == -1) |
| 897 | continue; |
| 898 | one=1; |
| 899 | status=setsockopt(server_socket,SOL_SOCKET,SO_REUSEADDR,&one,(socklen_t) |
| 900 | sizeof(one)); |
| 901 | if (status == -1) |
| 902 | continue; |
| 903 | status=bind(server_socket,p->ai_addr,p->ai_addrlen); |
| 904 | if (status == -1) |
| 905 | { |
| 906 | (void) close(status); |
| 907 | continue; |
| 908 | } |
| 909 | break; |
| 910 | } |
| 911 | if (p == (struct addrinfo *) NULL) |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 912 | ThrowFatalException(CacheFatalError,"UnableToBind"); |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 913 | freeaddrinfo(result); |
| 914 | status=listen(server_socket,DPCPendingConnections); |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 915 | if (status != 0) |
| 916 | ThrowFatalException(CacheFatalError,"UnableToListen"); |
| 917 | pthread_attr_init(&attributes); |
| 918 | for ( ; ; ) |
| 919 | { |
| 920 | int |
| 921 | client_socket; |
| 922 | |
| 923 | socklen_t |
| 924 | length; |
| 925 | |
| 926 | length=(socklen_t) sizeof(address); |
| 927 | client_socket=accept(server_socket,(struct sockaddr *) &address,&length); |
| 928 | if (client_socket == -1) |
| 929 | ThrowFatalException(CacheFatalError,"UnableToEstablishConnection"); |
cristy | 81aa849 | 2013-01-18 19:12:43 +0000 | [diff] [blame] | 930 | status=pthread_create(&threads,&attributes,DistributePixelCacheClient, |
| 931 | (void *) &client_socket); |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 932 | if (status == -1) |
| 933 | ThrowFatalException(CacheFatalError,"UnableToCreateClientThread"); |
| 934 | } |
| 935 | (void) close(server_socket); |
cristy | e80f9cb | 2013-01-09 01:09:31 +0000 | [diff] [blame] | 936 | #else |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 937 | ThrowFatalException(MissingDelegateError,"distributed pixel cache"); |
cristy | e80f9cb | 2013-01-09 01:09:31 +0000 | [diff] [blame] | 938 | #endif |
| 939 | } |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 940 | |
| 941 | /* |
| 942 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 943 | % % |
| 944 | % % |
| 945 | % % |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 946 | + G e t D i s t r i b u t e C a c h e F i l e % |
| 947 | % % |
| 948 | % % |
| 949 | % % |
| 950 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 951 | % |
| 952 | % GetDistributeCacheFile() returns the file associated with this |
| 953 | % DistributeCacheInfo structure. |
| 954 | % |
| 955 | % The format of the GetDistributeCacheFile method is: |
| 956 | % |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 957 | % int GetDistributeCacheFile(const DistributeCacheInfo *server_info) |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 958 | % |
| 959 | % A description of each parameter follows: |
| 960 | % |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 961 | % o server_info: the distributed cache info. |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 962 | % |
| 963 | */ |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 964 | MagickPrivate int GetDistributeCacheFile(const DistributeCacheInfo *server_info) |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 965 | { |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 966 | assert(server_info != (DistributeCacheInfo *) NULL); |
| 967 | assert(server_info->signature == MagickSignature); |
| 968 | return(server_info->file); |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 969 | } |
| 970 | |
| 971 | /* |
| 972 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 973 | % % |
| 974 | % % |
| 975 | % % |
| 976 | + G e t D i s t r i b u t e C a c h e H o s t n a m e % |
| 977 | % % |
| 978 | % % |
| 979 | % % |
| 980 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 981 | % |
| 982 | % GetDistributeCacheHostname() returns the hostname associated with this |
| 983 | % DistributeCacheInfo structure. |
| 984 | % |
| 985 | % The format of the GetDistributeCacheHostname method is: |
| 986 | % |
| 987 | % const char *GetDistributeCacheHostname( |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 988 | % const DistributeCacheInfo *server_info) |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 989 | % |
| 990 | % A description of each parameter follows: |
| 991 | % |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 992 | % o server_info: the distributed cache info. |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 993 | % |
| 994 | */ |
| 995 | MagickPrivate const char *GetDistributeCacheHostname( |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 996 | const DistributeCacheInfo *server_info) |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 997 | { |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 998 | assert(server_info != (DistributeCacheInfo *) NULL); |
| 999 | assert(server_info->signature == MagickSignature); |
| 1000 | return(server_info->hostname); |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | /* |
| 1004 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1005 | % % |
| 1006 | % % |
| 1007 | % % |
| 1008 | + G e t D i s t r i b u t e C a c h e P o r t % |
| 1009 | % % |
| 1010 | % % |
| 1011 | % % |
| 1012 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1013 | % |
| 1014 | % GetDistributeCachePort() returns the port associated with this |
| 1015 | % DistributeCacheInfo structure. |
| 1016 | % |
| 1017 | % The format of the GetDistributeCachePort method is: |
| 1018 | % |
cristy | 066c4fb | 2013-01-19 02:36:14 +0000 | [diff] [blame] | 1019 | % int GetDistributeCachePort(const DistributeCacheInfo *server_info) |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1020 | % |
| 1021 | % A description of each parameter follows: |
| 1022 | % |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 1023 | % o server_info: the distributed cache info. |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1024 | % |
| 1025 | */ |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 1026 | MagickPrivate int GetDistributeCachePort(const DistributeCacheInfo *server_info) |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1027 | { |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 1028 | assert(server_info != (DistributeCacheInfo *) NULL); |
| 1029 | assert(server_info->signature == MagickSignature); |
| 1030 | return(server_info->port); |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1031 | } |
| 1032 | |
| 1033 | /* |
| 1034 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1035 | % % |
| 1036 | % % |
| 1037 | % % |
cristy | 43940f4 | 2013-01-17 00:24:06 +0000 | [diff] [blame] | 1038 | + O p e n D i s t r i b u t e P i x e l C a c h e % |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 1039 | % % |
| 1040 | % % |
| 1041 | % % |
| 1042 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1043 | % |
| 1044 | % OpenDistributePixelCache() opens a pixel cache on a remote server. |
| 1045 | % |
| 1046 | % The format of the OpenDistributePixelCache method is: |
| 1047 | % |
| 1048 | % MagickBooleanType *OpenDistributePixelCache( |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 1049 | % DistributeCacheInfo *server_info,Image *image) |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 1050 | % |
| 1051 | % A description of each parameter follows: |
| 1052 | % |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 1053 | % o server_info: the distributed cache info. |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 1054 | % |
| 1055 | % o image: the image. |
| 1056 | % |
| 1057 | */ |
| 1058 | MagickPrivate MagickBooleanType OpenDistributePixelCache( |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 1059 | DistributeCacheInfo *server_info,Image *image) |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 1060 | { |
cristy | 8cca92e | 2013-01-23 21:00:51 +0000 | [diff] [blame] | 1061 | MagickBooleanType |
| 1062 | status; |
| 1063 | |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 1064 | MagickOffsetType |
| 1065 | count; |
| 1066 | |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1067 | register unsigned char |
| 1068 | *p; |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 1069 | |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1070 | unsigned char |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 1071 | message[MaxTextExtent]; |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1072 | |
cristy | feb2167 | 2013-01-23 00:12:55 +0000 | [diff] [blame] | 1073 | /* |
| 1074 | Open distributed pixel cache. |
| 1075 | */ |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 1076 | assert(server_info != (DistributeCacheInfo *) NULL); |
| 1077 | assert(server_info->signature == MagickSignature); |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 1078 | assert(image != (Image *) NULL); |
| 1079 | assert(image->signature == MagickSignature); |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 1080 | p=message; |
cristy | 9c3f05b | 2013-01-17 18:51:14 +0000 | [diff] [blame] | 1081 | *p++='o'; /* open */ |
cristy | 766c2f1 | 2013-01-25 02:46:26 +0000 | [diff] [blame] | 1082 | /* |
| 1083 | Serialize image attributes (see ValidatePixelCacheMorphology()). |
| 1084 | */ |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 1085 | (void) memcpy(p,&server_info->session_key,sizeof(server_info->session_key)); |
| 1086 | p+=sizeof(server_info->session_key); |
cristy | 766c2f1 | 2013-01-25 02:46:26 +0000 | [diff] [blame] | 1087 | (void) memcpy(p,&image->storage_class,sizeof(image->storage_class)); |
| 1088 | p+=sizeof(image->storage_class); |
| 1089 | (void) memcpy(p,&image->colorspace,sizeof(image->colorspace)); |
| 1090 | p+=sizeof(image->colorspace); |
| 1091 | (void) memcpy(p,&image->alpha_trait,sizeof(image->alpha_trait)); |
| 1092 | p+=sizeof(image->alpha_trait); |
cristy | 883fde1 | 2013-04-08 00:50:13 +0000 | [diff] [blame] | 1093 | (void) memcpy(p,&image->read_mask,sizeof(image->read_mask)); |
| 1094 | p+=sizeof(image->read_mask); |
| 1095 | (void) memcpy(p,&image->write_mask,sizeof(image->write_mask)); |
| 1096 | p+=sizeof(image->write_mask); |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1097 | (void) memcpy(p,&image->columns,sizeof(image->columns)); |
| 1098 | p+=sizeof(image->columns); |
| 1099 | (void) memcpy(p,&image->rows,sizeof(image->rows)); |
| 1100 | p+=sizeof(image->rows); |
| 1101 | (void) memcpy(p,&image->number_channels,sizeof(image->number_channels)); |
| 1102 | p+=sizeof(image->number_channels); |
cristy | 766c2f1 | 2013-01-25 02:46:26 +0000 | [diff] [blame] | 1103 | (void) memcpy(p,image->channel_map,MaxPixelChannels* |
| 1104 | sizeof(*image->channel_map)); |
| 1105 | p+=MaxPixelChannels*sizeof(*image->channel_map); |
| 1106 | (void) memcpy(p,&image->metacontent_extent,sizeof(image->metacontent_extent)); |
| 1107 | p+=sizeof(image->metacontent_extent); |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 1108 | count=dpc_send(server_info->file,p-message,message); |
| 1109 | if (count != (MagickOffsetType) (p-message)) |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 1110 | return(MagickFalse); |
cristy | 8cca92e | 2013-01-23 21:00:51 +0000 | [diff] [blame] | 1111 | status=MagickFalse; |
| 1112 | count=dpc_read(server_info->file,sizeof(status),(unsigned char *) &status); |
| 1113 | if (count != (MagickOffsetType) sizeof(status)) |
| 1114 | return(MagickFalse); |
| 1115 | return(status); |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | /* |
| 1119 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1120 | % % |
| 1121 | % % |
| 1122 | % % |
cristy | 43940f4 | 2013-01-17 00:24:06 +0000 | [diff] [blame] | 1123 | + R e a d D i s t r i b u t e P i x e l C a c h e M e t a c o n t e n t % |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 1124 | % % |
| 1125 | % % |
| 1126 | % % |
| 1127 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1128 | % |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1129 | % ReadDistributePixelCacheMetacontents() reads metacontent from the specified |
| 1130 | % region of the distributed pixel cache. |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 1131 | % |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1132 | % The format of the ReadDistributePixelCacheMetacontents method is: |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 1133 | % |
cristy | d6e5ed3 | 2013-01-19 17:24:56 +0000 | [diff] [blame] | 1134 | % MagickOffsetType ReadDistributePixelCacheMetacontents( |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 1135 | % DistributeCacheInfo *server_info,const RectangleInfo *region, |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1136 | % const MagickSizeType length,unsigned char *metacontent) |
| 1137 | % |
| 1138 | % A description of each parameter follows: |
| 1139 | % |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 1140 | % o server_info: the distributed cache info. |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1141 | % |
| 1142 | % o image: the image. |
| 1143 | % |
| 1144 | % o region: read the metacontent from this region of the image. |
| 1145 | % |
cristy | a4eb3d6 | 2013-01-17 00:36:58 +0000 | [diff] [blame] | 1146 | % o length: the length in bytes of the metacontent. |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1147 | % |
| 1148 | % o metacontent: read these metacontent from the pixel cache. |
| 1149 | % |
| 1150 | */ |
cristy | d6e5ed3 | 2013-01-19 17:24:56 +0000 | [diff] [blame] | 1151 | MagickPrivate MagickOffsetType ReadDistributePixelCacheMetacontent( |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 1152 | DistributeCacheInfo *server_info,const RectangleInfo *region, |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1153 | const MagickSizeType length,unsigned char *metacontent) |
| 1154 | { |
cristy | d6e5ed3 | 2013-01-19 17:24:56 +0000 | [diff] [blame] | 1155 | MagickOffsetType |
| 1156 | count; |
| 1157 | |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1158 | register unsigned char |
| 1159 | *p; |
| 1160 | |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1161 | unsigned char |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 1162 | message[MaxTextExtent]; |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1163 | |
cristy | feb2167 | 2013-01-23 00:12:55 +0000 | [diff] [blame] | 1164 | /* |
| 1165 | Read distributed pixel cache metacontent. |
| 1166 | */ |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 1167 | assert(server_info != (DistributeCacheInfo *) NULL); |
| 1168 | assert(server_info->signature == MagickSignature); |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1169 | assert(region != (RectangleInfo *) NULL); |
| 1170 | assert(metacontent != (unsigned char *) NULL); |
cristy | 766c2f1 | 2013-01-25 02:46:26 +0000 | [diff] [blame] | 1171 | if (length > (MagickSizeType) SSIZE_MAX) |
cristy | d6e5ed3 | 2013-01-19 17:24:56 +0000 | [diff] [blame] | 1172 | return(-1); |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 1173 | p=message; |
cristy | feb2167 | 2013-01-23 00:12:55 +0000 | [diff] [blame] | 1174 | *p++='R'; |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 1175 | (void) memcpy(p,&server_info->session_key,sizeof(server_info->session_key)); |
| 1176 | p+=sizeof(server_info->session_key); |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1177 | (void) memcpy(p,®ion->width,sizeof(region->width)); |
| 1178 | p+=sizeof(region->width); |
| 1179 | (void) memcpy(p,®ion->height,sizeof(region->height)); |
| 1180 | p+=sizeof(region->height); |
| 1181 | (void) memcpy(p,®ion->x,sizeof(region->x)); |
| 1182 | p+=sizeof(region->x); |
| 1183 | (void) memcpy(p,®ion->y,sizeof(region->y)); |
| 1184 | p+=sizeof(region->y); |
| 1185 | (void) memcpy(p,&length,sizeof(length)); |
| 1186 | p+=sizeof(length); |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 1187 | count=dpc_send(server_info->file,p-message,message); |
| 1188 | if (count != (MagickOffsetType) (p-message)) |
cristy | d6e5ed3 | 2013-01-19 17:24:56 +0000 | [diff] [blame] | 1189 | return(-1); |
cristy | feb2167 | 2013-01-23 00:12:55 +0000 | [diff] [blame] | 1190 | return(dpc_read(server_info->file,length,metacontent)); |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1191 | } |
| 1192 | |
| 1193 | /* |
| 1194 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1195 | % % |
| 1196 | % % |
| 1197 | % % |
cristy | 43940f4 | 2013-01-17 00:24:06 +0000 | [diff] [blame] | 1198 | + R e a d D i s t r i b u t e P i x e l C a c h e P i x e l s % |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1199 | % % |
| 1200 | % % |
| 1201 | % % |
| 1202 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1203 | % |
| 1204 | % ReadDistributePixelCachePixels() reads pixels from the specified region of |
| 1205 | % the distributed pixel cache. |
| 1206 | % |
| 1207 | % The format of the ReadDistributePixelCachePixels method is: |
| 1208 | % |
cristy | d6e5ed3 | 2013-01-19 17:24:56 +0000 | [diff] [blame] | 1209 | % MagickOffsetType ReadDistributePixelCachePixels( |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 1210 | % DistributeCacheInfo *server_info,const RectangleInfo *region, |
cristy | 1d1254d | 2013-04-19 16:12:56 +0000 | [diff] [blame] | 1211 | % const MagickSizeType length,unsigned char *restrict pixels) |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 1212 | % |
| 1213 | % A description of each parameter follows: |
| 1214 | % |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 1215 | % o server_info: the distributed cache info. |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 1216 | % |
| 1217 | % o image: the image. |
| 1218 | % |
| 1219 | % o region: read the pixels from this region of the image. |
| 1220 | % |
cristy | a4eb3d6 | 2013-01-17 00:36:58 +0000 | [diff] [blame] | 1221 | % o length: the length in bytes of the pixels. |
cristy | e34745c | 2013-01-16 02:27:04 +0000 | [diff] [blame] | 1222 | % |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 1223 | % o pixels: read these pixels from the pixel cache. |
| 1224 | % |
| 1225 | */ |
cristy | d6e5ed3 | 2013-01-19 17:24:56 +0000 | [diff] [blame] | 1226 | MagickPrivate MagickOffsetType ReadDistributePixelCachePixels( |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 1227 | DistributeCacheInfo *server_info,const RectangleInfo *region, |
cristy | 1d1254d | 2013-04-19 16:12:56 +0000 | [diff] [blame] | 1228 | const MagickSizeType length,unsigned char *restrict pixels) |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 1229 | { |
cristy | d6e5ed3 | 2013-01-19 17:24:56 +0000 | [diff] [blame] | 1230 | MagickOffsetType |
| 1231 | count; |
| 1232 | |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1233 | register unsigned char |
| 1234 | *p; |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 1235 | |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1236 | unsigned char |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 1237 | message[MaxTextExtent]; |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1238 | |
cristy | feb2167 | 2013-01-23 00:12:55 +0000 | [diff] [blame] | 1239 | /* |
| 1240 | Read distributed pixel cache pixels. |
| 1241 | */ |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 1242 | assert(server_info != (DistributeCacheInfo *) NULL); |
| 1243 | assert(server_info->signature == MagickSignature); |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 1244 | assert(region != (RectangleInfo *) NULL); |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1245 | assert(pixels != (unsigned char *) NULL); |
cristy | 766c2f1 | 2013-01-25 02:46:26 +0000 | [diff] [blame] | 1246 | if (length > (MagickSizeType) SSIZE_MAX) |
cristy | d6e5ed3 | 2013-01-19 17:24:56 +0000 | [diff] [blame] | 1247 | return(-1); |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 1248 | p=message; |
cristy | feb2167 | 2013-01-23 00:12:55 +0000 | [diff] [blame] | 1249 | *p++='r'; |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 1250 | (void) memcpy(p,&server_info->session_key,sizeof(server_info->session_key)); |
| 1251 | p+=sizeof(server_info->session_key); |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1252 | (void) memcpy(p,®ion->width,sizeof(region->width)); |
| 1253 | p+=sizeof(region->width); |
| 1254 | (void) memcpy(p,®ion->height,sizeof(region->height)); |
| 1255 | p+=sizeof(region->height); |
| 1256 | (void) memcpy(p,®ion->x,sizeof(region->x)); |
| 1257 | p+=sizeof(region->x); |
| 1258 | (void) memcpy(p,®ion->y,sizeof(region->y)); |
| 1259 | p+=sizeof(region->y); |
| 1260 | (void) memcpy(p,&length,sizeof(length)); |
| 1261 | p+=sizeof(length); |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 1262 | count=dpc_send(server_info->file,p-message,message); |
| 1263 | if (count != (MagickOffsetType) (p-message)) |
cristy | d6e5ed3 | 2013-01-19 17:24:56 +0000 | [diff] [blame] | 1264 | return(-1); |
cristy | feb2167 | 2013-01-23 00:12:55 +0000 | [diff] [blame] | 1265 | return(dpc_read(server_info->file,length,pixels)); |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 1266 | } |
| 1267 | |
| 1268 | /* |
| 1269 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1270 | % % |
| 1271 | % % |
| 1272 | % % |
cristy | 43940f4 | 2013-01-17 00:24:06 +0000 | [diff] [blame] | 1273 | + R e l i n q u i s h D i s t r i b u t e P i x e l C a c h e % |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 1274 | % % |
| 1275 | % % |
| 1276 | % % |
| 1277 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1278 | % |
| 1279 | % RelinquishDistributePixelCache() frees resources acquired with |
| 1280 | % OpenDistributePixelCache(). |
| 1281 | % |
| 1282 | % The format of the RelinquishDistributePixelCache method is: |
| 1283 | % |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1284 | % MagickBooleanType RelinquishDistributePixelCache( |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 1285 | % DistributeCacheInfo *server_info) |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 1286 | % |
| 1287 | % A description of each parameter follows: |
| 1288 | % |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 1289 | % o server_info: the distributed cache info. |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 1290 | % |
| 1291 | */ |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1292 | MagickPrivate MagickBooleanType RelinquishDistributePixelCache( |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 1293 | DistributeCacheInfo *server_info) |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 1294 | { |
cristy | 3349e17 | 2013-01-25 20:05:18 +0000 | [diff] [blame] | 1295 | MagickBooleanType |
| 1296 | status; |
| 1297 | |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 1298 | MagickOffsetType |
| 1299 | count; |
| 1300 | |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1301 | register unsigned char |
| 1302 | *p; |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 1303 | |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1304 | unsigned char |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 1305 | message[MaxTextExtent]; |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 1306 | |
cristy | feb2167 | 2013-01-23 00:12:55 +0000 | [diff] [blame] | 1307 | /* |
| 1308 | Delete distributed pixel cache. |
| 1309 | */ |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 1310 | assert(server_info != (DistributeCacheInfo *) NULL); |
| 1311 | assert(server_info->signature == MagickSignature); |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 1312 | p=message; |
cristy | feb2167 | 2013-01-23 00:12:55 +0000 | [diff] [blame] | 1313 | *p++='d'; |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 1314 | (void) memcpy(p,&server_info->session_key,sizeof(server_info->session_key)); |
| 1315 | p+=sizeof(server_info->session_key); |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 1316 | count=dpc_send(server_info->file,p-message,message); |
| 1317 | if (count != (MagickOffsetType) (p-message)) |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1318 | return(MagickFalse); |
cristy | 3349e17 | 2013-01-25 20:05:18 +0000 | [diff] [blame] | 1319 | count=dpc_read(server_info->file,sizeof(status),(unsigned char *) &status); |
| 1320 | if (count != (MagickOffsetType) sizeof(status)) |
| 1321 | return(MagickFalse); |
| 1322 | return(status); |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 1323 | } |
| 1324 | |
| 1325 | /* |
| 1326 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1327 | % % |
| 1328 | % % |
| 1329 | % % |
cristy | 43940f4 | 2013-01-17 00:24:06 +0000 | [diff] [blame] | 1330 | + W r i t e D i s t r i b u t e P i x e l C a c h e M e t a c o n t e n t % |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 1331 | % % |
| 1332 | % % |
| 1333 | % % |
| 1334 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1335 | % |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1336 | % WriteDistributePixelCacheMetacontents() writes image metacontent to the |
| 1337 | % specified region of the distributed pixel cache. |
cristy | e34745c | 2013-01-16 02:27:04 +0000 | [diff] [blame] | 1338 | % |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1339 | % The format of the WriteDistributePixelCacheMetacontents method is: |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 1340 | % |
cristy | d6e5ed3 | 2013-01-19 17:24:56 +0000 | [diff] [blame] | 1341 | % MagickOffsetType WriteDistributePixelCacheMetacontents( |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 1342 | % DistributeCacheInfo *server_info,const RectangleInfo *region, |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1343 | % const MagickSizeType length,const unsigned char *metacontent) |
| 1344 | % |
| 1345 | % A description of each parameter follows: |
| 1346 | % |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 1347 | % o server_info: the distributed cache info. |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1348 | % |
| 1349 | % o image: the image. |
| 1350 | % |
| 1351 | % o region: write the metacontent to this region of the image. |
| 1352 | % |
cristy | a4eb3d6 | 2013-01-17 00:36:58 +0000 | [diff] [blame] | 1353 | % o length: the length in bytes of the metacontent. |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1354 | % |
| 1355 | % o metacontent: write these metacontent to the pixel cache. |
| 1356 | % |
| 1357 | */ |
cristy | d6e5ed3 | 2013-01-19 17:24:56 +0000 | [diff] [blame] | 1358 | MagickPrivate MagickOffsetType WriteDistributePixelCacheMetacontent( |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 1359 | DistributeCacheInfo *server_info,const RectangleInfo *region, |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1360 | const MagickSizeType length,const unsigned char *metacontent) |
| 1361 | { |
cristy | d6e5ed3 | 2013-01-19 17:24:56 +0000 | [diff] [blame] | 1362 | MagickOffsetType |
| 1363 | count; |
| 1364 | |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1365 | register unsigned char |
| 1366 | *p; |
| 1367 | |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1368 | unsigned char |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 1369 | message[MaxTextExtent]; |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1370 | |
cristy | feb2167 | 2013-01-23 00:12:55 +0000 | [diff] [blame] | 1371 | /* |
| 1372 | Write distributed pixel cache metacontent. |
| 1373 | */ |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 1374 | assert(server_info != (DistributeCacheInfo *) NULL); |
| 1375 | assert(server_info->signature == MagickSignature); |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1376 | assert(region != (RectangleInfo *) NULL); |
| 1377 | assert(metacontent != (unsigned char *) NULL); |
cristy | 766c2f1 | 2013-01-25 02:46:26 +0000 | [diff] [blame] | 1378 | if (length > (MagickSizeType) SSIZE_MAX) |
cristy | d6e5ed3 | 2013-01-19 17:24:56 +0000 | [diff] [blame] | 1379 | return(-1); |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 1380 | p=message; |
cristy | feb2167 | 2013-01-23 00:12:55 +0000 | [diff] [blame] | 1381 | *p++='W'; |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 1382 | (void) memcpy(p,&server_info->session_key,sizeof(server_info->session_key)); |
| 1383 | p+=sizeof(server_info->session_key); |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1384 | (void) memcpy(p,®ion->width,sizeof(region->width)); |
| 1385 | p+=sizeof(region->width); |
| 1386 | (void) memcpy(p,®ion->height,sizeof(region->height)); |
| 1387 | p+=sizeof(region->height); |
| 1388 | (void) memcpy(p,®ion->x,sizeof(region->x)); |
| 1389 | p+=sizeof(region->x); |
| 1390 | (void) memcpy(p,®ion->y,sizeof(region->y)); |
| 1391 | p+=sizeof(region->y); |
| 1392 | (void) memcpy(p,&length,sizeof(length)); |
| 1393 | p+=sizeof(length); |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 1394 | count=dpc_send(server_info->file,p-message,message); |
| 1395 | if (count != (MagickOffsetType) (p-message)) |
cristy | d6e5ed3 | 2013-01-19 17:24:56 +0000 | [diff] [blame] | 1396 | return(-1); |
cristy | feb2167 | 2013-01-23 00:12:55 +0000 | [diff] [blame] | 1397 | return(dpc_send(server_info->file,length,metacontent)); |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1398 | } |
| 1399 | |
| 1400 | /* |
| 1401 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1402 | % % |
| 1403 | % % |
| 1404 | % % |
cristy | 43940f4 | 2013-01-17 00:24:06 +0000 | [diff] [blame] | 1405 | + W r i t e D i s t r i b u t e P i x e l C a c h e P i x e l s % |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1406 | % % |
| 1407 | % % |
| 1408 | % % |
| 1409 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1410 | % |
| 1411 | % WriteDistributePixelCachePixels() writes image pixels to the specified |
| 1412 | % region of the distributed pixel cache. |
| 1413 | % |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1414 | % The format of the WriteDistributePixelCachePixels method is: |
| 1415 | % |
cristy | d6e5ed3 | 2013-01-19 17:24:56 +0000 | [diff] [blame] | 1416 | % MagickBooleanType WriteDistributePixelCachePixels( |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 1417 | % DistributeCacheInfo *server_info,const RectangleInfo *region, |
cristy | 1d1254d | 2013-04-19 16:12:56 +0000 | [diff] [blame] | 1418 | % const MagickSizeType length,const unsigned char *restrict pixels) |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 1419 | % |
| 1420 | % A description of each parameter follows: |
| 1421 | % |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 1422 | % o server_info: the distributed cache info. |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 1423 | % |
| 1424 | % o image: the image. |
| 1425 | % |
| 1426 | % o region: write the pixels to this region of the image. |
| 1427 | % |
cristy | a4eb3d6 | 2013-01-17 00:36:58 +0000 | [diff] [blame] | 1428 | % o length: the length in bytes of the pixels. |
cristy | e34745c | 2013-01-16 02:27:04 +0000 | [diff] [blame] | 1429 | % |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 1430 | % o pixels: write these pixels to the pixel cache. |
| 1431 | % |
| 1432 | */ |
cristy | d6e5ed3 | 2013-01-19 17:24:56 +0000 | [diff] [blame] | 1433 | MagickPrivate MagickOffsetType WriteDistributePixelCachePixels( |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 1434 | DistributeCacheInfo *server_info,const RectangleInfo *region, |
cristy | 1d1254d | 2013-04-19 16:12:56 +0000 | [diff] [blame] | 1435 | const MagickSizeType length,const unsigned char *restrict pixels) |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 1436 | { |
cristy | d6e5ed3 | 2013-01-19 17:24:56 +0000 | [diff] [blame] | 1437 | MagickOffsetType |
| 1438 | count; |
| 1439 | |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1440 | register unsigned char |
| 1441 | *p; |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 1442 | |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1443 | unsigned char |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 1444 | message[MaxTextExtent]; |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1445 | |
cristy | feb2167 | 2013-01-23 00:12:55 +0000 | [diff] [blame] | 1446 | /* |
| 1447 | Write distributed pixel cache pixels. |
| 1448 | */ |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 1449 | assert(server_info != (DistributeCacheInfo *) NULL); |
| 1450 | assert(server_info->signature == MagickSignature); |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 1451 | assert(region != (RectangleInfo *) NULL); |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1452 | assert(pixels != (const unsigned char *) NULL); |
cristy | 766c2f1 | 2013-01-25 02:46:26 +0000 | [diff] [blame] | 1453 | if (length > (MagickSizeType) SSIZE_MAX) |
cristy | d6e5ed3 | 2013-01-19 17:24:56 +0000 | [diff] [blame] | 1454 | return(-1); |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 1455 | p=message; |
cristy | feb2167 | 2013-01-23 00:12:55 +0000 | [diff] [blame] | 1456 | *p++='w'; |
cristy | d9fdd23 | 2013-01-19 00:14:59 +0000 | [diff] [blame] | 1457 | (void) memcpy(p,&server_info->session_key,sizeof(server_info->session_key)); |
| 1458 | p+=sizeof(server_info->session_key); |
cristy | ce9db09 | 2013-01-16 22:16:51 +0000 | [diff] [blame] | 1459 | (void) memcpy(p,®ion->width,sizeof(region->width)); |
| 1460 | p+=sizeof(region->width); |
| 1461 | (void) memcpy(p,®ion->height,sizeof(region->height)); |
| 1462 | p+=sizeof(region->height); |
| 1463 | (void) memcpy(p,®ion->x,sizeof(region->x)); |
| 1464 | p+=sizeof(region->x); |
| 1465 | (void) memcpy(p,®ion->y,sizeof(region->y)); |
| 1466 | p+=sizeof(region->y); |
| 1467 | (void) memcpy(p,&length,sizeof(length)); |
| 1468 | p+=sizeof(length); |
cristy | b912072 | 2013-01-20 17:20:50 +0000 | [diff] [blame] | 1469 | count=dpc_send(server_info->file,p-message,message); |
| 1470 | if (count != (MagickOffsetType) (p-message)) |
cristy | d6e5ed3 | 2013-01-19 17:24:56 +0000 | [diff] [blame] | 1471 | return(-1); |
cristy | feb2167 | 2013-01-23 00:12:55 +0000 | [diff] [blame] | 1472 | return(dpc_send(server_info->file,length,pixels)); |
cristy | bb31fcd | 2013-01-15 20:06:37 +0000 | [diff] [blame] | 1473 | } |