Exemple #1
0
            public static HpiDomain CreateDomain(string host,
                                                 int port,
                                                 SaHpiEntityPathT entity_root)
            {
                HpiDomain d = new HpiDomain(HpiConst.SAHPI_UNSPECIFIED_DOMAIN_ID,
                                            host,
                                            port,
                                            entity_root);
                bool ok = false;

                lock ( domains )
                {
                    for (long did = 0; did < long.MaxValue; ++did)
                    {
                        if (!domains.ContainsKey(did))
                        {
                            d.SetLocalDid(did);
                            domains[did] = d;
                            ok           = true;
                            break;
                        }
                    }
                }

                if (!ok)
                {
                    d = null;
                }

                return(d);
            }
Exemple #2
0
            /***********************************************************
             * Iterate over entity resource ids
             **********************************************************/
            public static IEnumerable <long> EntityResourceIds(long sid, SaHpiEntityPathT ep)
            {
                long id = HpiConst.SAHPI_FIRST_ENTRY;

                do
                {
                    long rid;
                    long instrid;
                    long rptcnt;
                    long rv = Api.saHpiGetIdByEntityPath(sid,
                                                         ep,
                                                         HpiConst.SAHPI_NO_RECORD,
                                                         ref id,
                                                         out rid,
                                                         out instrid,
                                                         out rptcnt);
                    if ((id == HpiConst.SAHPI_FIRST_ENTRY) && (rv == HpiConst.SA_ERR_HPI_NOT_PRESENT))
                    {
                        yield break;
                    }
                    if (rv != HpiConst.SA_OK)
                    {
                        yield break;
                    }
                    yield return(rid);
                } while (id != HpiConst.SAHPI_LAST_ENTRY);
            }
Exemple #3
0
            public static IEnumerable <ResourceIdInstrumentId> EntityInstrumentIds(long sid,
                                                                                   SaHpiEntityPathT ep,
                                                                                   long rdrtype)
            {
                long id = HpiConst.SAHPI_FIRST_ENTRY;

                do
                {
                    ResourceIdInstrumentId ri = new ResourceIdInstrumentId();
                    long rptcnt;
                    long rv = Api.saHpiGetIdByEntityPath(sid,
                                                         ep,
                                                         rdrtype,
                                                         ref id,
                                                         out ri.ResourceId,
                                                         out ri.InstrumentId,
                                                         out rptcnt);
                    if ((id == HpiConst.SAHPI_FIRST_ENTRY) && (rv == HpiConst.SA_ERR_HPI_NOT_PRESENT))
                    {
                        yield break;
                    }
                    if (rv != HpiConst.SA_OK)
                    {
                        yield break;
                    }
                    yield return(ri);
                } while (id != HpiConst.SAHPI_LAST_ENTRY);
            }
Exemple #4
0
            public static long oHpiDomainAdd(
                SaHpiTextBufferT Host,
                int Port,
                SaHpiEntityPathT EntityRoot,
                out long DomainId
                )
            {
                DomainId = 0;

                String s = HpiUtil.FromSaHpiTextBufferT(Host);

                if (s == null)
                {
                    return(HpiConst.SA_ERR_HPI_INVALID_PARAMS);
                }

                HpiDomain d = HpiCore.CreateDomain(s, Port, EntityRoot);

                if (d == null)
                {
                    return(HpiConst.SA_ERR_HPI_INTERNAL_ERROR);
                }

                DomainId = d.GetLocalDid();

                return(HpiConst.SA_OK);
            }
Exemple #5
0
            public static HpiDomain CreateDomain( string host,
                                          int port,
                                          SaHpiEntityPathT entity_root )
            {
                HpiDomain d = new HpiDomain( HpiConst.SAHPI_UNSPECIFIED_DOMAIN_ID,
                                     host,
                                     port,
                                     entity_root );
                bool ok = false;

                lock ( domains )
                {
                for ( long did = 0; did < long.MaxValue; ++did ) {
                if ( !domains.ContainsKey( did ) ) {
                    d.SetLocalDid( did );
                    domains[did] = d;
                    ok = true;
                    break;
                }
                }
                }

                if ( !ok ) {
                d = null;
                }

                return d;
            }
