Beispiel #1
0
 def handle_input(self, source, condition):
     #olog("handle_input:")
     m = self.message_handler.recv()
     if m[0] == message.RenderCompleted :
         # load a new shared memory
         #olog("display msg is received")
         shmid = int(m[1])
         if self.shm_obj <> None:
             if self.shm_obj.shmid == shmid :
                 self.redraw()
             else:
                 self.thread_lock.acquire()
                 try :
                     self.shm_obj.detach()
                     self.shm_obj = shm.memory(shmid)
                     self.sem_obj = shm.semaphore(shm.getsemid(shmid))
                     self.shm_obj.attach()
                 finally:
                     self.thread_lock.release()
         else :
             self.thread_lock.acquire()
             try :
                 self.shm_obj = shm.memory(shmid)
                 self.sem_obj = shm.semaphore(shm.getsemid(shmid))
                 self.shm_obj.attach()
             finally:
                 self.thread_lock.release()
     else :
         sys.stderr.write('invalid event type\n')
         sys.exit(1)
     gobject.io_add_watch(self.soc.fileno(), gobject.IO_IN, self.handle_input)
     return False
Beispiel #2
0
    def __init__(self, log, shm_id=1):

	# Connect or create shm
        try:
	    self.stat_buf = shmw.SharedMemoryHandle(STATUS_KEY + shm_id - 1)
	    log.info("Connected to status shm key: %d"%(STATUS_KEY + shm_id - 1))
	except KeyError:
	    self.a = shm.create_memory(STATUS_KEY + shm_id - 1, STATUS_SIZE, 0666)
	    log.info("Created new status shm key: %d"%(STATUS_KEY + shm_id - 1))
	    #  Init 
	    self.chk_init()
	    self.stat_buf = shmw.SharedMemoryHandle(STATUS_KEY + shm_id - 1)
	    log.info("Connected to status shm key: %d"%(STATUS_KEY + shm_id - 1))
	

	# Semaphore for status shm
        try:
	    self.semid = shm.getsemid(STATUS_SEM_KEY + shm_id - 1)
	    self.sem = shm.semaphore(self.semid)
	except KeyError:
	    self.sem = shm.create_semaphore(STATUS_SEM_KEY + shm_id - 1)
	    self.semid = shm.getsemid(STATUS_SEM_KEY + shm_id - 1)

        self.hdr = None
	self.read()
Beispiel #3
0
 def handle_input(self, source, condition):
     #olog("handle_input:")
     m = self.message_handler.recv()
     if m[0] == message.RenderCompleted:
         # load a new shared memory
         #olog("display msg is received")
         shmid = int(m[1])
         if self.shm_obj <> None:
             if self.shm_obj.shmid == shmid:
                 self.redraw()
             else:
                 self.thread_lock.acquire()
                 try:
                     self.shm_obj.detach()
                     self.shm_obj = shm.memory(shmid)
                     self.sem_obj = shm.semaphore(shm.getsemid(shmid))
                     self.shm_obj.attach()
                 finally:
                     self.thread_lock.release()
         else:
             self.thread_lock.acquire()
             try:
                 self.shm_obj = shm.memory(shmid)
                 self.sem_obj = shm.semaphore(shm.getsemid(shmid))
                 self.shm_obj.attach()
             finally:
                 self.thread_lock.release()
     else:
         sys.stderr.write('invalid event type\n')
         sys.exit(1)
     gobject.io_add_watch(self.soc.fileno(), gobject.IO_IN,
                          self.handle_input)
     return False
