How to use IAS queries

The following example code illustrates successive IAS queries from the client side and subsequent closing of the RNetDatabase instance, ias. Note that the IASQuery() function employs two status words (one for the timeout and the other for the query). A much better way of handling the asynchroneity would be to use an active scheduler and queue the IAS request and timer on separate active objects.

// it is assumed here that addr is filled in from a successful
// discovery
//
// IAS QUERY
//
 RNetDatabase ias;
 ret=ias.Open(ss,protoInfo.addrFamily,protoInfo.protocol);

 if (ret==KErrNone)
  {
  // Successfully opened RNetDB
  }
 else
  {
  // Failed to open RNetDB
  }
 
 _LIT8(KTxtDevice,"Device");
 _LIT8(KTxtDeviceName,"DeviceName");
 _LIT8(KTxtIrDAIrCOMM,"IrDA:IrCOMM");
 _LIT8(KTxtParameters,"Parameters");
 _LIT8(KTxtIrDATinyTP,"IrDA:TinyTP:LsapSel");

 TUint remDevAddr=addr.GetRemoteDevAddr();
 IASQuery(ias,KTxtDevice,KTxtDeviceName,remDevAddr);
 IASQuery(ias,KTxtIrDAIrCOMM,KTxtParameters,remDevAddr);
 IASQuery(ias,KTxtIrDAIrCOMM,KTxtIrDATinyTP,remDevAddr); 

 ias.Close();     // Close RNetDB
 ...


void IASQuery(RNetDatabase &aIAS,const TDesC8 &aClassName,
  const TDesC8 &aAttributeName,TUint aRemDevAddr)
//
// Synchronous IAS query.  RTimer timeout of 5 seconds on the query.
//
 {
 TBuf<64>       res;
 TIASQuery      querybuf(aClassName,aAttributeName,aRemDevAddr);
 TRequestStatus stat1,stat2;
 TIASResponse   results;

 aIAS.Query(querybuf,results,stat2);
 RTimer tim;
 tim.CreateLocal();
 tim.After(stat1,5000000L);
 User::WaitForRequest(stat1,stat2);

 if (stat1.Int()==KErrNone)          // TIMER COMPLETED - IAS QUERY 
  {                              // REQUEST HAS TIMED OUT.
  aIAS.Cancel();
  return;
  } 

 else if (stat2.Int()==KErrNone)     // IAS QUERY COMPLETED OK.
  {
  switch(results.Type())
   {
  case EIASDataMissing:          // Missing
   break;

  case EIASDataInteger:          // Integer
   TInt num;
   if (results.GetInteger(num)==KErrNone)
    {
    TinyTPPort=TUint8(num);
    }
   else
    {
    // Bad type
    }
   break;

  case EIASDataOctetSequence:     // Byte sequence
   results.GetOctetSeq(res);
   DumpBuf(res);
   break;

  case EIASDataUserString:        // String. Use
   break;                     // results.GetCharString8()
                                         // to get string

  default:                        // Bad type
   break;
   }
  tim.Cancel();
  }

 else if (stat2.Int()!=KErrNone)      // IAS QUERY COMPLETED 
  {                               // UNSUCCESSFULLY.
  switch (stat2.Int())
   {
  case KErrUnknown:               // No such attribute
   break;

  case KErrBadName:               // No such class
   break;

  default:                        // Unknown error
   break;
   }
  tim.Cancel();
  }
 else
  {
  tim.Cancel();                   // Unknown error on IAS query
  }

 };