API Reference | developer.brewmp.com API Reference | developer.brewmp.com

Developer

API Reference

IBTBPPSENDER

Brew Release
Brew MP 1.0.2
Description

This interface enables the Sender role of the Basic Printing Profile (BPP). To connect to a Bluetooth Printer, BPP Sender app needs to provide the Bluetooth address of the printer, and the minimum Bluetooth security level to be applied on the connection.The implementation connects to the Direct Printing Service of the printer and is responsible for setting up the status channel when required.
Once a connection is set up, BPP Sender can print objects using the Simple Print Model or the Job Based model. Some print data formats (e.g. XHTML-Print) require that the Printer be able to retrieve objects or parts of objects from the Sender.For example, the Printer can retrieve from the Sender, image(s) that need to be interleaved with text.To service such requests from the Printer,the Sender application can create an instance of the referenced object server using IBTBPPSender_CreateSenderServer().
Usage

Usage example

===== To create an IBTBPPSender object, see instruction in .bid file


   

===== To register signal

// first create the signal; // for example, use ISignalCBFactory_CreateSignal() // then register the signal: IBTBPPSender_OnEventNotify (piBTBPPSender, piSignal);

===== To Register for OBEX Authentication Requests

if (IBTBPPSender_QueryInterface(piBTBPPSender, AEEIID_IOBEXAuthentication, (void**)&piAuth) == AEE_SUCCESS) { IAuthentication_OnRequest(piAuth, pSigAuth); }

===== To Handle Authentication Requests

// When the signal registered via IOBEXAuthentication_OnRequest() is triggered, IOBEXAuthentication_GetRequest(piAuth, &cCharSet, pRealm, realmLen, &nRealmLenReq, &bUserIdRequired, &bFullAccess ); // Prompt user for user ID, if used, and password. // Supply the data entered by user. IOBEXAuthentication_Authenticate(piAuth, pUid, nUidLen, pPswd, pswdLen);

===== To Connect to a printer

IBTBPPSender_Connect(piBTBPPSender, bdAddrOfPrinter, 0, //server channel unknown AEEBT_SEC_SM4_MEDIUM);

===== To Perform Simple Print

IFilePort1* piTempFile = NULL; IFileSystem1_Open (piFileSys, AEECLSID_FilePort1, pathToFile, FS_CAP_RDONLY, (void**)&piTempFile); if (NULL != piTempFile) { IBTBPPSender_SendDocument(piBTBPPSender, "text/plain", // if printer supports this format (IPort1**)&piTempFile, 1, // one port "simple.txt" 0, // no layout information "", // no layout information "", // no description 0); // no Job id for simple print }

===== to cancel Send File operation

IBTBPPSender_CancelSendDocument(piBTBPPSender);

===== To perform Job-based print

// send the CreateJob request to get a Job id from the printer IBTBPPSender_SendSOAPRequest(piBTBPPSender, AEEBTBPP_CREATE_JOB, pSoapRequestBuf, // buffer containing SOAP request soapReqBufLen) // length of buffer // wait for AEEBTBPP_EV_SOAP_RESPONSE to be generated . . . // AEEBTBPP_EV_SOAP_RESPONSE generated; cRequest in event data is AEEBTBPP_CREATE_JOB int soapRespBufLenReq; IBTBPPSender_RetrieveSOAPResponse(piBTBPPSender, AEEBTBPP_CREATE_JOB, pSoapRespBuf, // app allocated buffer to copy the response into soapRespBufLen, // length of the buffer &soapRespBufLenReq); // either parse the response or get the job id from AEEBTBPPSenderEvent // now send file IBTBPPSender_SendDocument(piBTBPPSender, "text/plain", (IPort1**)&piTempFile, 1, "simple.txt" 0, // no layout information "", // no layout information "", // no description jobId); // job id sent by the Printer // monitor the status of the job IBTBPPSender_SendSOAPRequest(piBTBPPSender,AEEBTBPP_GET_EVENT,pSoapRequestBuf,soapReqBufLen); . . . // received AEEBTBPP_EV_SOAP_RESPONSE, cRequest in event data is AEEBTBPP_GET_EVENT // get the status int soapRespBufLenReq; IBTBPPSender_RetrieveSOAPResponse(piBTBPPSender, AEEBTBPP_GET_EVENT, pSoapRespBuf, // app allocated buffer to copy the response into soapRespBufLen, // length of the buffer &soapRespBufLenReq); . . . // Printer status changed. received AEEBTBPP_EV_SOAP_RESPONSE, cRequest in event data is AEEBTBPP_GET_EVENT // get the status int soapRespBufLenReq; IBTBPPSender_RetrieveSOAPResponse(piBTBPPSender, AEEBTBPP_GET_EVENT, pSoapRespBuf, // app allocated buffer to copy the response into soapRespBufLen, // length of the buffer &soapRespBufLenReq); // Job complete // cancel Monitoring print status IBTBPPSender_CancelSOAPRequest()

===== To perform printing with referenced content

IBTBPPRefObjectServer *pisrv; IBTBPPSender_CreateSenderServer(piBTBPPSender, AEECLSID_BTBPPRefObjectServer, &pisrv) // Enable the server. See interface header file of server // send file IBTBPPSender_SendDocument(piBTBPPSender, "application/vnd.pwg-xhtml-print+xml:1.0", &piTempFile, 1, "", 0 "", "", 0); // handle requests from the printer on the server object

===== To retrieve and handle events when Event signal is triggered:

while (IBTBPPSender_GetEvent (piBTBPPSender, &eventData) != AEE_ENOMORE) { switch (eventData.cEvent) { case AEEBTBPP_EV_CONNECTED: break; case AEEBTBPP_EV_CONN_FAILED: break; . . . default: break; } } ISignalCtl_Enable (piSignalCtl); // re-enable signal

===== To Disconnect from a printer

IBTBPPSender_Disconnect(piBTBPPSender);