top of page
  • Writer's pictureadmin

First ITK Program for Login


Following the Server Side Customization topics, let us move to create our first basic program to login to Teamcenter using ITK utility.


Please go through the below pre-requisite blogs,

Teamcenter Server-side Customization (ITK)

ITK Customizations - Part2


All standalone ITK program must login to Teamcenter to connect to the Teamcenter database layer. Without establishing the login session with Teamcenter, we cannot read or modify any data in Teamcenter.


Program Main Function

ITK_user_main

As like any C/C++ program, Teamcenter standalone ITK programs requires main function ITK_user_main as it is responsible for the starting the execution and termination of the program. ITK_user_main is a special function that always starts executing code.


Login Function

Teamcenter has 2 login function, based on the use case/scenario choose the login function.

int ITK_auto_login()

ITK_auto_login() function is used to login to Teamcenter based on user id password and group details.

ITK_auto_login() function can be used in different ways,

  • If login details are provided in command line, ITK_auto_login() attempts to login based on the data provided in command line.

Eg: your_program -u=<user_id> -p=<password> -g=<group>
  • If the site preference TC_auto_login is set as TRUE, then user does not need to enter in a user id, password or group in the command line. The ITK_auto_login() function attempts to login based on operating system user name assuming the operating system username & password are same as Teamcenter user id & password.

TC_auto_login = TRUE

However, if the user wants to use a login name other than their operating system name, then user need to use the command line format with username, password and group parameters.


int ITK_init_module()

ITK_init_module() function attempts to login with the passed-in information. The function needs user id, password and group parameters.

int ITK_init_module (
            const char * user_id,
            const char * user_password,
            const char * user_group)

Both the login function returns integer as return type. Both function returns 0, if it has successfully logged in and returns error code, if there are any login issues.


Note: ITK_auto_login & ITK_init_module works in same way. ITK_init_module supports hardcoded values for user id, password and group where as auto login function doesn't support.  

Reading command line arguments

char* ITK_ask_cli_argument
char* ITK_ask_cli_argument(const char * argument_name)

ITK_ask_cli_argument() is used to read the command line arguments. The function takes argument for which value has to be returned.


Eg: If the program is called with command line argument -i=on, the use ITK_ask_cli_argument( "-i=" ) to retrieve the value "on".

Sample Code Snippet:


#include<tcinit/tcinit.h>

int ITK_user_main(int argc, char* argv[])
{
	int iFail = ITK_ok;

	char *users_id, *users_password, *users_group;
	
	users_id = ITK_ask_cli_argument("-u=");
	users_password = ITK_ask_cli_argument("-p=");
	users_group = ITK_ask_cli_argument("-g=");
	iFail = ITK_init_module(users_id, users_password, users_group);

	printf("Login Status : %d", iFail);
	TC_write_syslog("Login Status : %d", iFail);

	return iFail;
}

#include<tcinit/tcinit.h> => Include file for ITK_init_module function


int ITK_user_main(int argc, char* argv[]) => Main function, starting function for the utility

{

int iFail = ITK_ok; =>Variable declaration for return type; ITK_ok


char *users_id, *users_password, *users_group; =>Variable declaration to read command line arguments

users_id = ITK_ask_cli_argument("-u="); => Reading command line arguments

users_password = ITK_ask_cli_argument("-p=");

users_group = ITK_ask_cli_argument("-g=");

iFail = ITK_init_module(users_id, users_password, users_group); => Logging to Teamcenter


printf("Login Status : %d", iFail); => To print on command prompt

TC_write_syslog("Login Status : %d", iFail); => To write on Teamcenter syslog


return iFail;=> Main function return statement

}


bottom of page