/* * This is MergeCOM3 toolkit sample code that reads an image from the * Storage SCU application MERGE_STORE_SCU, and writes it to a Part 10 * media file, image.dcm, as MERGE_STORE_SCP. */ #include "mergecom.h" #include "mc3media.h" #include "diction.h" /* Media function callback and implementation for MC_Write_File. */ typedef struct { FILE* fp; } CBinfo; MC_STATUS FileObjToMedia( char* A_filename, void* A_userInfo, int A_dataSize, void* A_dataBuffer, int A_isFirst, int A_isLast ) { CBinfo* cbInfo = (CBinfo*)A_userInfo; if( A_isFirst ) cbInfo->fp = fopen( A_filename, "wb" ); fwrite( A_dataBuffer, 1, A_dataSize, cbInfo->fp ); if( A_isLast ) fclose( cbInfo->fp ); return MC_NORMAL_COMPLETION; } /* FileObjToMedia() */ int main(int argc, char** argv) { int applID, assocID, msgID, rspMsgID, dummyID; AssocInfo assocInfo; char* serviceName; MC_COMMAND command; char* fileName = "image.dcm"; TRANSFER_SYNTAX xferSyntax; char SOPClassUID[65], SOPInstanceUID[65], xferSyntaxUID[65]; char version[] = {0x00,0x01}; CBinfo cbInfo; /* Initialize the library */ MC_Library_Initialization( NULL, NULL, NULL ); /* Create the local application */ MC_Register_Application( &applID, "MERGE_STORE_SCP" ); /* Wait for the association request from the image sender */ MC_Wait_For_Association( "Storage_SCP_Service_List", -1, &applID, &assocID); /* Accept the association if MERGE_STORE_SCU is calling */ MC_Get_Association_Info( assocID, &assocInfo ); if( strcmp( assocInfo.RemoteApplicationTitle, "MERGE_STORE_SCU" ) != 0 ) { printf( "Unrecognized sender: %s\n", assocInfo.RemoteApplicationTitle ); MC_Reject_Association( assocID, PERMANENT_CALLING_AE_TITLE_NOT_RECOGNIZED ); return( -1 ); } MC_Accept_Association( assocID ); /* Read the C-STORE request */ MC_Read_Message( assocID, -1, &msgID, &serviceName, &command); /* Get the Transfer Syntax */ MC_Get_Message_Transfer_Syntax( msgID, &xferSyntax ); MC_Get_Transfer_Syntax_From_Enum( xferSyntax, xferSyntaxUID, 65 ); /* Convert the message to a media file */ MC_Message_To_File( msgID, fileName ); /* Set the file meta information */ MC_Set_Value_From_String( msgID, MC_ATT_TRANSFER_SYNTAX_UID, xferSyntaxUID ); MC_Set_Value_From_Buffer( msgID, MC_ATT_FILE_META_INFORMATION_VERSION, version, 2 ); MC_Get_Value_To_String( msgID, MC_ATT_SOP_CLASS_UID, 65, SOPClassUID ); MC_Set_Value_From_String( msgID, MC_ATT_MEDIA_STORAGE_SOP_CLASS_UID, SOPClassUID ); MC_Get_Value_To_String( msgID, MC_ATT_SOP_INSTANCE_UID, 65, SOPInstanceUID ); MC_Set_Value_From_String( msgID, MC_ATT_MEDIA_STORAGE_SOP_INSTANCE_UID, SOPInstanceUID ); MC_Set_Value_From_String( msgID, MC_ATT_SOURCE_APPLICATION_ENTITY_TITLE, "MERGE_STORE_SCP" ); /* Write the media file */ MC_Write_File( msgID, 0, &cbInfo, FileObjToMedia ); /* Send the C-STORE response */ MC_Open_Message (&rspMsgID, serviceName, C_STORE_RSP ); MC_Send_Response_Message( assocID, C_STORE_SUCCESS, rspMsgID ); /* Read for release request */ MC_Read_Message( assocID, 2, &dummyID, &serviceName, &command); /* Cleanup */ MC_Free_Message( &msgID ); MC_Free_Message( &rspMsgID ); MC_Release_Application( &applID ); /* Release the library */ MC_Library_Release(); return( 0 ); }