Beispiel #4
0
 def handle_input(self, source, condition):
     #olog("handle_input:")
     m = self.read_message()
     if m.type == msg.mtypes.K2G_DISPLAY:
         pass
     elif m.type == msg.mtypes.K2G_DISPLAY_SHM:
         # load a new shared memory
         #olog("display msg is received")
         if self.shm_obj <> None:
             if self.shm_obj.shmid == m.shmid:
                 self.redraw()
             else:
                 self.thread_lock.acquire()
                 try:
                     self.shm_obj.detach()
                     self.shm_obj = shm.memory(m.shmid)
                     self.sem_obj = shm.semaphore(shm.getsemid(m.shmid))
                     self.shm_obj.attach()
                 finally:
                     self.thread_lock.release()
         else:
             self.thread_lock.acquire()
             try:
                 self.shm_obj = shm.memory(m.shmid)
                 self.sem_obj = shm.semaphore(shm.getsemid(m.shmid))
                 self.shm_obj.attach()
             finally:
                 self.thread_lock.release()
         #olog("self.shm_obj:" + str(self.shm_obj))
     elif m.type == msg.mtypes.REQ_URI:
         if len(m.uri) > 80:
             uri = m.uri[0:79] + " ..."
         else:
             uri = m.uri
         self.status.set_text("loading " + uri)
     elif m.type == msg.mtypes.SET_STATUS:
         if len(m.status) > 80:
             status = m.status[0:79] + " ..."
         else:
             status = m.status
         self.status.set_text(status)
     elif m.type == msg.mtypes.EXIT:
         gtk.main_quit()
     gobject.io_add_watch(self.soc.fileno(), gobject.IO_IN,
                          self.handle_input)
     return False
Beispiel #5
0
 def handle_input(self, source, condition):
     #olog("handle_input:")
     m = self.read_message()
     if m.type == msg.mtypes.K2G_DISPLAY:
         pass
     elif m.type == msg.mtypes.K2G_DISPLAY_SHM:
         # load a new shared memory
         #olog("display msg is received")
         if self.shm_obj <> None:
             if self.shm_obj.shmid == m.shmid :
                 self.redraw()
             else:
                 self.thread_lock.acquire()
                 try :
                     self.shm_obj.detach()
                     self.shm_obj = shm.memory(m.shmid)
                     self.sem_obj = shm.semaphore(shm.getsemid(m.shmid))
                     self.shm_obj.attach()
                 finally:
                     self.thread_lock.release()
         else :
             self.thread_lock.acquire()
             try :
                 self.shm_obj = shm.memory(m.shmid)
                 self.sem_obj = shm.semaphore(shm.getsemid(m.shmid))
                 self.shm_obj.attach()
             finally:
                 self.thread_lock.release()
         #olog("self.shm_obj:" + str(self.shm_obj))
     elif m.type == msg.mtypes.REQ_URI:
         if len(m.uri) > 80:
             uri = m.uri[0:79] + " ..."
         else:
             uri = m.uri
         self.status.set_text("loading " + uri)
     elif m.type == msg.mtypes.SET_STATUS:
         if len(m.status) > 80:
             status = m.status[0:79] + " ..."
         else:
             status = m.status
         self.status.set_text(status)
     elif m.type == msg.mtypes.EXIT:
         gtk.main_quit()
     gobject.io_add_watch(self.soc.fileno(), gobject.IO_IN, self.handle_input)
     return False
Beispiel #6
0
    def __init__(self, log, shm_id=1):

        # Connect or create shm
        try:
            self.stat_buf = shmw.SharedMemoryHandle(STATUS_KEY + shm_id - 1)
            log.info("Connected to status shm key: 0x%08x" %
                     (STATUS_KEY + shm_id - 1))
            print("Try Connected to status shm key: 0x%08x" %
                  (STATUS_KEY + shm_id - 1))
        except KeyError:
            self.a = shm.create_memory(STATUS_KEY + shm_id - 1, STATUS_SIZE,
                                       0666)
            log.info("Created new status shm key: 0x%08x" %
                     (STATUS_KEY + shm_id - 1))
            print("Created new status shm key: 0x%08x" %
                  (STATUS_KEY + shm_id - 1))
            #  Init
            self.chk_init()
            self.stat_buf = shmw.SharedMemoryHandle(STATUS_KEY + shm_id - 1)
            log.info("Connected to status shm key: 0x%08x" %
                     (STATUS_KEY + shm_id - 1))
            print("Connected to status shm key: 0x%08x" %
                  (STATUS_KEY + shm_id - 1))

