Hi Anton,

Entres implementation has been useful to me, thanks for pointing this out. 
Based on this implementation I wrote sample program attached with this mail. 
Though I am getting compilation error at line 151 which is pasted below: (I am 
not able to figure out why compilation should complain here, passed type seems 
correct to me)





[root@rmtestvm1 clients]# ./rmComp.sh

rmClient.c:43: warning: no previous prototype for âget_string_paramâ

rmClient.c:56: warning: no previous prototype for âask_entityâ

rmClient.c: In function âmainâ:

rmClient.c:151: error: invalid type argument of âunary *â

rmClient.c:159: warning: implicit declaration of function âprocâ

rmClient.c:88: warning: unused variable ârptentryidâ

libtool: link: gcc -pthread -I/usr/include/glib-2.0 
-I/usr/lib64/glib-2.0/include -O0 -ggdb3 -Wall -Wmissing-prototypes 
-Wmissing-declarations -Wstrict-prototypes -Wpointer-arith -Wformat=2 
-Wformat-security -Wformat-nonliteral -Wno-format-y2k -Wcast-qual -Wcast-align 
-Wno-strict-aliasing -fno-strict-aliasing -Wno-unused-value -D_GNU_SOURCE 
-D_REENTRANT -fexceptions -o .libs/rmClient rmClient.o clients.o -pthread  
../baselib/.libs/libopenhpi.so -L/lib64 
/root/preeti/openhpi-2.15.1/transport/.libs/libopenhpitransport.so 
/root/preeti/openhpi-2.15.1/marshal/.libs/libopenhpimarshal.so 
/root/preeti/openhpi-2.15.1/utils/.libs/libopenhpiutils.so -lltdl -lssl 
-lgthread-2.0 -lglib-2.0 -lm -lpthread -pthread

gcc: rmClient.o: No such file or directory

gcc -pthread -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -O0 -ggdb3 
-Wall -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes 
-Wpointer-arith -Wformat=2 -Wformat-security -Wformat-nonliteral 
-Wno-format-y2k -Wcast-qual -Wcast-align -Wno-strict-aliasing 
-fno-strict-aliasing -Wno-unused-value -D_GNU_SOURCE -D_REENTRANT -fexceptions 
-o .libs/rmClient rmClient.o clients.o -pthread ../baselib/.libs/libopenhpi.so 
/root/preeti/openhpi-2.15.1/transport/.libs/libopenhpitransport.so 
/root/preeti/openhpi-2.15.1/marshal/.libs/libopenhpimarshal.so 
/root/preeti/openhpi-2.15.1/utils/.libs/libopenhpiutils.so -pthread  -L/lib64 
-lltdl -lssl -lgthread-2.0 -lglib-2.0 -lm -lpthread

gcc: rmClient.o: No such file or directory



Regards,

Preeti



-----Original Message-----
From: Anton Pak [mailto:[email protected]]
Sent: Monday, February 21, 2011 6:53 PM
To: [email protected]; Preeti Sharma
Subject: Re: [Openhpi-devel] How to get rpt resourceId from Entity Path?



Preeti,



Could you try "lsent", "entres" and "entinstr" commands in hpi_shell?



      Anton Pak



On Tue, 22 Feb 2011 02:42:53 +0300, Preeti Sharma

<[email protected]> wrote:



> Hi,

> I want to extract RDRs using Entity Path. I tried to do this by calling

> method saHpiGetIdByEntityPath to get Rpt resourceId and then use this

> resource Id in method saHpiRdrGet to get RDRs. My sample program is

> calling saHpiGetIdByEntityPath though it is failing with error

> INVALID_PARAMS . Sample program and shell script (I used to compile this

> client in client directory of openhpi source code) is attached with this

> mail. Please let me know what correction is required in this program or

> any other way if I am not calling right method.

>

> Regards,

> Preeti

>
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <string.h>

#include <SaHpi.h>
#include <oh_utils.h>
#include <oh_clients.h>

#define OH_SVN_REV "$Revision: 7189 $"

#include <unistd.h>

#define HPI_NSEC_PER_SEC 1000000000LL
#define SHOW_BUF_SZ     1024

int fdebug = 1;

typedef enum {
        HPI_SHELL_OK = 0,
        HPI_SHELL_CMD_ERROR = -1,
        HPI_SHELL_PARM_ERROR = -2,
        HPI_SHELL_SYNTAX_ERROR = -3
} ret_code_t;

typedef enum {
        CMD_TERM,
        ITEM_TERM,
        CMD_END_TERM,
        CMD_REDIR_TERM,
        CMD_ERROR_TERM,
        EMPTY_TERM
} term_t;

typedef struct {
        term_t  term_type;
        char    *term;
} term_def_t;

SaHpiDomainIdT domainid = SAHPI_UNSPECIFIED_DOMAIN_ID;

