示例#1
0
        public void Start()
        {
            lock (_lockObject)
            {
                ConnectorProfile prof;
                try
                {
                    prof              = new ConnectorProfile();
                    prof.ports        = new[] { _portService };
                    prof.name         = "dummy"; //名前見直し?
                    prof.connector_id = "";
                    ConnectorProfileExtension.AddDataFlowType(ref prof, "push");
                    ConnectorProfileExtension.AddInterfaceType(ref prof, "corba_cdr");
                    ConnectorProfileExtension.AddSubscriptionType(ref prof, "new");
                    //TODO: エンディアンは?

                    var ret = _portService.connect(ref prof);

                    if (ret != ReturnCode_t.RTC_OK)
                    {
                        throw new Exception("ポートの接続に失敗しました。");
                    }
                }
                catch (Exception)
                {
                    IsAlive = false;
                    NotifyError("ポートの接続に失敗しました。");
                    return;
                }

                var ior = prof.GetInPortIor();

                var orb = OrbServices.GetSingleton();
                _inPortCdr = (InPortCdr)orb.string_to_object(ior);

                try
                {
                    _dataFileReader = new BinaryReader(
                        File.OpenRead(SettingHolder.BaseDirectory + RecordDescription.DataFileName));
                    _indexFileReader = new BinaryReader(
                        File.OpenRead(SettingHolder.BaseDirectory + RecordDescription.IndexFileName));
                }
                catch (Exception)
                {
                    IsAlive = false;
                    NotifyError("再生ファイルが開けませんでした。");
                    return;
                }

                try
                {
                    if (AutoActivate)
                    {
                        var comp = NamingServiceManager.Default.GetComponent(_namingName);
                        if (comp.GetState(0) == LifeCycleState.INACTIVE_STATE)
                        {
                            comp.Activate(0);
                        }

                        comp.WaitState(LifeCycleState.ACTIVE_STATE, TimeSpan.FromSeconds(5));
                    }
                }
                catch (Exception)
                {
                    IsAlive = false;
                    NotifyError("RTコンポーネントの活性化に失敗しました。");
                    return;
                }

                _stopWatch.Start();
                CurrentCount = 0;
                IsPlaying    = true;

                _cancellation = new CancellationTokenSource();
                _task         = Task.Factory.StartNew(Run, _cancellation.Token);
            }
        }
示例#2
0
        private void Start()
        {
            lock (_lockObject)
            {
                if (!IsAlive)
                {
                    return;
                }
                if (IsRecording)
                {
                    return;
                }

                IsRecording = true;

                try
                {
                    var adapter = new DelegateInPortCdr(Write);
                    var orb     = OrbServices.GetSingleton();
                    var ior     = orb.object_to_string(adapter);

                    var prof = new ConnectorProfile();
                    prof.ports        = new[] { _portService };
                    prof.name         = "dummy"; // 名前見直し?
                    prof.connector_id = "";

                    ConnectorProfileExtension.AddDataFlowType(ref prof, "push");
                    ConnectorProfileExtension.AddInterfaceType(ref prof, "corba_cdr");
                    ConnectorProfileExtension.AddSubscriptionType(ref prof, "new");
                    ConnectorProfileExtension.AddInPortIor(ref prof, ior);

                    var ret = _portService.connect(ref prof);

                    if (ret != ReturnCode_t.RTC_OK)
                    {
                        throw new Exception("接続に失敗しました。");
                    }

                    _connectorId = prof.connector_id;
                    //TODO: エンディアンチェックしたいけど、ミドルウェアが対応してない。
                    //name = "dataport.serializer.cdr.endian"
                }
                catch (Exception)
                {
                    IsAlive = false;
                    NotifyError("ポートの接続に失敗しました。");
                    return;
                }

                var now = DateTime.Now;
                RecordDescription.CreatedDateTime = now;
                RecordDescription.Count           = 0;
                RecordDescription.SumSize         = 0;
                RecordDescription.IsLittleEndian  = 1;

                var fileName = FileUtility.ValidFileName(now.ToString("yyyyMMdd_HHmmss") + "_" + Key);
                RecordDescription.DataFileName  = fileName + ".data";
                RecordDescription.IndexFileName = fileName + ".index";


                try
                {
                    if (!Directory.Exists(SettingHolder.BaseDirectory))
                    {
                        Directory.CreateDirectory(SettingHolder.BaseDirectory);
                    }
                    _dataFileWriter = new BinaryWriter(
                        File.Create(SettingHolder.BaseDirectory + RecordDescription.DataFileName));
                    _indexFileWriter = new BinaryWriter(
                        File.Create(SettingHolder.BaseDirectory + RecordDescription.IndexFileName));
                }
                catch (Exception)
                {
                    IsAlive = false;
                    NotifyError("ファイルを開くことができませんでした。");
                    return;
                }

                try
                {
                    if (AutoActivate)
                    {
                        var comp = NamingServiceManager.Default.GetComponent(_namingName);
                        if (comp.GetState(0) == LifeCycleState.INACTIVE_STATE)
                        {
                            comp.Activate(0);
                        }

                        comp.WaitState(LifeCycleState.ACTIVE_STATE, TimeSpan.FromSeconds(5));
                    }
                }
                catch (Exception)
                {
                    IsAlive = false;
                    NotifyError("RTコンポーネントの活性化に失敗しました。");
                    return;
                }

                _stopWatch.Start();

                IsRecording = true;
            }
        }