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 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 #3
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 #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_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()
    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:
        if DemoConstants.USE_SEMAPHORE:
Beispiel #7
0
    def __init__(self, key):
        self._MemoryHandle = None

        # getshmid will raise a KeyError if there's no memory segment with this key.
        shmid = shm.getshmid(key)
        self._MemoryHandle = shm.memory(shmid)