cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How do you programmatically distinguish between Checkout and Borrow date time?

How do you programmatically distinguish between Checkout and Borrow date time?

Summary

How do you programmatically distinguish between Checkout and Borrow date time?

Question

In our product, we're creating a report at the client side to show the list of nodes that use floating licenses. In the table of the report, we have a Checkout column and a Borrow column. As far as we understand, someone can checkout and at a later time to borrow, so the two columns can be different. How can they get the two values using LM_USERS struct and lc_userlist method? It seems to only have one time value, which we assume is the checkout time? How can we get the borrow time?

If we use lc_userlist like:

LM_USERS *users = lc_userlist(job, (LM_CHAR_PTR)"XYZ");

And then iterate the users like:

while (users)
{
if (users->name[0] == 0)
{
// Special record.
numberOfAvailableLicenses = users->nlic;
dateTime = UnixEpoch.AddSeconds(static_cast<double>(users->time));

users = users->next;

continue;
}

// How do you find the borrow time here for each user (if they have borrowed a license?)
DateTime checkoutDateTime = UnixEpoch.AddSeconds(static_cast<double>(users->time));

users = users->next;
}

What example code illustrates how to do this?

Answer

You can use users->linger (a structure member of LM_USERS) to distinguish between Checkout and Borrow. Using this structure member, you can find out the borrow time for each user.
LM_USERS *users = lc_userlist(job, feature_name);
if (users->next)
{
        while (users->next)
        {    
            users = users->next;
            printf("Linger is : %d\n", users->linger);
        }
}

Additional Information

To find out the checkout time:
chk_time = localtime(&users->time);
printf("checkout time for feature %s is %2d:%02d:%02d\n",
                         feature , chk_time->tm_hour, chk_time->tm_min,
                         chk_time->tm_sec);


To find out the borrow checkout time:
chk_time = localtime(&users->time);
printf("borrow time for feature %s is %2d:%02d:%02d\n",
                         feature , chk_time->tm_hour, chk_time->tm_min,
                         chk_time->tm_sec);


To find Expiration time for borrow feature:
int tNow = ((difftime( (users->linger + users->time), time(NULL) ))/3600);
printf("Feature %s Expire after %d hours\n",feature, tNow);


The below code combines the above to find out checkout time,borrow checkout time and expiration time.
while (users->next)
{    
      users = users->next;
      chk_time = localtime(&users->time);
      if(users->linger)
      {
         int tNow = ((difftime( (users->linger + users->time), time(NULL) ))/3600);
         printf("borrow time for feature %s is %2d:%02d:%02d\n",
                         feature , chk_time->tm_hour, chk_time->tm_min,
                         chk_time->tm_sec);
         printf("Feature %s Expire after %d hours\n",feature, tNow);
       }
       else
       {
          printf("checkout time for feature %s is %2d:%02d:%02d\n",
                         feature , chk_time->tm_hour, chk_time->tm_min,
                         chk_time->tm_sec);
       }
}
Labels (1)
Was this article helpful? Yes No
No ratings
Version history
Last update:
‎Nov 15, 2018 05:19 PM
Updated by: