Example #1
0
    def test_mmap_address(self):
        import mmap
        import _multiprocessing

        # This is a bit faster than importing ctypes
        import _ctypes

        class c_double(_ctypes._SimpleCData):
            _type_ = "d"

        sizeof_double = _ctypes.sizeof(c_double)

        buf = mmap.mmap(-1, 300)
        buf[0:300] = '\0' * 300

        # Get the address of shared memory
        address, length = _multiprocessing.address_of_buffer(buf)
        assert length == 300

        # build a ctypes object from it
        var = c_double.from_address(address)
        assert buf[0:sizeof_double] == '\0' * sizeof_double
        assert var.value == 0

        # check that both objects share the same memory
        var.value = 123.456
        assert buf[0:sizeof_double] != '\0' * sizeof_double
        buf[0:sizeof_double] = '\0' * sizeof_double
        assert var.value == 0
Example #2
0
    def test_mmap_address(self):
        import mmap
        import _multiprocessing

        # This is a bit faster than importing ctypes
        import _ctypes
        class c_double(_ctypes._SimpleCData):
            _type_ = "d"
        sizeof_double = _ctypes.sizeof(c_double)

        buf = mmap.mmap(-1, 300)
        buf[0:300] = '\0' * 300

        # Get the address of shared memory
        address, length = _multiprocessing.address_of_buffer(buf)
        assert length == 300

        # build a ctypes object from it
        var = c_double.from_address(address)
        assert buf[0:sizeof_double] == '\0' * sizeof_double
        assert var.value == 0

        # check that both objects share the same memory
        var.value = 123.456
        assert buf[0:sizeof_double] != '\0' * sizeof_double
        buf[0:sizeof_double] = '\0' * sizeof_double
        assert var.value == 0
  def my_constructor(self, Identity, Context, Graph, AvatarName, CameraName):
    self._Identity = Identity
    self._Context = Context

    self._Graph = Graph
    self._AvatarName = AvatarName
    self._CameraName = CameraName


    #open shared memory
    _name = "/MumbleLink." + str(os.getuid()) #name of shared memory
    #TODO: next line crashes if mumble isn't running. Maybe add Error output
    try:
      _mem = pos.SharedMemory(_name, flags=0, size=sizeof(LinkedMem))   #flag 0 means access
      print _mem.name
      self._map = mmap.mmap(_mem.fd, _mem.size)
      _mem.close_fd()
      addr, size = address_of_buffer(self._map)
      assert size == sizeof(LinkedMem)
    
    except:
      #print "Error while opening shared memory. Propably Mumble is not running !"
      raise ShmError('Error while opening shared memory. Propably Mumble is not running !')

    self._lm = LinkedMem.from_address(addr)
    self._lm.uiTick = 1 #start with a number other than 0 so the first updated isn't skipped'''
    
    #init trigger callback
    #relying on field has changed could lead to mumble assuming the application died
    self.frame_trigger = avango.script.nodes.Update(Callback = self.update, Active = True)
Example #4
0
 def open(self):
   _name = "/MumbleLink." + str(os.getuid()) #name of shared memory
   _mem = pos.SharedMemory(_name, flags=0, size=sizeof(LinkedMem))   #flag 0 means access
   print _mem.name
   self._map = mmap.mmap(_mem.fd, _mem.size)
   _mem.close_fd()
   addr, size = address_of_buffer(self._map)
   assert size == sizeof(LinkedMem)
   self._lm = LinkedMem.from_address(addr)
   self._lm.uiTick = 1 #start with a number other than 0 so the first updated isn't skipped
Example #5
0
 def get_address(self):
     (arena, start, stop), size = self._state
     address, length = _multiprocessing.address_of_buffer(arena.buffer)
     assert size <= length
     return address + start
Example #6
0
 def get_address(self):
     addr, size = address_of_buffer(self._map)
     assert size >= self.size
     return addr
Example #7
0
 def get_address(self):
     (arena, start, stop), size = self._state
     address, length = _multiprocessing.address_of_buffer(arena.buffer)
     assert size <= length
     return address + start
Example #8
0
 def get_address(self):
     (arena, start, stop), size = self._state
     address, length = _multiprocessing.address_of_buffer(arena.buffer)
     raise size <= length or AssertionError
     return address + start
Example #9
0
 def get_address(self):
     (arena, start, stop), size = self._state
     address, length = _multiprocessing.address_of_buffer(arena.buffer)
     raise size <= length or AssertionError
     return address + start
Example #10
0
 def get_address(self):
     addr, size = address_of_buffer(self._map)
     assert size >= self.size
     return addr