Exemple #6
0
            public static SaHpiEntityPathT MakeRootSaHpiEntityPathT()
            {
                SaHpiEntityPathT ep = MakeUnspecifiedSaHpiEntityPathT();

                ep.Entry[0].EntityType     = HpiConst.SAHPI_ENT_ROOT;
                ep.Entry[0].EntityLocation = 0;
                return(ep);
            }
 public HpiDomain(HpiDomain other)
 {
     this.local_did   = other.local_did;
     this.remote_did  = other.remote_did;
     this.remote_host = other.remote_host;
     this.remote_port = other.remote_port;
     this.entity_root = other.entity_root;
 }
Exemple #8
0
            static HpiCore()
            {
                domains  = new Dictionary <long, HpiDomain>();
                sessions = new Dictionary <long, HpiSession>();
                my_ep    = null;

                CreateDefaultDomain();
            }
Exemple #9
0
 public HpiDomain( HpiDomain other )
 {
     this.local_did   = other.local_did;
     this.remote_did  = other.remote_did;
     this.remote_host = other.remote_host;
     this.remote_port = other.remote_port;
     this.entity_root = other.entity_root;
 }
Exemple #10
0
            static HpiCore()
            {
                domains = new Dictionary<long, HpiDomain>();
                sessions = new Dictionary<long, HpiSession>();
                my_ep = null;

                CreateDefaultDomain();
            }
Exemple #11
0
 public HpiDomain( long local_did,
           string remote_host,
           int remote_port,
           SaHpiEntityPathT entity_root )
 {
     this.local_did   = local_did;
     this.remote_did  = HpiConst.SAHPI_UNSPECIFIED_DOMAIN_ID;
     this.remote_host = remote_host;
     this.remote_port = remote_port;
     this.entity_root = entity_root;
 }
Exemple #12
0
 /**********************************************************
  * Entity Path Helpers
  *********************************************************/
 public static SaHpiEntityPathT MakeUnspecifiedSaHpiEntityPathT()
 {
     SaHpiEntityPathT ep = new SaHpiEntityPathT();
     ep.Entry = new SaHpiEntityT[HpiConst.SAHPI_MAX_ENTITY_PATH];
     for ( int i = 0; i < HpiConst.SAHPI_MAX_ENTITY_PATH; ++i ) {
     ep.Entry[i] = new SaHpiEntityT();
     ep.Entry[i].EntityType = HpiConst.SAHPI_ENT_UNSPECIFIED;
     ep.Entry[i].EntityLocation = 0;
     }
     return ep;
 }
 public HpiDomain(long local_did,
                  string remote_host,
                  int remote_port,
                  SaHpiEntityPathT entity_root)
 {
     this.local_did   = local_did;
     this.remote_did  = HpiConst.SAHPI_UNSPECIFIED_DOMAIN_ID;
     this.remote_host = remote_host;
     this.remote_port = remote_port;
     this.entity_root = entity_root;
 }
Exemple #14
0
            /**********************************************************
             * Entity Path Helpers
             *********************************************************/
            public static SaHpiEntityPathT MakeUnspecifiedSaHpiEntityPathT()
            {
                SaHpiEntityPathT ep = new SaHpiEntityPathT();

                ep.Entry = new SaHpiEntityT[HpiConst.SAHPI_MAX_ENTITY_PATH];
                for (int i = 0; i < HpiConst.SAHPI_MAX_ENTITY_PATH; ++i)
                {
                    ep.Entry[i]                = new SaHpiEntityT();
                    ep.Entry[i].EntityType     = HpiConst.SAHPI_ENT_UNSPECIFIED;
                    ep.Entry[i].EntityLocation = 0;
                }
                return(ep);
            }
Exemple #15
0
            public static string FromSaHpiEntityPathT(SaHpiEntityPathT ep)
            {
                StringBuilder b = new StringBuilder();
                int           l = GetSaHpiEntityPathLength(ep);

                for (int i = (l - 1); i >= 0; --i)
                {
                    b.AppendFormat("{{{0},{1}}}",
                                   FromSaHpiEntityTypeT(ep.Entry[i].EntityType),
                                   ep.Entry[i].EntityLocation);
                }
                return(b.ToString());
            }
