/*******************************************************************************
 *  Copyright 2017-2018 Centre for Development of Advanced Computing(C-DAC), Pune
 *  
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *  
 *   http://www.apache.org/licenses/LICENSE-2.0
 *  
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *******************************************************************************/
package cdac.medinfo.sdk.dcm30_04.services.cservices.testcases.scu;

import java.io.IOException;
import java.net.InetSocketAddress;


import cdac.medinfo.sdk.dcm30_04.enums.EnumLoggingLevel;

import cdac.medinfo.sdk.dcm30_04.services.cecho.commons.CEchoRSP;
import cdac.medinfo.sdk.dcm30_04.services.cecho.scu.CEchoSCU;
import cdac.medinfo.sdk.dcm30_04.utils.DicomConfig;

/**
 * This class tests a Stand Alone CEcho SCU.
 * "Stand Alone" means that the User is required to write a minimal set of code to actually send a 
 * CEcho Request. Once the required parameters are given to the CEchoSCU object it is 
 * capable of making a connection to the SCP, sending the CEcho Request and receiving the 
 * DIMSE Response for the same. If User wants to handle the request sending scenarios by his/her code 
 * then please refer to sample code "CEcho_SCU.java". 
 */
public class CEcho_SCU_Standalone 
{
	public static void main(String args[])
	{
		try
		{
			DicomConfig objDicomConfig = DicomConfig.createInstance();

			//enable logging,specify the path of the directory where log files are created.
			//User can specify any directory in place of 'c:\DCM_Logs'.
			//If no directory is defined by user to create logs then it is created in User Temp DIR.
			objDicomConfig.enableLogging(EnumLoggingLevel.INFO, "C:\\DCM_Logs");

			/*
			 * Creates object of CEcho_SCU_Standalone and start CEcho operation.
			 */
			CEcho_SCU_Standalone objCEchoSCUTest = new CEcho_SCU_Standalone();
			objCEchoSCUTest.doCEcho();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}

	/**
	 * Creates CEcho SCU by specifying address and port of the destination CEcho SCP.
	 * Sends the available dataset to SCP.
	 * @throws IOException Signals IOException if IO operation fails.
	 */
	public void doCEcho() throws IOException
	{

		int iPort = 9000;
		InetSocketAddress addr = new InetSocketAddress("192.168.8.94",iPort);

		/* 
		 * Creates SCU with specified destination .
		 */
		CEchoSCU objCEchoSCU = new CEchoSCU(addr);

		/*
		 * sends the C-Echo request.
		 */
		objCEchoSCU.verify("SDK","SDK");
		System.out.println("C-Echo Operation is performed. Response Collection Size "+objCEchoSCU.getDIMSEResponse().size());
		if(objCEchoSCU.getDIMSEResponse().size() >0)
		{
			CEchoRSP objCEchoRSP = new CEchoRSP(objCEchoSCU.getDIMSEResponse().get(0));
			System.out.println("C-Echo Response Status :" + objCEchoRSP.getStatus());
		}
	}
}
