![]() |
![]() |
![]() |
This document describes PFS_ExecuteCommand(), the QNX PFS driver access function provided with the QNX Aviage Multimedia Interface for PlaysForSure. This function provides client application developers:
Support user-specified MTP commands to a PFS device
#include <pfs_userx.h> MTP_RESULT PFS_ExecuteCommand( int fd, OPCODE opCode, int nSendParams, MTP_UINT32 *pSendParams, int handleParamNumber, int nSendDataBytes, MTP_UINT8 *pSendDataBytes, int *pnRecvParams, MTP_UINT32 *pRecvParams, int *pnRecvDataBytes, MTP_UINT8 *pRecvDataBytes, RESPONSECODE *pResponseCode );
pfs_userx.h
The function PFS_ExecuteCommand() allows applications to execute atomic MTP on PFS devices. An atomic MTP command is executed as a single transaction, which consists of the following:
PFS_ExecuteCommand() is not intended for reading of media content (i.e. execute OPCODE_GETOBJECT), and its data transfers are expected to be less than 64 kilobytes. To read media content, use the POSIX read() function.
![]() |
|
None delivered.
This function validates that at least one of the data buffers (read or write) is set to NULL. It executes to completion.
PFS_ExecuteCommand() relays to the client application any errors it receives from the PFS driver. The function does some parameter validation, and only explicitly returns the MTP_ERROR_INVALIDARG error code; all other error codes are generated by either the PFS driver or the PFS device itself.
The enumerated values listed below define the most common errors returned or relayed by PFS_ExecuteCommand(). For a complete list, see the MTP specification.
QNX Neutrino
The following examples show how you can use PFS_ExecuteCommand() to execute:
#include <errno.h> #include <string.h> #include <stdio.h> #include <sys/iomsg.h> #include <fcntl.h> #include "pfs_userx.h" #ifndef MTP_RESULT_OK #define MTP_RESULT_OK 0 #endif int main(int argc, char *argv[]) { char *music = "/fs/pfs0/Music"; int i, n, fd; MTP_RESULT hr; MTP_UINT32 send_params[5]; MTP_UINT32 recv_params[5]; MTP_UINT32 nRecvParams = 1; MTP_UINT32 nRecvDataBytes = 0; MTP_UINT8 *pSendDataBytes; MTP_UINT8 *pRecvDataBytes; RESPONSECODE ResponseCode = 0;
// example 1: no data transfer, get number of objects under Music folder fd = open(music, O_RDONLY); if (fd > 0) { send_params[0] = 0xffffffff; // StorageID send_params[1] = 0; // ObjectFormat send_params[2] = 0; // ObjectHandle (pararameter 3 to be overwritten with handle) nRecvParams = 1; hr = PFS_ExecuteCommand(fd, 0x1006, // OPCODE_GETNUMOBJECTS 3, // number of 32- bit send parameters send_params, // address of array of 32-bit send parameters 3, // operation parameter to contain the object handle 0, // number of data bytes to send in transfer phase NULL, // address of buffer with data bytes to send &nRecvParams, // input: maximum number of receive parameters expected, // output: actual received recv_params, // address of array to hold response parameters NULL, // input: max data bytes to receive, output: actual received NULL, // address of buffer to receive data &ResponseCode); // the response code received printf("\nexample 1: hr=%d, RC=%04x, num_recv_parms=%d, num_objects=%d\n", hr, ResponseCode, nRecvParams, recv_params[0]); close(fd); }
// example 2: receive data, get object handles from Music directory fd = open(music, O_RDONLY); pRecvDataBytes = (MTP_UINT8 *) alloca(n = sizeof(MTP_UINT32) * 1000); if (pRecvDataBytes != NULL && fd > 0) { send_params[0] = 0xffffffff; // StorageID send_params[1] = 0; // ObjectFormat send_params[2] = 0; // ObjectHandle (pararameter 3 to be overwritten with handle) nRecvParams = 0; nRecvDataBytes = n; hr = PFS_ExecuteCommand(fd, 0x1007, // OPCODE_GETOBJECTHANDLES 3, // number of 32-bit send parameters send_params, // address of array of 32-bit send parameters 3, // operation parameter to contain the object handle 0, // number of data bytes to send in transfer phase NULL, // address of buffer with data bytes to send NULL, // input: maximum number of receive parameters expected, // output: actual received NULL, // address of array to hold response parameters &nRecvDataBytes, // input: maximum data bytes to receive, output: // actual received pRecvDataBytes, // address of buffer to receive data &ResponseCode); // the response code received printf("\nexample 2: hr=%d, RC=%04x, num_recv_bytes=%d\n", hr, ResponseCode, nRecvDataBytes); n = (nRecvDataBytes - sizeof(MTP_UINT32)) / sizeof(MTP_UINT32); if (hr == MTP_RESULT_OK && n != 0 && n == pRecvDataBytes[0]) { for (i = 1; i <= n; ++i) printf("\n %3d %#10x", i, ((MTP_UINT32 *) pRecvDataBytes)[i]); } printf("\n"); close(fd); }
// example 3: send data, update the "Friendly Name" device property fd = open(music, O_RDONLY); n = 5; // write five UNICODE16 characters pSendDataBytes = (MTP_UINT8 *) alloca(2*(n+1)); if (pSendDataBytes != NULL && fd > 0) { send_params[0] = 0xD402; // DEVICEPROPCODE_DEVICEFRIENDLYNAME pSendDataBytes[0] = n; // "NAME" with null has total of 5 characters pSendDataBytes[1] = 'N'; // 16-bit characters pSendDataBytes[2] = 0; // - high bits are zero pSendDataBytes[3] = 'A'; pSendDataBytes[4] = 0; pSendDataBytes[5] = 'M'; pSendDataBytes[6] = 0; pSendDataBytes[7] = 'E'; pSendDataBytes[8] = 0; pSendDataBytes[9] = 0; // 16-bit null pSendDataBytes[10] = 0; hr = PFS_ExecuteCommand(fd, 0x1016, // OPCODE_SETDEVICEPROPVALUE 1, // number of 32-bit send parameters send_params, // address of array of 32-bit send parameters 0, // operation parameter to contain the object handle 1+2*n, // number of data bytes to send in transfer phase pSendDataBytes, // address of buffer with data bytes to send NULL, // input: maximum number of receive parameters expected, // output: actual received NULL, // address of array to hold response parameters NULL, // input: maximum data bytes to receive, output: actual received NULL, // address of buffer to receive data &ResponseCode); // the response code received printf("\nexample 3: hr=%d, RC=%04x\n", hr, ResponseCode); close(fd); } return 0; }
![]() |
![]() |
![]() |