Exemple #16
0
            public static SaHpiEntityPathT ToSaHpiEntityPathT(string s)
            {
                SaHpiEntityPathT ep = MakeRootSaHpiEntityPathT();

                if (s.Length == 0)
                {
                    return(ep);
                }

                if (s.IndexOf('{') != 0)
                {
                    throw new FormatException();
                }

                int i = 0;

                string[] parts = s.Substring(1).Split(new Char[] { '{' });
                Array.Reverse(parts);
                foreach (string part in parts)
                {
                    if (!part.EndsWith("}"))
                    {
                        throw new FormatException();
                    }
                    string[] et_el = part.Substring(0, part.Length - 1).Split(new Char[] { ',' });
                    if (et_el.Length != 2)
                    {
                        throw new FormatException();
                    }
                    ep.Entry[i].EntityType = ToSaHpiEntityTypeT(et_el[0]);
                    try {
                        ep.Entry[i].EntityLocation = UInt32.Parse(et_el[1]);
                    } catch (Exception) {
                        throw new FormatException();
                    }
                    ++i;
                    if (i == HpiConst.SAHPI_MAX_ENTITY_PATH)
                    {
                        break;
                    }
                }
                if (i < HpiConst.SAHPI_MAX_ENTITY_PATH)
                {
                    ep.Entry[i].EntityType     = HpiConst.SAHPI_ENT_ROOT;
                    ep.Entry[i].EntityLocation = 0;
                }

                return(ep);
            }
Exemple #17
0
            public static SaHpiEntityPathT CloneSaHpiEntityPathT( SaHpiEntityPathT ep )
            {
                if ( ep == null ) {
                return null;
                }

                SaHpiEntityPathT ep2 = new SaHpiEntityPathT();
                ep2.Entry = new SaHpiEntityT[HpiConst.SAHPI_MAX_ENTITY_PATH];
                for ( int i = 0; i < HpiConst.SAHPI_MAX_ENTITY_PATH; ++i ) {
                ep2.Entry[i] = new SaHpiEntityT();
                ep2.Entry[i].EntityType = ep.Entry[i].EntityType;
                ep2.Entry[i].EntityLocation = ep.Entry[i].EntityLocation;
                }
                return ep2;
            }
Exemple #18
0
            private static int GetSaHpiEntityPathLength(SaHpiEntityPathT ep)
            {
                int i;

                for (i = 0; i < HpiConst.SAHPI_MAX_ENTITY_PATH; ++i)
                {
                    if ((ep.Entry[i].EntityType == HpiConst.SAHPI_ENT_ROOT))
                    {
                        if (ep.Entry[i].EntityLocation == 0)
                        {
                            break;
                        }
                    }
                }
                return(i);
            }
Exemple #19
0
 /**
  * Check function for HPI struct SaHpiEntityPathT
  */
 public static bool Check( SaHpiEntityPathT x )
 {
     if ( x == null ) {
     return false;
     }
     if ( x.Entry == null ) {
     return false;
     }
     if ( x.Entry.Length != HpiConst.SAHPI_MAX_ENTITY_PATH ) {
     return false;
     }
     for ( int i = 0; i < HpiConst.SAHPI_MAX_ENTITY_PATH; ++i ) {
     if ( !Check( x.Entry[i] ) ) {
     return false;
     }
     }
     return true;
 }
Exemple #20
0
            public static SaHpiEntityPathT CloneSaHpiEntityPathT(SaHpiEntityPathT ep)
            {
                if (ep == null)
                {
                    return(null);
                }

                SaHpiEntityPathT ep2 = new SaHpiEntityPathT();

                ep2.Entry = new SaHpiEntityT[HpiConst.SAHPI_MAX_ENTITY_PATH];
                for (int i = 0; i < HpiConst.SAHPI_MAX_ENTITY_PATH; ++i)
                {
                    ep2.Entry[i]                = new SaHpiEntityT();
                    ep2.Entry[i].EntityType     = ep.Entry[i].EntityType;
                    ep2.Entry[i].EntityLocation = ep.Entry[i].EntityLocation;
                }
                return(ep2);
            }
Exemple #21
0
            /**********************************************************
             * Creates and returns new domain with specified Domain Id
             * Returns null if overwrite == false and
             * the specified Domain Id is already in use
             *********************************************************/
            public static HpiDomain CreateDomainById(long did,
                                                     string host,
                                                     int port,
                                                     SaHpiEntityPathT entity_root,
                                                     bool overwrite)
            {
                HpiDomain d = null;

                lock ( domains )
                {
                    if ((!domains.ContainsKey(did)) || overwrite)
                    {
                        d            = new HpiDomain(did, host, port, entity_root);
                        domains[did] = d;
                    }
                }

                return(d);
            }