# Semaphore for status shm
        try:
            self.semid = shm.getsemid(STATUS_SEM_KEY + shm_id - 1)
            self.sem = shm.semaphore(self.semid)
        except KeyError:
            self.sem = shm.create_semaphore(STATUS_SEM_KEY + shm_id - 1)
            self.semid = shm.getsemid(STATUS_SEM_KEY + shm_id - 1)

        self.hdr = None
        if (self.sem.val == 3):
            log.info("WARNING sem 0x%08x is lock" %
                     (STATUS_SEM_KEY + shm_id - 1))
            print("WARNING sem 0x%08x is lock" % (STATUS_SEM_KEY + shm_id - 1))
        self.read()
Beispiel #7
0
 def handle_display_shm(self, m):
   shm_id = int(m[1])
   if self.shm_obj <> None:
     if self.shm_obj.shmid == shm_id :
       pass #self.redraw()
     else:
       self.thread_lock.acquire()
       try :
         self.shm_obj.detach()
         self.shm_obj = shm.memory(shm_id)
         self.sem_obj = shm.semaphore(shm.getsemid(shm_id))
         self.shm_obj.attach()
       finally:
         self.thread_lock.release()
   else :
     self.thread_lock.acquire()
     try :
       self.shm_obj = shm.memory(shm_id)
       self.sem_obj = shm.semaphore(shm.getsemid(shm_id))
       self.shm_obj.attach()
     finally:
       self.thread_lock.release()
   self.redraw()
Beispiel #8
0
 def __init__(self, databuf_id=1):
     self.buf = shmw.SharedMemoryHandle(DATABUF_KEY + databuf_id - 1)
     self.data_type = self.buf.read(NumberOfBytes=64, offset=0)
     packed = self.buf.read(NumberOfBytes=3 * 8 + 3 * 4, offset=64)
     self.struct_size, self.block_size, self.header_size = \
          n.fromstring(packed[0:24], dtype=n.int64)
     self.shmid, self.semid, self.n_block= \
          n.fromstring(packed[24:36], dtype=n.int32)
     self.header_offset = self.struct_size
     self.data_offset = self.struct_size + self.n_block * self.header_size
     self.dtype = n.int8
     self.read_size = self.block_size
     self.read_all_hdr()
     # Try to grab semid
     self.semid = shm.getsemid(DATABUF_KEY + databuf_id - 1)
Beispiel #9
0
    def __init__(self, databuf_id=1):
	self.buf = shmw.SharedMemoryHandle(DATABUF_KEY+databuf_id - 1)
	self.data_type = self.buf.read(NumberOfBytes=64, offset=0)
	packed = self.buf.read(NumberOfBytes=3*8+3*4, offset=64)
	self.struct_size, self.block_size, self.header_size = \
		    n.fromstring(packed[0:24], dtype=n.int64)
	self.shmid, self.semid, self.n_block= \
		    n.fromstring(packed[24:36], dtype=n.int32)
	self.header_offset = self.struct_size 
	self.data_offset = self.struct_size + self.n_block*self.header_size
	self.dtype = n.int8
	self.read_size = self.block_size
	self.read_all_hdr()

	# Try to grab semid 
	self.semid = shm.getsemid(DATABUF_KEY + databuf_id - 1)
    s = MemoryHandle.read(MemoryHandle.size).strip()
    say("read %s" % s)
    MemoryHandle.detach()

    return s

def say(s):
    print "conclusion@%1.6f: %s" % (time.time(), s)

if len(sys.argv) != 2:
    print "Please supply Mrs. Premise's integer key on the command line."
    sys.exit(-1)

key = int(sys.argv[1])

SemaphoreHandle = shm.semaphore(shm.getsemid(key))
MemoryHandle = shm.memory(shm.getshmid(key))

WhatIWrote = ""
s = ""

for i in xrange(0, DemoConstants.ITERATIONS):
    say("i = %d" % i)
    if DemoConstants.USE_SEMAPHORE:
        # Wait for Mrs. Premise to free up the semaphore.
        say("waiting for semaphore")
        SemaphoreHandle.P()

    s = ReadFromMemory(MemoryHandle)

    while s == WhatIWrote:
Beispiel #11
0
 def __init__(self, key):
     # getsemid will raise a KeyError if appropriate.
     self._SemaphoreHandle = shm.semaphore(shm.getsemid(key))
Beispiel #12
0
def remove_semaphore(key):
    # Destroys the semaphore. Raises KeyError if the key doesn't exist.
    shm.remove_semaphore(shm.getsemid(key))