summaryrefslogtreecommitdiffstats
path: root/tksao/fitsy++/sshare.C
diff options
context:
space:
mode:
authorWilliam Joye <wjoye@cfa.harvard.edu>2016-10-27 18:59:29 (GMT)
committerWilliam Joye <wjoye@cfa.harvard.edu>2016-10-27 18:59:29 (GMT)
commitd4d595fa7fb12903db9227d33d48b2b00120dbd1 (patch)
tree7d18365de0d6d1b29399b6a17c7eb01c2eb3ed49 /tksao/fitsy++/sshare.C
parent949f96e29bfe0bd8710d775ce220e597064e2589 (diff)
downloadblt-d4d595fa7fb12903db9227d33d48b2b00120dbd1.zip
blt-d4d595fa7fb12903db9227d33d48b2b00120dbd1.tar.gz
blt-d4d595fa7fb12903db9227d33d48b2b00120dbd1.tar.bz2
Initial commit
Diffstat (limited to 'tksao/fitsy++/sshare.C')
-rw-r--r--tksao/fitsy++/sshare.C148
1 files changed, 148 insertions, 0 deletions
diff --git a/tksao/fitsy++/sshare.C b/tksao/fitsy++/sshare.C
new file mode 100644
index 0000000..37e3080
--- /dev/null
+++ b/tksao/fitsy++/sshare.C
@@ -0,0 +1,148 @@
+// Copyright (C) 1999-2016
+// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
+// For conditions of distribution and use, see copyright notice in "copyright"
+
+#include "sshare.h"
+
+#if (HAVE_SYS_SHM_H && !__WIN32)
+#include <sys/types.h>
+#include <sys/shm.h>
+#include <sys/ipc.h>
+
+FitsSShareID::FitsSShareID(int hdrid, int shmid, const char* filter)
+{
+ // reset
+ valid_ =0;
+
+ {
+ // find size
+ struct shmid_ds info;
+ if (shmctl(hdrid, IPC_STAT, &info)) {
+ internalError("Fitsy++ sshare shctl failed");
+ return;
+ }
+ hmapsize_ = info.shm_segsz;
+
+ // Attach the memory segment
+ if ((long)(hmapdata_ = (char*)shmat(hdrid, 0, SHM_RDONLY)) == -1) {
+ internalError("Fitsy++ sshare shmat failed");
+ return;
+ }
+ }
+
+ {
+ parse(filter);
+ if (!valid_)
+ return;
+
+ // reset
+ valid_ =0;
+
+ // find size
+ struct shmid_ds info;
+ if (shmctl(shmid, IPC_STAT, &info)) {
+ internalError("Fitsy++ sshare shctl failed");
+ return;
+ }
+ mapsize_ = info.shm_segsz;
+
+ // Attach the memory segment
+ if ((long)(mapdata_ = (char*)shmat(shmid, 0, SHM_RDONLY)) == -1) {
+ internalError("Fitsy++ sshare shmat failed");
+ return;
+ }
+ }
+
+ // so far so good
+ valid_ = 1;
+}
+
+FitsSShareID::~FitsSShareID()
+{
+ shmdt(mapdata_);
+}
+
+FitsSShareKey::FitsSShareKey(int hdr, int key, const char* filter)
+{
+ // reset
+ valid_ =0;
+
+ {
+ // get shmid
+ int shmid;
+ if ((shmid = shmget(hdr, 0, 0)) < 0) {
+ internalError("Fitsy++ sshare shmget failed");
+ return;
+ }
+
+ // find size
+ struct shmid_ds info;
+ if (shmctl(shmid, IPC_STAT, &info)) {
+ internalError("Fitsy++ sshare shctl failed");
+ return;
+ }
+ mapsize_ = info.shm_segsz;
+
+ // Attach the memory segment
+ if ((long)(mapdata_ = (char*)shmat(shmid, 0, SHM_RDONLY)) == -1) {
+ internalError("Fitsy++ sshare shmat failed");
+ return;
+ }
+ }
+
+ {
+ parse(filter);
+ if (!valid_)
+ return;
+
+ // reset
+ valid_ =0;
+
+ // get shmid
+ int shmid;
+ if ((shmid = shmget(key, 0, 0)) < 0) {
+ internalError("Fitsy++ sshare shmget failed");
+ return;
+ }
+
+ // find size
+ struct shmid_ds info;
+ if (shmctl(shmid, IPC_STAT, &info)) {
+ internalError("Fitsy++ sshare shmctl failed");
+ return;
+ }
+ mapsize_ = info.shm_segsz;
+
+ // Attach the memory segment
+ if ((long)(mapdata_ = (char*)shmat(shmid, 0, SHM_RDONLY)) == -1) {
+ internalError("Fitsy++ sshare shmat failed");
+ return;
+ }
+ }
+
+ // so far so good
+ valid_ = 1;
+}
+
+FitsSShareKey::~FitsSShareKey()
+{
+ shmdt(mapdata_);
+}
+
+#else
+
+FitsSShareID::FitsSShareID(int hdrid, int shmid, const char* filter)
+{
+ valid_ = 0;
+}
+
+FitsSShareID::~FitsSShareID() {}
+
+FitsSShareKey::FitsSShareKey(int hdr, int key, const char* filter)
+{
+ valid_ = 0;
+}
+
+FitsSShareKey::~FitsSShareKey() {}
+
+#endif