Exemple #22
0
            /***********************************************************
             * Iterate over child entities
             **********************************************************/
            public static IEnumerable <SaHpiEntityPathT> ChildEntities(long sid, SaHpiEntityPathT parent_ep)
            {
                long id = HpiConst.SAHPI_FIRST_ENTRY;

                do
                {
                    long             rptcnt;
                    SaHpiEntityPathT child_ep;
                    long             rv = Api.saHpiGetChildEntityPath(sid, parent_ep, ref id, out child_ep, out rptcnt);
                    if ((id == HpiConst.SAHPI_FIRST_ENTRY) && (rv == HpiConst.SA_ERR_HPI_NOT_PRESENT))
                    {
                        yield break;
                    }
                    if (rv != HpiConst.SA_OK)
                    {
                        yield break;
                    }
                    yield return(child_ep);
                } while (id != HpiConst.SAHPI_LAST_ENTRY);
            }
Exemple #23
0
            public static long saHpiMyEntityPathGet(
                long SessionId,
                out SaHpiEntityPathT EntityPath
                )
            {
                EntityPath = null;

                HpiSession s = HpiCore.GetSession(SessionId);

                if (s == null)
                {
                    return(HpiConst.SA_ERR_HPI_INVALID_SESSION);
                }
                EntityPath = HpiCore.GetMyEntity();
                if (EntityPath == null)
                {
                    return(HpiConst.SA_ERR_HPI_UNKNOWN);
                }

                return(HpiConst.SA_OK);
            }
Exemple #24
0
            public static long oHpiDomainAdd(
        SaHpiTextBufferT Host,
        int Port,
        SaHpiEntityPathT EntityRoot,
        out long DomainId
    )
            {
                DomainId = 0;

                string s = HpiUtil.FromSaHpiTextBufferT( Host );
                if ( s == null ) {
                return HpiConst.SA_ERR_HPI_INVALID_PARAMS;
                }

                HpiDomain d = HpiCore.CreateDomain( s, Port, EntityRoot );
                if ( d == null ) {
                return HpiConst.SA_ERR_HPI_INTERNAL_ERROR;
                }

                DomainId = d.GetLocalDid();

                return HpiConst.SA_OK;
            }
Exemple #25
0
 public static string FromSaHpiEntityPathT( SaHpiEntityPathT ep )
 {
     StringBuilder b = new StringBuilder();
     int l = GetSaHpiEntityPathLength( ep );
     for ( int i = ( l - 1 ); i >= 0; --i ) {
     b.AppendFormat( "{{{0},{1}}}",
                 FromSaHpiEntityTypeT( ep.Entry[i].EntityType ),
                 ep.Entry[i].EntityLocation );
     }
     return b.ToString();
 }
Exemple #26
0
            /**********************************************************
             * Creates and returns new domain with specified Domain Id
             * Returns null if overwrite == false and
             * the specified Domain Id is already in use
             *********************************************************/
            public static HpiDomain CreateDomainById( long did,
                                              string host,
                                              int port,
                                              SaHpiEntityPathT entity_root,
                                              bool overwrite )
            {
                HpiDomain d = null;

                lock ( domains )
                {
                if ( ( !domains.ContainsKey( did ) ) || overwrite ) {
                d = new HpiDomain( did, host, port, entity_root );
                domains[did] = d;
                }
                }

                return d;
            }
Exemple #27
0
            public static long saHpiMyEntityPathGet(
        long SessionId,
        out SaHpiEntityPathT EntityPath
    )
            {
                EntityPath = null;

                HpiSession s = HpiCore.GetSession( SessionId );
                if ( s == null ) {
                return HpiConst.SA_ERR_HPI_INVALID_SESSION;
                }
                EntityPath = HpiCore.GetMyEntity();
                if ( EntityPath == null ) {
                return HpiConst.SA_ERR_HPI_UNKNOWN;
                }

                return HpiConst.SA_OK;
            }
Exemple #28
0
            public SaHpiEntityPathT DemarshalSaHpiEntityPathT()
            {
                SaHpiEntityPathT x = new SaHpiEntityPathT();

                x.Entry = new SaHpiEntityT[HpiConst.SAHPI_MAX_ENTITY_PATH];
                for ( int i = 0; i < HpiConst.SAHPI_MAX_ENTITY_PATH; ++i ) {
                x.Entry[i] = DemarshalSaHpiEntityT();
                }

                return x;
            }
