Example #1
0
        internal int WaitAction(IntPtr userData, IntPtr arg)
        {
            int proceed = 1;

            // Extract the condition list from the pointer and add the condition to it.
            GCHandle      argGCHandle = GCHandle.FromIntPtr(arg);
            WaitActionArg actionArg   = (WaitActionArg)argGCHandle.Target;

            if (userData == IntPtr.Zero)
            {
                foreach (IGuardCondition guardCond in actionArg.attachedGuards)
                {
                    if (guardCond.GetTriggerValue())
                    {
                        actionArg.Add(guardCond);
                    }
                }
                proceed = (actionArg.nrTriggeredConditions == 0) ? 1 : 0;
            }
            else
            {
                GCHandle   condGCHandle = GCHandle.FromIntPtr(userData);
                ICondition cond         = condGCHandle.Target as ICondition;
                actionArg.Add(cond);
            }
            argGCHandle.Target = actionArg;
            return(proceed);
        }
Example #2
0
        /// <summary>
        /// This operation allows an application thread to wait for the occurrence of at least one
        /// of the conditions that is attached to the WaitSet.
        /// </summary>
        /// <param name="activeConditions">a sequence which is used to pass the list of all the attached
        /// conditions that have a trigger_value of true.</param>
        /// <param name="timeout">the maximum duration to block for the wait, after which the application thread
        /// is unblocked. The special constant Infinite can be used when the maximum waiting time does not
        /// need to be bounded.</param>
        /// <returns>Possible return codes for the operation are:
        /// Ok, Error, OutOfResources, Timeout or PreconditionNotMet</returns>
        public ReturnCode Wait(ref ICondition[] activeConditions, Duration timeout)
        {
            ReturnCode result = DDS.ReturnCode.Ok;

            ReportStack.Start();
            WaitActionArg arg = new WaitActionArg(activeConditions);

            if (QosManager.countErrors(timeout) > 0)
            {
                result = DDS.ReturnCode.BadParameter;
                ReportStack.Report(result, "Duration timeout incorrect");
            }

            while (result == DDS.ReturnCode.Ok && arg.nrTriggeredConditions == 0)
            {
                lock (this)
                {
                    arg.maxConditions  = conditionList.Count + guardList.Count;
                    arg.attachedGuards = guardList.ToArray();
                    if (activeConditions == null)
                    {
                        activeConditions = new ICondition[arg.maxConditions];
                    }
                }

                GCHandle argGCHandle = GCHandle.Alloc(arg, GCHandleType.Normal);

                V_RESULT uResult = DDS.OpenSplice.User.WaitSet.WaitAction2(
                    rlReq_UserPeer,
                    WaitAction,
                    GCHandle.ToIntPtr(argGCHandle),
                    timeout.OsDuration);

                if (uResult == V_RESULT.DETACHING)
                {
                    arg = (WaitActionArg)argGCHandle.Target;
                    lock (this)
                    {
                        foreach (ICondition cond in conditionList)
                        {
                            Condition condImpl = cond as Condition;
                            if (condImpl.IsAlive() == DDS.ReturnCode.AlreadyDeleted)
                            {
                                arg.Add(cond);
                            }
                        }
                    }
                    result = DDS.ReturnCode.Ok;
                }
                else
                {
                    result = SacsSuperClass.uResultToReturnCode(uResult);
                    arg    = (WaitActionArg)argGCHandle.Target;
                }

                argGCHandle.Free();

                activeConditions = arg.Finalize();
            }
            ReportStack.Flush(this, (result != ReturnCode.Ok) && (result != ReturnCode.Timeout));

            return(result);
        }