Ejemplo n.º 1
0
        /// <summary>
        /// Merge the changed members based on the timestamps.
        /// <para/>
        /// All members of the given entity that are marked as changed will be merged into the
        /// current entity object in the pool given that the top member has a timestamp that is "newer" than
        /// the corresponding timestamp in the Dob.
        /// </summary>
        /// <param name="entity">Entity to create or update.</param>
        /// <param name="instanceId">Instance id.</param>
        /// <param name="timestamp">Timestamp valid for the top members that are marked as changed.</param>
        /// <param name="handlerId">Handler id.</param>
        public void InjectChanges(Entity entity,
                                  Typesystem.InstanceId instanceId,
                                  System.Int64 timestamp,
                                  Typesystem.HandlerId handlerId)
        {
            byte success;

            //TODO: serialize directly to shared memory
            System.Int32  blobSize = entity.CalculateBlobSize();
            System.IntPtr blob     = Marshal.AllocHGlobal(blobSize); //allocate blob
            System.IntPtr beginningOfUnused;
            Typesystem.Internal.InternalOperations.FormatBlob(blob, blobSize, entity.GetTypeId(), out beginningOfUnused);
            entity.WriteToBlob(blob, ref beginningOfUnused);

            System.IntPtr instanceIdStr = Dob.Typesystem.Internal.InternalOperations.CStringOf(instanceId.RawString);
            System.IntPtr handlerIdStr  = Dob.Typesystem.Internal.InternalOperations.CStringOf(handlerId.RawString);

            Interface.DoseC_InjectEntity(ControllerId,
                                         blob,
                                         instanceId.RawValue,
                                         instanceIdStr,
                                         handlerId.RawValue,
                                         handlerIdStr,
                                         timestamp,
                                         out success);

            Marshal.FreeHGlobal(instanceIdStr);
            Marshal.FreeHGlobal(handlerIdStr);

            if (!Interface.BoolOf(success))
            {
                Typesystem.LibraryExceptions.Instance.Throw();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Allows an application to inject an initial entity state.
        /// </summary>
        /// <param name="entity">Entity to create.</param>
        /// <param name="instanceId">Instance id of entity to inject.</param>
        /// <param name="handlerId">The handler id to inject to.</param>
        public void InitialSet(Entity entity,
                               Typesystem.InstanceId instanceId,
                               Typesystem.HandlerId handlerId)
        {
            byte success;

            //TODO: serialize directly to shared memory
            System.Int32  blobSize = entity.CalculateBlobSize();
            System.IntPtr blob     = Marshal.AllocHGlobal(blobSize); //allocate blob
            System.IntPtr beginningOfUnused;
            Typesystem.Internal.InternalOperations.FormatBlob(blob, blobSize, entity.GetTypeId(), out beginningOfUnused);
            entity.WriteToBlob(blob, ref beginningOfUnused);

            System.IntPtr instanceIdStr = Dob.Typesystem.Internal.InternalOperations.CStringOf(instanceId.RawString);
            System.IntPtr handlerIdStr  = Dob.Typesystem.Internal.InternalOperations.CStringOf(handlerId.RawString);

            Interface.DoseC_SetEntity(ControllerId,
                                      blob,
                                      instanceId.RawValue,
                                      instanceIdStr,
                                      handlerId.RawValue,
                                      handlerIdStr,
                                      Interface.ByteOf(false),   // false => don't consider change flags
                                      Interface.ByteOf(true),    // true => this is an initial injection
                                      out success);

            Marshal.FreeHGlobal(instanceIdStr);
            Marshal.FreeHGlobal(handlerIdStr);

            if (!Interface.BoolOf(success))
            {
                Typesystem.LibraryExceptions.Instance.Throw();
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Constructor with type id and instance arguments.
 /// <para/>
 /// Creates an EntityId with the given typeid and instance number.
 /// </summary>
 /// <param name="type">The type id of the entity that the EntityId is to refer to.</param>
 /// <param name="instanceId">The instance of the entity that the EntityId is to refer to.</param>
 public EntityId(System.Int64 type, InstanceId instanceId)
 {
     if (instanceId == null)
     {
         throw new SoftwareViolationException("instance cannot be null in EntityId constructor");
     }
     m_typeId     = type;
     m_instanceId = instanceId;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Equals method
        /// </summary>
        /// <param name="obj">The instance id to compare with.</param>
        /// <returns>True if the instance ids are equal.</returns>
        public override bool Equals(object obj)
        {
            InstanceId other = obj as InstanceId;

            if (other == null)
            {
                return(false);
            }
            else
            {
                return(m_instanceId == other.m_instanceId);
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 public EntityId()
 {
     m_typeId     = 0;
     m_instanceId = new InstanceId();
 }