Exemple #29
0
 public static void SetMyEntity( SaHpiEntityPathT ep )
 {
     my_ep = HpiUtil.CloneSaHpiEntityPathT( ep );
 }
Exemple #30
0
 /***********************************************************
  * Iterate over child entities
  **********************************************************/
 public static IEnumerable<SaHpiEntityPathT> ChildEntities( long sid, SaHpiEntityPathT parent_ep )
 {
     long id = HpiConst.SAHPI_FIRST_ENTRY;
     do {
     long rptcnt;
     SaHpiEntityPathT child_ep;
     long rv = Api.saHpiGetChildEntityPath( sid, parent_ep, ref id, out child_ep, out rptcnt );
     if ( ( id == HpiConst.SAHPI_FIRST_ENTRY ) && ( rv == HpiConst.SA_ERR_HPI_NOT_PRESENT ) ) {
     yield break;
     }
     if ( rv != HpiConst.SA_OK ) {
     yield break;
     }
     yield return child_ep;
     } while ( id != HpiConst.SAHPI_LAST_ENTRY );
 }
Exemple #31
0
 public static IEnumerable<ResourceIdInstrumentId> EntityInstrumentIds( long sid,
                                                                SaHpiEntityPathT ep,
                                                                long rdrtype )
 {
     long id = HpiConst.SAHPI_FIRST_ENTRY;
     do {
     ResourceIdInstrumentId ri = new ResourceIdInstrumentId();
     long rptcnt;
     long rv = Api.saHpiGetIdByEntityPath( sid,
                                       ep,
                                       rdrtype,
                                       ref id,
                                       out ri.ResourceId,
                                       out ri.InstrumentId,
                                       out rptcnt );
     if ( ( id == HpiConst.SAHPI_FIRST_ENTRY ) && ( rv == HpiConst.SA_ERR_HPI_NOT_PRESENT ) ) {
     yield break;
     }
     if ( rv != HpiConst.SA_OK ) {
     yield break;
     }
     yield return ri;
     } while ( id != HpiConst.SAHPI_LAST_ENTRY );
 }
Exemple #32
0
            public static long saHpiGetChildEntityPath(
        long SessionId,
        SaHpiEntityPathT ParentEntityPath,
        ref long InstanceId,
        out SaHpiEntityPathT ChildEntityPath,
        out long RptUpdateCount
    )
            {
                long rv;
                bool rc;

                ChildEntityPath = null;
                RptUpdateCount = 0;

                rc = HpiUtil.Check( ParentEntityPath );
                if ( !rc ) {
                return HpiConst.SA_ERR_HPI_INVALID_PARAMS;
                }

                HpiSession s = HpiCore.GetSession( SessionId );
                if ( s == null ) {
                return HpiConst.SA_ERR_HPI_INVALID_SESSION;
                }
                OhpiMarshal m = s.GetMarshal();
                if ( m == null ) {
                return HpiConst.SA_ERR_HPI_NO_RESPONSE;
                }

                m.MarshalSaHpiSessionIdT( s.GetRemoteSid() );
                m.MarshalSaHpiEntityPathT( ParentEntityPath );
                m.MarshalSaHpiUint32T( InstanceId );
                rc = m.Interchange( OhpiConst.RPC_SAHPI_GET_CHILD_ENTITY_PATH );
                if ( !rc ) {
                m.Close();
                return HpiConst.SA_ERR_HPI_NO_RESPONSE;
                }
                rv = m.DemarshalSaErrorT();
                if ( rv == HpiConst.SA_OK ) {
                InstanceId = m.DemarshalSaHpiUint32T();
                ChildEntityPath = m.DemarshalSaHpiEntityPathT();
                RptUpdateCount = m.DemarshalSaHpiUint32T();
                }
                s.PutMarshal( m );

                return rv;
            }
