/* * This is MergeCOM3 toolkit sample code that reads an image from a DICOM * Part 10 media file, image.dcm, and sends it to the Storage SCP application * MERGE_STORE_SCP as MERGE_STORE_SCU */ #include #include #include /* MC_Open_File media function callback data and implementation */ typedef struct { FILE* fp; char buffer[64*1024]; } CBinfo; MC_STATUS MediaToFileObj( char* A_filename, void* A_userInfo, int* A_dataSize, void** A_dataBuffer, int A_isFirst, int* A_isLast ) { CBinfo* cbInfo = (CBinfo*)A_userInfo; size_t bytes_read; if( A_isFirst ) cbInfo->fp = fopen( A_filename, "rb" ); bytes_read = fread( cbInfo->buffer, 1, sizeof(cbInfo->buffer),cbInfo->fp ); if( feof( cbInfo->fp ) ) { *A_isLast = 1; fclose( cbInfo->fp ); cbInfo->fp = NULL; } else *A_isLast = 0; *A_dataBuffer = cbInfo->buffer; *A_dataSize = (int)bytes_read; return MC_NORMAL_COMPLETION; } /* MediaToFileObj() */ int main(int argc, char** argv) { char* fileName = "image.dcm"; int applID, assocID, msgID, rspmsgID; char xferSyntaxUID[65], SOPClassUID[65], SOPInstanceUID[65], serviceName[48]; TRANSFER_SYNTAX xferSyntax; char* rspService; MC_COMMAND rspCommand; unsigned int dcmStatus; CBinfo cbInfo; /* Initialize the library */ MC_Library_Initialization( NULL, NULL, NULL ); /* Create the local application */ MC_Register_Application( &applID, "MERGE_STORE_SCU"); /* Create and read the media file */ MC_Create_Empty_File( &msgID, fileName ); MC_Open_File( applID, msgID, &cbInfo, MediaToFileObj ); /* Get the Transfer Syntax and the other UID attributes */ MC_Get_Value_To_String( msgID, MC_ATT_TRANSFER_SYNTAX_UID, 65, xferSyntaxUID ); MC_Get_Enum_From_Transfer_Syntax( xferSyntaxUID, &xferSyntax ); MC_Get_Value_To_String( msgID, MC_ATT_SOP_CLASS_UID, 65, SOPClassUID ); MC_Get_Value_To_String( msgID, MC_ATT_SOP_INSTANCE_UID, 65, SOPInstanceUID); /* Convert the file to a message and set the Transfer Syntax */ MC_File_To_Message( msgID ); MC_Set_Message_Transfer_Syntax( msgID, xferSyntax ); /* Set the required Affected SOP Instance UID attribute */ MC_Set_Value_From_String( msgID, MC_ATT_AFFECTED_SOP_INSTANCE_UID, SOPInstanceUID ); /* Create the association */ MC_Open_Association( applID, &assocID, "MERGE_STORE_SCP", NULL, NULL, NULL ); /* Send the C-STORE request */ MC_Get_MergeCOM_Service( SOPClassUID, serviceName, 48 ); MC_Set_Service_Command( msgID, serviceName, C_STORE_RQ ); MC_Send_Request_Message( assocID, msgID ); /* Wait for and read the response */ MC_Read_Message( assocID, -1, &rspmsgID, &rspService, &rspCommand); /* Check for success or failure */ MC_Get_Value_To_UInt( rspmsgID, MC_ATT_STATUS, &dcmStatus ); if( dcmStatus != C_STORE_SUCCESS ) printf( "Failed to send file, status %x\n", dcmStatus ); else printf( "Send succeeded\n" ); /* Close the association */ MC_Close_Association( &assocID ); /* Cleanup */ MC_Free_Message( &msgID ); MC_Free_Message( &rspmsgID ); MC_Release_Application( &applID ); /* Release the library */ MC_Library_Release(); return( 0 ); }