int get_string_param(char *mes, char *val, int len)
{
        char*      entity_str;
        int             i;

        gets(entity_str);
        memset(val, 0, len);
        strncpy(val, entity_str, len);
        for (i = 0; i < len; i++)
                if (val[i] == '\n') val[i] = 0;
        return(0);
}

ret_code_t ask_entity(SaHpiEntityPathT *ret)
{
        int     res;
    SaErrorT rv;
    char buf[256];
    const char * epstr;

        SaHpiEntityPathT root;
        root.Entry[0].EntityType = SAHPI_ENT_ROOT;
        root.Entry[0].EntityLocation = 0;

                res = get_string_param("Entity Path ==> ", buf, sizeof(buf));
                if (res != 0) {
            printf("Invalid entity path");
            return(HPI_SHELL_PARM_ERROR);
        }
        epstr = buf;

    rv = oh_encode_entitypath(epstr, ret);
    if ( rv != SA_OK ) {
        printf("Invalid entity path");
    }

        return 0;
}

int main(int argc, char **argv)
{
        int do_discover_after_subscribe = 0;
        SaErrorT rv;
        SaHpiSessionIdT sessionid;
        SaHpiDomainInfoT domainInfo;
        SaHpiRptEntryT rptentry;
        SaHpiEntryIdT rptentryid;

        memset(&rptentry, 0, sizeof(rptentry));

        oh_prog_version(argv[0], OH_SVN_REV);

        rv = saHpiSessionOpen(domainid, &sessionid, NULL);
        if (rv != SA_OK) {
                if (rv == SA_ERR_HPI_ERROR) 
                        printf("saHpiSessionOpen: error %d, SpiLibd not 
running\n", rv);
                else
                        printf("saHpiSessionOpen: %s\n", oh_lookup_error(rv));
                exit(-1);
        }
 
        if (!do_discover_after_subscribe) {
                if (fdebug) printf("saHpiDiscover\n");
                rv = saHpiDiscover(sessionid);
                if (rv != SA_OK) {
                        printf("saHpiDiscover: %s\n", oh_lookup_error(rv));
                        exit(-1);
                }
        }
        
        if (fdebug) printf( "Subscribe to events\n");
        rv = saHpiSubscribe( sessionid );
        if (rv != SA_OK) {
                printf("saHpiSubscribe: %s\n", oh_lookup_error(rv));
                exit(-1);
        }

        if (do_discover_after_subscribe) {
                if (fdebug) printf("saHpiDiscover after saHpiSubscribe\n");
                rv = saHpiDiscover(sessionid);
                if (rv != SA_OK) {
                        printf("saHpiDiscover after saHpiSubscribe: %s\n", 
oh_lookup_error(rv));
                        exit(-1);
                }
        }

        rv = saHpiDomainInfoGet(sessionid, &domainInfo);

        if (fdebug) printf("saHpiDomainInfoGet %s\n", oh_lookup_error(rv));
        printf("DomainInfo: UpdateCount = %u, UpdateTime = %lx\n",
                domainInfo.RptUpdateCount, (unsigned 
long)domainInfo.RptUpdateTimestamp);

        /* walk the RPT list */
    SaHpiResourceIdT rid;
    SaHpiInstrumentIdT instr;
    SaHpiUint32T update_cnt;
    SaHpiEntityPathT ep;
    char buf[SHOW_BUF_SZ];
    ret_code_t ret;

    ret = ask_entity(&ep);

    rv = SA_OK;
    SaHpiUint32T i = SAHPI_FIRST_ENTRY;
    SaHpiBoolT first = SAHPI_TRUE;
    SaHpiBoolT found = SAHPI_FALSE;
    SaHpiRdrTypeT type = SAHPI_NO_RECORD;
    while ( rv == SA_OK ) {
        buf[0] = '\0';
        rv = saHpiGetIdByEntityPath( sessionid, *ep, type, &i, &rid, &instr, 
&update_cnt );
        if ( rv != SA_OK ) {
            break;
        }
        if ( type == SAHPI_NO_RECORD ) {
            snprintf( buf, SHOW_BUF_SZ, "  Resource %u\n", rid );
        } 

        proc( buf );
        found = SAHPI_TRUE;
        first = SAHPI_FALSE;
        if ( i == SAHPI_LAST_ENTRY ) {
            break;
        }

    }
    if ( found == SAHPI_FALSE ) {
        if ( type == SAHPI_NO_RECORD ) {
            proc( "  No resources found\n" );
        }
    }

    rv = saHpiSessionClose(sessionid);
    return(0);
}
 
/* end hpigetevents.c */
------------------------------------------------------------------------------
Free Software Download: Index, Search & Analyze Logs and other IT data in 
Real-Time with Splunk. Collect, index and harness all the fast moving IT data 
generated by your applications, servers and devices whether physical, virtual
or in the cloud. Deliver compliance at lower cost and gain new business 
insights. http://p.sf.net/sfu/splunk-dev2dev 
_______________________________________________
Openhpi-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openhpi-devel

Reply via email to