Exemple #33
0
            public static long saHpiGetIdByEntityPath(
        long SessionId,
        SaHpiEntityPathT EntityPath,
        long InstrumentType,
        ref long InstanceId,
        out long ResourceId,
        out long InstrumentId,
        out long RptUpdateCount
    )
            {
                long rv;
                bool rc;

                ResourceId = 0;
                InstrumentId = 0;
                RptUpdateCount = 0;

                rc = HpiUtil.Check( EntityPath );
                if ( !rc ) {
                return HpiConst.SA_ERR_HPI_INVALID_PARAMS;
                }

                HpiSession s = HpiCore.GetSession( SessionId );
                if ( s == null ) {
                return HpiConst.SA_ERR_HPI_INVALID_SESSION;
                }
                OhpiMarshal m = s.GetMarshal();
                if ( m == null ) {
                return HpiConst.SA_ERR_HPI_NO_RESPONSE;
                }

                m.MarshalSaHpiSessionIdT( s.GetRemoteSid() );
                m.MarshalSaHpiEntityPathT( EntityPath );
                m.MarshalSaHpiRdrTypeT( InstrumentType );
                m.MarshalSaHpiUint32T( InstanceId );
                rc = m.Interchange( OhpiConst.RPC_SAHPI_GET_ID_BY_ENTITY_PATH );
                if ( !rc ) {
                m.Close();
                return HpiConst.SA_ERR_HPI_NO_RESPONSE;
                }
                rv = m.DemarshalSaErrorT();
                if ( rv == HpiConst.SA_OK ) {
                InstanceId = m.DemarshalSaHpiUint32T();
                ResourceId = m.DemarshalSaHpiResourceIdT();
                InstrumentId = m.DemarshalSaHpiInstrumentIdT();
                RptUpdateCount = m.DemarshalSaHpiUint32T();
                }
                s.PutMarshal( m );

                return rv;
            }
Exemple #34
0
 /***********************************************************
  * Iterate over entity resource ids
  **********************************************************/
 public static IEnumerable<long> EntityResourceIds( long sid, SaHpiEntityPathT ep )
 {
     long id = HpiConst.SAHPI_FIRST_ENTRY;
     do {
     long rid;
     long instrid;
     long rptcnt;
     long rv = Api.saHpiGetIdByEntityPath( sid,
                                       ep,
                                       HpiConst.SAHPI_NO_RECORD,
                                       ref id,
                                       out rid,
                                       out instrid,
                                       out rptcnt );
     if ( ( id == HpiConst.SAHPI_FIRST_ENTRY ) && ( rv == HpiConst.SA_ERR_HPI_NOT_PRESENT ) ) {
     yield break;
     }
     if ( rv != HpiConst.SA_OK ) {
     yield break;
     }
     yield return rid;
     } while ( id != HpiConst.SAHPI_LAST_ENTRY );
 }
Exemple #35
0
 private static int GetSaHpiEntityPathLength( SaHpiEntityPathT ep )
 {
     int i;
     for ( i = 0; i < HpiConst.SAHPI_MAX_ENTITY_PATH; ++i ) {
     if ( ( ep.Entry[i].EntityType == HpiConst.SAHPI_ENT_ROOT ) ) {
     if ( ep.Entry[i].EntityLocation == 0 ) {
         break;
     }
     }
     }
     return i;
 }
Exemple #36
0
 public static void SetMyEntity(SaHpiEntityPathT ep)
 {
     my_ep = HpiUtil.CloneSaHpiEntityPathT(ep);
 }
Exemple #37
0
 public void MarshalSaHpiEntityPathT( SaHpiEntityPathT x )
 {
     for ( int i = 0; i < HpiConst.SAHPI_MAX_ENTITY_PATH; ++i ) {
     MarshalSaHpiEntityT( x.Entry[i] );
     }
 }
