OpenSplice C# API  v6.x
OpenSplice C# Data Distribution Service Data-Centric Publish-Subscribe API
QosProvider.cs
Go to the documentation of this file.
1 /*
2  * Vortex OpenSplice
3  *
4  * This software and documentation are Copyright 2006 to 2024 ADLINK
5  * Technology Limited, its affiliated companies and licensors. All rights
6  * reserved.
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 using System;
22 using System.Runtime.InteropServices;
23 using DDS.OpenSplice;
24 using DDS.OpenSplice.OS;
25 using DDS.OpenSplice.CustomMarshalers;
26 using DDS.OpenSplice.Common;
27 using DDS;
28 
29 namespace DDS
30 {
69  public class QosProvider : IQosProvider
70  {
71  private IntPtr cmnQpPtr;
72  private cmn_qosProviderInputAttr attr = new cmn_qosProviderInputAttr();
73 
74  private void loadQosInputAttr(
75  OpenSplice.CustomMarshalers.DatabaseMarshaler qosMarshaler,
76  Type dataType,
77  ref OpenSplice.Common.cmn_qosInputAttr attr)
78  {
79  DatabaseMarshaler.Add(null, dataType, qosMarshaler);
80  qosMarshaler.InitEmbeddedMarshalers(null);
81 
82  attr.copyOut = qosMarshaler.CopyOutDelegate;
83  }
84 
85  private ReturnCode qpResultToReturnCode (QP_RESULT qpResult)
86  {
87  ReturnCode result;
88 
89  switch (qpResult) {
90  case QP_RESULT.OK:
91  result = DDS.ReturnCode.Ok;
92  break;
93  case QP_RESULT.NO_DATA:
94  result = DDS.ReturnCode.NoData;
95  break;
96  case QP_RESULT.OUT_OF_MEMORY:
97  result = DDS.ReturnCode.OutOfResources;
98  break;
99  case QP_RESULT.ILL_PARAM:
100  result = DDS.ReturnCode.BadParameter;
101  break;
102  default:
103  result = DDS.ReturnCode.Error;
104  break;
105  }
106 
107  return result;
108  }
109 
110 
136  public QosProvider(
137  string uri,
138  string profile)
139  {
140  attr = new cmn_qosProviderInputAttr ();
141  attr.participantQos = new cmn_qosInputAttr();
142  attr.topicQos = new cmn_qosInputAttr();
143  attr.publisherQos = new cmn_qosInputAttr();
144  attr.dataWriterQos = new cmn_qosInputAttr();
145  attr.subscriberQos = new cmn_qosInputAttr();
146  attr.dataReaderQos = new cmn_qosInputAttr();
147 
148  /* let's assign defaults and see what happens */
149 
150  loadQosInputAttr(
151  new __NamedDomainParticipantQosMarshaler(),
152  typeof(NamedDomainParticipantQos),
153  ref attr.participantQos);
154  loadQosInputAttr(
155  new __NamedTopicQosMarshaler(),
156  typeof(NamedTopicQos),
157  ref attr.topicQos);
158  loadQosInputAttr(
159  new __NamedPublisherQosMarshaler(),
160  typeof(NamedPublisherQos),
161  ref attr.publisherQos);
162  loadQosInputAttr(
163  new __NamedSubscriberQosMarshaler(),
164  typeof(NamedSubscriberQos),
165  ref attr.subscriberQos);
166  loadQosInputAttr(
167  new __NamedDataWriterQosMarshaler(),
168  typeof(NamedDataWriterQos),
169  ref attr.dataWriterQos);
170  loadQosInputAttr(
171  new __NamedDataReaderQosMarshaler(),
172  typeof(NamedDataReaderQos),
173  ref attr.dataReaderQos);
174 
175  IntPtr attrPtr = os.malloc(new IntPtr(Marshal.SizeOf(attr)));
176  Marshal.StructureToPtr(attr, attrPtr, false);
177  cmnQpPtr = OpenSplice.Common.QosProvider.New(uri, profile, attrPtr);
178  os.free(attrPtr);
179 
180  if (cmnQpPtr == IntPtr.Zero)
181  {
182  // cmn_qosProviderNew already logged that the qosprovider has not been created
183  // successfully. Now create a deliberate null pointer exception to let the current
184  // constructor fail.
185  throw new System.NullReferenceException("cmn_qosProviderNew returned a NULL pointer.");
186  }
187  }
188 
190  ~QosProvider()
191  {
192  OpenSplice.Common.QosProvider.Free(cmnQpPtr);
193  }
195 
220  public ReturnCode
222  ref DomainParticipantQos participantQos,
223  string id)
224  {
225  ReportStack.Start ();
226  NamedDomainParticipantQos pQos = new NamedDomainParticipantQos ();
227  GCHandle qosHandle = GCHandle.Alloc (pQos, GCHandleType.Normal);
228  ReturnCode result = qpResultToReturnCode (
229  OpenSplice.Common.QosProvider.GetParticipantQos (cmnQpPtr, id, GCHandle.ToIntPtr (qosHandle)));
230  if (result == ReturnCode.Ok) {
231  participantQos = pQos.DomainparticipantQos;
232  } else {
233  ReportStack.Report (result, "Could not copy DomainParticipantQos.");
234  }
235  qosHandle.Free();
236  ReportStack.Flush(null, result != ReturnCode.Ok);
237  return result;
238  }
239 
264  public ReturnCode
266  ref TopicQos topicQos,
267  string id)
268  {
269  ReportStack.Start ();
270  NamedTopicQos tQos = new NamedTopicQos ();
271  GCHandle qosHandle = GCHandle.Alloc (tQos, GCHandleType.Normal);
272  ReturnCode result = qpResultToReturnCode (
273  OpenSplice.Common.QosProvider.GetTopicQos (cmnQpPtr, id, GCHandle.ToIntPtr (qosHandle)));
274  if (result == ReturnCode.Ok) {
275  topicQos = tQos.TopicQos;
276  } else {
277  ReportStack.Report (result, "Could not copy TopicQos.");
278  }
279  qosHandle.Free();
280  ReportStack.Flush(null, result != ReturnCode.Ok);
281  return result;
282  }
283 
308  public ReturnCode
310  ref SubscriberQos subscriberQos,
311  string id)
312  {
313  ReportStack.Start ();
314  NamedSubscriberQos sQos = new NamedSubscriberQos ();
315  GCHandle qosHandle = GCHandle.Alloc (sQos, GCHandleType.Normal);
316  ReturnCode result = qpResultToReturnCode (
317  OpenSplice.Common.QosProvider.GetSubscriberQos (cmnQpPtr, id, GCHandle.ToIntPtr (qosHandle)));
318  if (result == ReturnCode.Ok) {
319  subscriberQos = sQos.SubscriberQos;
320  } else {
321  ReportStack.Report (result, "Could not copy subscriberQos.");
322  }
323  qosHandle.Free();
324  ReportStack.Flush(null, result != ReturnCode.Ok);
325  return result;
326  }
327 
352  public ReturnCode
354  ref DataReaderQos datareaderQos,
355  string id)
356  {
357  ReportStack.Start ();
358  NamedDataReaderQos drQos = new NamedDataReaderQos ();
359  GCHandle qosHandle = GCHandle.Alloc (drQos, GCHandleType.Normal);
360  ReturnCode result = qpResultToReturnCode (
361  OpenSplice.Common.QosProvider.GetDataReaderQos (cmnQpPtr, id, GCHandle.ToIntPtr (qosHandle)));
362  if (result == ReturnCode.Ok) {
363  datareaderQos = drQos.DatareaderQos;
364  } else {
365  ReportStack.Report (result, "Could not copy datareaderQos.");
366  }
367 
368  qosHandle.Free();
369  ReportStack.Flush(null, result != ReturnCode.Ok);
370  return result;
371  }
372 
397  public ReturnCode
399  ref PublisherQos publisherQos,
400  string id)
401  {
402  ReportStack.Start ();
403  NamedPublisherQos pQos = new NamedPublisherQos ();
404  GCHandle qosHandle = GCHandle.Alloc (pQos, GCHandleType.Normal);
405  ReturnCode result = qpResultToReturnCode (
406  OpenSplice.Common.QosProvider.GetPublisherQos (cmnQpPtr, id, GCHandle.ToIntPtr (qosHandle)));
407  if (result == ReturnCode.Ok) {
408  publisherQos = pQos.PublisherQos;
409  } else {
410  ReportStack.Report (result, "Could not copy publisherQos.");
411  }
412 
413  qosHandle.Free();
414  ReportStack.Flush(null, result != ReturnCode.Ok);
415  return result;
416  }
417 
442  public ReturnCode
444  ref DataWriterQos datawriterQos,
445  string id)
446  {
447  ReportStack.Start ();
448  NamedDataWriterQos dwQos = new NamedDataWriterQos ();
449  GCHandle qosHandle = GCHandle.Alloc (dwQos, GCHandleType.Normal);
450  ReturnCode result = qpResultToReturnCode (
451  OpenSplice.Common.QosProvider.GetDataWriterQos (cmnQpPtr, id, GCHandle.ToIntPtr (qosHandle)));
452  if (result == ReturnCode.Ok) {
453  datawriterQos = dwQos.DatawriterQos;
454  } else {
455  ReportStack.Report (result, "Could not copy datawriterQos.");
456  }
457 
458  qosHandle.Free();
459  ReportStack.Flush(null, result != ReturnCode.Ok);
460  return result;
461  }
462 
463  // Future expansion will allow the user to share QoSs over DDS
464  //
465  // ReturnCode_t
466  // subscribe ();
467  //
468  // ReturnCode_t
469  // publish ();
470  }
471 }
QosProvider(string uri, string profile)
Constructs a new QosProvider based on the provided uri and profile.
Definition: QosProvider.cs:136
ReturnCode GetTopicQos(ref TopicQos topicQos, string id)
Resolves the TopicQos identified by the id from the uri this QosProvider is associated with...
Definition: QosProvider.cs:265
ReturnCode GetDataReaderQos(ref DataReaderQos datareaderQos, string id)
Resolves the DataReaderQos identified by the id from the uri this QosProvider is associated with...
Definition: QosProvider.cs:353
ReturnCode GetDataWriterQos(ref DataWriterQos datawriterQos, string id)
Resolves the DataWriterQos identified by the id from the uri this QosProvider is associated with...
Definition: QosProvider.cs:443
This struct provides the basic mechanism for an application to specify Quality of Service attributes ...
This struct provides the basic mechanism for an application to specify Quality of Service attributes ...
This struct provides the basic mechanism for an application to specify Quality of Service attributes ...
ReturnCode
This is the enum that represents the various ReturnCode values that DDS operations return...
Definition: DdsDcpsEnums.cs:32
ReturnCode GetPublisherQos(ref PublisherQos publisherQos, string id)
Resolves the PublisherQos identified by the id from the uri this QosProvider is associated with...
Definition: QosProvider.cs:398
This struct provides the basic mechanism for an application to specify Quality of Service attributes ...
This class provides the basic mechanism for an application to specify Quality of Service attributes f...
This struct provides the basic mechanism for an application to specify Quality of Service attributes ...
ReturnCode GetSubscriberQos(ref SubscriberQos subscriberQos, string id)
Resolves the SubscriberQos identified by the id from the uri this QosProvider is associated with...
Definition: QosProvider.cs:309
ReturnCode GetParticipantQos(ref DomainParticipantQos participantQos, string id)
Resolves the DomainParticipantQos identified by the id from the uri this QosProvider is associated wi...
Definition: QosProvider.cs:221
Create a QosProvider fetching QoS configuration from the specified URI.
Definition: QosProvider.cs:69