If you are expecting ARInitialization to fail because of a bad server name, or 
user/password - it won't.  ARInitialization simply setus up some client side 
state, and in general won't fail.  It doesn't actually connect to the server.
 
You first "real" API call (ARGetListSchema), or a call to ARVerifyUser, will 
actually test out that the server/user/password is fine.
 
First of all, you should not use the C API without RTL.  
(http://www.sourceforge.net/projects/rtl).  It will reduce your C code below by 
80 or 90% and make it much more bulletproof.  Everything you've done would be 
about 8 lines of code (see below).  To see why and another comparison, go to 
http://rtl.sourceforge.net/doc.  With rtl, you won't have to worry about 
freeing status lists, allocating memory, testing errors after every call, doing 
expensive lookups with for loops, etc.  I cringe looking at how verbose and 
error prone API programs are without it.  Oh yes, I almost forgot - it's free 
and open source.
 
Here is what your code would loook like using RTL (taken straight from the 
docs).  This does everything for you (memory management, error handling, etc.). 
 All those checks for error codes and calls to FreeARStatusList go away for 
starters (whew).
 
 try {
   Server server("localhost", "Demo", "");
   NameList names;
   server.getListSchema(names);
   NameList::iterator iter = names.begin();
   for (; iter != names.end(); iter++) {
       cout << (*iter).getName().c_str() << "\n";
   }
 } catch (Exception &err) {
   cerr << err.toString().c_str();
 }
Regards, 
Dan Hardy
Co-Founder and Chief Architect
Pathworks Software
http://www/pathworkssoftware.com/
Get Work Done Right, Every Time.
 


________________________________

From: Action Request System discussion list(ARSList) on behalf of Marc Nations
Sent: Fri 10/27/2006 9:47 PM
To: arslist@ARSLIST.ORG
Subject: Newb needs API help...couple of questions


** Hello all,

For starters, I'm trying to integrate the Remedy API into a Python
application. That is my ultimate goal. So if anyone has any experience
with that or knows where some sample code is, I'd appreciate it. I'm 
going to use ctypes to make the dll calls and am building the
structures.

However, I've hit a wall so far with Python so I decided to run some
example code in C and follow the process. I don't understand what is 
happening here, so I'm hoping someone could explain it to me. I am
running the example given in the Remedy API documentation (with a
couple of small modifications):

Let me start off by saying that the code works, however almost 
seemingly by accident. The problem is when I step through it using
Visual Studio, it doesn't respond like I thought it would. Here's the
problem:

Right now I have the application set up to fail at the initialization 
stage. So at Step A (marked below) I should see a failure after the
ARInitialization call is made. However that is not the case. Instead I
get back a response of '0', and it does not fall into the exception
loop. 

Instead it moves on and attempts the ARGetListSchema call. At Step B is
when the error for the initialization is actually recognized. So then
it falls in the exception loop, prints out the error that was supposed 
to be printed in ARInit loop, and finishes execution.

This also means that the status list is not being freed like is
supposed to happen during the FreeARStatusList proc. It's still there
when the next function is called. 

So in the end the application does work, but it's not failing at the
correct place. So until I understand how this is supposed to properly
work, there's no way I'll be able to get it interfaced over to another 
language. Does anyone know what either I or it is doing wrong?

Thanks,
Marc


// ARS.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include " ar.h"
#include "arextern.h"
#include "arfree.h"

void printStatusList(ARStatusList *theList)
{
       unsigned int i;
       for (i=0; i< theList -> numItems; i++)
       {
               if (theList -> statusList[i].appendedText == NULL ||
                       theList -> statusList[i].appendedText == '\0')
                       printf("%s", theList -> statusList[i].messageText); 
               else
                       printf("%s:%s", theList -> statusList[i].messageText,
                               theList -> statusList[i].appendedText);
                       printf("(ARERR %d)\n", theList -> 
statusList[i].messageNum); 
                       printf("(Type %d)\n", theList -> 
statusList[i].messageType);
       }
}

int main(void)
{
       ARControlStruct control =
{0,0,"TEST_REMEDY","TEST 
_REMEDY02","",0,"","TSTREMEDY01"};
       ARNameList formNameList;
       unsigned int i;
       unsigned int ARInt;
       unsigned int ARGetInt;
       ARStatusList status; 

       ARInt = ARInitialization(&control, &status);

----------------------------------------------------------STEP
A--------------------------------------------

       printf("(ARInt %d)\n", ARInt); 

       if ( ARInt >= AR_RETURN_ERROR)
       {
               printStatusList(&status);
               FreeARStatusList(&status, FALSE);
               return 1;
       }

       FreeARStatusList(&status, FALSE); 


       ARGetInt = ARGetListSchema(&control, 0,
                               AR_LIST_SCHEMA_ALL|AR_HIDDEN_INCREMENT,
                               NULL,NULL,
                               &formNameList, &status); 

----------------------------------------------------------STEP
B--------------------------------------------

       if(ARGetInt >= AR_RETURN_ERROR)
               printStatusList(&status);
       else
       {
               for (i=0; i<formNameList.numItems; i++)
                       printf("%s\n",formNameList.nameList[i]);
       }

       FreeARStatusList(&status, FALSE); 
       FreeARNameList(&formNameList, FALSE);
       if(ARTermination(&control,&status) >= AR_RETURN_ERROR)
               printStatusList(&status);
       FreeARStatusList(&status, FALSE); 
}

__20060125_______________________This posting was submitted with HTML in it___ 

_______________________________________________________________________________
UNSUBSCRIBE or access ARSlist Archives at www.arslist.org ARSlist:"Where the 
Answers Are"

_______________________________________________________________________________
UNSUBSCRIBE or access ARSlist Archives at www.arslist.org ARSlist:"Where the 
Answers Are"

Reply via email to