Exemple #38
0
    public static void Main()
    {
        long rv;
        long did;
        long sid;

        rv = Api.oHpiDomainAdd(HpiUtil.ToSaHpiTextBufferT("localhost"),
                               OhpiConst.DEFAULT_PORT,
                               HpiUtil.MakeRootSaHpiEntityPathT(),
                               out did);
        if (rv != HpiConst.SA_OK)
        {
            Console.WriteLine("Error: oHpiDomainAdd: {0}", rv);
            return;
        }

        rv = Api.saHpiSessionOpen(did, out sid, null);
        if (rv != HpiConst.SA_OK)
        {
            Console.WriteLine("Error: saHpiSessionOpen: {0}", rv);
            return;
        }

        // DRT
        Console.WriteLine("");
        Console.WriteLine("DRT:");
        foreach (var drte in HpiIterators.Drt(sid))
        {
            Console.WriteLine("  HPI Domain {0}: Is Peer {1}",
                              drte.DomainId,
                              drte.IsPeer);
        }

        // DAT
        Console.WriteLine("");
        Console.WriteLine("DAT:");
        foreach (var a in HpiIterators.Dat(sid))
        {
            Console.WriteLine("  Alarm {0}: {1}: {2}",
                              a.AlarmId,
                              HpiUtil.FromSaHpiSeverityT(a.Severity),
                              HpiUtil.FromSaHpiStatusCondTypeT(a.AlarmCond.Type));
        }

        // DEL: Read backward
        Console.WriteLine("");
        Console.WriteLine("DEL: Newest entries first");
        foreach (var ex in HpiIterators.EventLogEntries(sid, HpiConst.SAHPI_UNSPECIFIED_RESOURCE_ID, false))
        {
            Console.WriteLine("  Entry {0}: {1}",
                              ex.EventLogEntry.EntryId,
                              HpiUtil.FromSaHpiEventTypeT(ex.EventLogEntry.Event.EventType));
        }

        // Iterate over top-level entities
        Console.WriteLine("");
        Console.WriteLine("Top-level Entities:");
        SaHpiEntityPathT root = HpiUtil.MakeRootSaHpiEntityPathT();

        foreach (var child in HpiIterators.ChildEntities(sid, root))
        {
            Console.WriteLine("  {0}", HpiUtil.FromSaHpiEntityPathT(child));
            // Resources for the entity
            Console.WriteLine("    Resources:");
            foreach (var rid in HpiIterators.EntityResourceIds(sid, child))
            {
                Console.WriteLine("      Resource {0}", rid);
            }
            // Sensors for the entity
            Console.WriteLine("    Sensors:");
            foreach (var ri in HpiIterators.EntityInstrumentIds(sid, child, HpiConst.SAHPI_SENSOR_RDR))
            {
                Console.WriteLine("      Resource {0} Sensor {1}", ri.ResourceId, ri.InstrumentId);
            }
        }

        // RPT
        Console.WriteLine("");
        Console.WriteLine("RPT:");
        foreach (var rpte in HpiIterators.Rpt(sid))
        {
            Console.WriteLine("  Resource {0}: {1}: {2}",
                              rpte.ResourceId,
                              HpiUtil.FromSaHpiTextBufferT(rpte.ResourceTag),
                              HpiUtil.FromSaHpiEntityPathT(rpte.ResourceEntity));
        }

        // RDRs
        Console.WriteLine("");
        Console.WriteLine("RDRs:");
        foreach (var rpte in HpiIterators.Rpt(sid))
        {
            Console.WriteLine("  Resource {0}:", rpte.ResourceId);
            foreach (var rdr in HpiIterators.Rdrs(sid, rpte.ResourceId))
            {
                Console.WriteLine("    {0}: {1}",
                                  HpiUtil.FromSaHpiRdrTypeT(rdr.RdrType),
                                  HpiUtil.FromSaHpiTextBufferT(rdr.IdString));
            }
        }

        // IDR Areas (LINQ is used to select IDRs as an example)
        Console.WriteLine("");
        Console.WriteLine("IDRs:");
        var idrs = from rpte in HpiIterators.Rpt(sid)
                   from rdr in HpiIterators.Rdrs(sid, rpte.ResourceId)
                   where rdr.RdrType == HpiConst.SAHPI_INVENTORY_RDR
                   select new { rid = rpte.ResourceId, idrid = rdr.RdrTypeUnion.InventoryRec.IdrId };

        foreach (var ri in idrs)
        {
            Console.WriteLine("  Resource {0}: IDR {1}:", ri.rid, ri.idrid);
            // IDR Areas
            foreach (var ahdr in HpiIterators.IdrAreaHeaders(sid, ri.rid, ri.idrid))
            {
                Console.WriteLine("    Area {0}: {1}",
                                  ahdr.AreaId,
                                  HpiUtil.FromSaHpiIdrAreaTypeT(ahdr.Type));
                // IDR Fields
                foreach (var f in HpiIterators.IdrAreaFields(sid, ri.rid, ri.idrid, ahdr.AreaId))
                {
                    Console.WriteLine("      Field {0}: {1}",
                                      f.FieldId,
                                      HpiUtil.FromSaHpiIdrFieldTypeT(f.Type));
                }
            }
        }

        // Announcements in Annunciators (LINQ is used to select annunciators as an example)
        Console.WriteLine("");
        Console.WriteLine("Annunciators:");
        var anns = from rpte in HpiIterators.Rpt(sid)
                   from rdr in HpiIterators.Rdrs(sid, rpte.ResourceId)
                   where rdr.RdrType == HpiConst.SAHPI_ANNUNCIATOR_RDR
                   select new { rid = rpte.ResourceId, annnum = rdr.RdrTypeUnion.AnnunciatorRec.AnnunciatorNum };

        foreach (var ri in anns)
        {
            Console.WriteLine("  Resource {0}: Annunciator {1}:", ri.rid, ri.annnum);
            // Announcements
            foreach (var a in HpiIterators.Announcements(sid, ri.rid, ri.annnum))
            {
                Console.WriteLine("    Announcement {0}: {1}: {2}",
                                  a.EntryId,
                                  HpiUtil.FromSaHpiSeverityT(a.Severity),
                                  HpiUtil.FromSaHpiStatusCondTypeT(a.StatusCond.Type));
            }
        }

        // FUMI (LINQ is used to select FUMIs with Logical Bank only as an example)
        Console.WriteLine("");
        Console.WriteLine("FUMIs:");
        var fumis = from rpte in HpiIterators.Rpt(sid)
                    from rdr in HpiIterators.Rdrs(sid, rpte.ResourceId)
                    where rdr.RdrType == HpiConst.SAHPI_FUMI_RDR
                    where rdr.RdrTypeUnion.FumiRec.NumBanks == 0
                    select new { rid = rpte.ResourceId, fuminum = rdr.RdrTypeUnion.FumiRec.Num };

        foreach (var ri in fumis)
        {
            Console.WriteLine("  Resource {0}: FUMI {1}:", ri.rid, ri.fuminum);
            // Source components
            Console.WriteLine("    Source Components:");
            foreach (var info in HpiIterators.FumiSourceComponents(sid, ri.rid, ri.fuminum, 0))
            {
                Console.WriteLine("      Component {0}: {1}: FW {2}.{3}.{4}",
                                  info.ComponentId,
                                  HpiUtil.FromSaHpiTextBufferT(info.MainFwInstance.Description),
                                  info.MainFwInstance.MajorVersion,
                                  info.MainFwInstance.MinorVersion,
                                  info.MainFwInstance.AuxVersion);
            }
            // Target components
            Console.WriteLine("    Target Components:");
            foreach (var info in HpiIterators.FumiTargetComponents(sid, ri.rid, ri.fuminum, 0))
            {
                Console.WriteLine("      Component {0}: {1}: FW {2}.{3}.{4}",
                                  info.ComponentId,
                                  HpiUtil.FromSaHpiTextBufferT(info.MainFwInstance.Description),
                                  info.MainFwInstance.MajorVersion,
                                  info.MainFwInstance.MinorVersion,
                                  info.MainFwInstance.AuxVersion);
            }
            // Logical Target components
            Console.WriteLine("    Logical Target Components:");
            foreach (var info in HpiIterators.FumiLogicalTargetComponents(sid, ri.rid, ri.fuminum))
            {
                Console.WriteLine("      Component {0}:", info.ComponentId);
                if (info.PendingFwInstance.InstancePresent != HpiConst.SAHPI_FALSE)
                {
                    Console.WriteLine("        Pending FW {0}.{1}.{2}:",
                                      info.PendingFwInstance.MajorVersion,
                                      info.PendingFwInstance.MinorVersion,
                                      info.PendingFwInstance.AuxVersion);
                }
                if (info.RollbackFwInstance.InstancePresent != HpiConst.SAHPI_FALSE)
                {
                    Console.WriteLine("        Rollback FW {0}.{1}.{2}:",
                                      info.RollbackFwInstance.MajorVersion,
                                      info.RollbackFwInstance.MinorVersion,
                                      info.RollbackFwInstance.AuxVersion);
                }
            }
        }

        rv = Api.saHpiSessionClose(sid);
        if (rv != HpiConst.SA_OK)
        {
            Console.WriteLine("Error: saHpiSessionClose: {0}", rv);
            return;
        }
    }