• No se han encontrado resultados

FaSinPat y el universo de las recuperadas Un estado de la cuestión

In document Ocupar, resistir y producir (página 55-61)

CAPÍTULO 3: Trabajadoras y trabajadores organizando la producción.

3.2. FaSinPat y el universo de las recuperadas Un estado de la cuestión

Parameters

Returns

VESP_SUCCESS Request was successful VESP_MSG_NOT_FOUND Message does not exist

VESP_BAD_PARAMETER Bad parameter passed to function

request A handle of type Object which uniquely identifies the request. Created with ORB_create_request or Session_create_request.

ev An environment variable filled when an error is detected.

return_result The return result of the original request. This should match the data type of the responding method as declared in its IDL specification. (See the section that describes the IDL declarations.)

VESP_SUCCESS Request was successful

Request_send_deferred_response

Issue 1.0 June 2002 157

64 data associated with a deferred request in TEST_DeferRequest.

65 */ 66 struct saved_for_callback { 67 Request oRequest; 68 Session oSession; 69 void *pxUserData; 70 }; . . . 78 static ORBStatus

79 defer_request_callback (Identifier, ORBStatus, Environment *, long, 80 Session, SeqCouple *);

. . .

685 /*********************************************************************/

686 /* This method demonstrates deferring the response to a client while the

687 server asynchronously makes a request to another server.

688 The client invoking this request expects output data. We will be making an 689 Alarm.GetStatus request and passing a copy of the returned sequence of 690 couples back to the client.

691 This method returns void instead of ORBStatus. For an example that returns 692 ORBStatus, see TEST_Assign.

693 */

694 /*********************************************************************/ 695 /*ARGSUSED */

696 void

697 TEST_DeferRequest (Object tObj, Environment * ptEnv, SeqCouple * ptOutputData)

698 {

699 Environment tMyEnv; 700 ORBStatus mMyStatus;

701 struct saved_for_callback *ptSaveInfo;

702 /* This has to be static for the callback to work. It will only be

703 filled in and meaningful in the callback to this function, so it 704 doesn't matter that it will be overwritten by subsequent function 705 calls. */

706 static SeqCouple tSeqCouple;

707 /* Initialize the structure to NULL - the information in this struct

708 will be sent to the server that you are making a request of, so 709 you're better off knowing what you are sending */

710 tSeqCouple._length = 0; 711 tSeqCouple._maximum = 0; 712 tSeqCouple._buffer = NULL;

713 /* Allocate space for saving the request, the session, and the output

714 data to be used by the callback function to send the deferred 715 response. */

716 ptSaveInfo = vesp_calloc (1, sizeof (struct saved_for_callback));

717 /* Save the request - we use it in the callback to retrieve the

718 client environment. */

719 ptSaveInfo->oRequest = Object_duplicate (ptEnv->request, &tMyEnv);

720 if (tMyEnv._major != NO_EXCEPTION) {

721 vesp_log_info (VESP_CAT_ALL, "Problem", "Object_duplicate"); 722 log_unparsable ("Error: %s", tMyEnv.vesp_error_description);

723 vesp_set_exception (ptEnv, tMyEnv._major, tMyEnv._minor, 724 tMyEnv.vesp_error_description);

725 vesp_free (ptSaveInfo); 726 return;

727 }

728 /* Save the session - we use it in the callback to check that the

729 client still exists. */

730 ptSaveInfo->oSession = Object_duplicate (ptEnv->session, &tMyEnv); 731 if (tMyEnv._major != NO_EXCEPTION) {

732 vesp_log_info (VESP_CAT_ALL, "Problem", "Object_duplicate"); 733 log_unparsable ("Error: %s", tMyEnv.vesp_error_description);

734 vesp_set_exception (ptEnv, tMyEnv._major, tMyEnv._minor, 735 tMyEnv.vesp_error_description);

736 Object_release (ptSaveInfo->oRequest, &tMyEnv); 737 if (tMyEnv._major != NO_EXCEPTION) {

738 vesp_log_info (VESP_CAT_ALL, "Problem", "Object_release"); 739 log_unparsable ("Error: %s", tMyEnv.vesp_error_description);

Request_send_deferred_response

Issue 1.0 June 2002 159

748 mMyStatus = Vesp_Request ("Alarm.GetStatus", defer_request_callback, 749 (unsigned long) ptSaveInfo, oMySession_gbl,

750 &tSeqCouple);

751 if (mMyStatus != VESP_SUCCESS) {

752 /* Return an error to the client immediately if there's a problem 753 with the request. */

754 vesp_log_info (VESP_CAT_ALL, "Problem", "Vesp_Request"); 755 log_unparsable ("Status: %s", vesp_find_error (mMyStatus));

756 vesp_set_exception (ptEnv, SYSTEM_EXCEPTION, VESP_FAILURE, 757 "defer_request method request failed");

758 vesp_free (ptSaveInfo); 759 return;

760 }

761 /* Now defer the request - after this is successfully called, no

762 response will be sent to the client until we send one. Normally, a 763 response would be sent to the client when this function returns. */ 764 mMyStatus = Request_defer (ptEnv->request, &tMyEnv);

765 if (tMyEnv._major != NO_EXCEPTION || mMyStatus != VESP_SUCCESS) { 766 /* We were unable to defer the request for some reason. */

767 vesp_log_info (VESP_CAT_ALL, "Problem", "Request_defer");

768 log_unparsable ("Error: %s, Status: %s", tMyEnv.vesp_error_description, 769 vesp_find_error (mMyStatus));

770 /* Clean up of our duplicated objects will happen in the callback. We 771 could release them here if we wanted to, then in the callback we'd 772 have to check that the saved objects were non-null.

773 Since the Request_defer failed, the response will be sent to the 774 client when this function returns. However, the callback will still 775 be invoked when the request we made in this function returns a 776 response.

777 We'll end up with a situation where there will be no

778 outstanding request associated with our stored request object. We 779 use Request_get_ev to detect this situation when it retrieves the 780 original request environment. */

781 vesp_set_exception (ptEnv, tMyEnv._major, tMyEnv._minor, 782 tMyEnv.vesp_error_description);

783 }

784 /* If we get to this point, we should be good to go - the session, the 785 request, and the output data pointer are saved, and the original

786 request has been deferred. */ 787 }

788 /*********************************************************************/

789 /* Send the results of the deferred request to the client. In this case,

790 we pass along the result returned by the toolkit, but that's not 791 necessary - you can send the client any status you want to. 792 */

793 /*********************************************************************/ 794 /*ARGSUSED */

795 static ORBStatus

796 defer_request_callback (Identifier tInterface, ORBStatus mStatus, 797 Environment * ptEnv, long lUserData,

798 Session oSession, SeqCouple * ptOutputData) 799 {

800 Environment tMyEnv;

801 struct saved_for_callback *ptSavedInfo;

802 ORBStatus mMyStatus;

803 int i;

804 any tReturnToClient; 805 Environment *ptRequestEnv; 806 SeqCouple *ptRequestData;

807 /* Make the user data look like a pointer again. */ 808 ptSavedInfo = (struct saved_for_callback *) lUserData;

809 /* Get the client environment first - this is mostly to check that our 810 request is still valid. If you're working with a toolkit older than 811 3.5.9 you have to add the following line before making the

812 Request_get_ev function call.

Request_send_deferred_response

Issue 1.0 June 2002 161

820 log_unparsable ("Error: %s, Status: %s", tMyEnv.vesp_error_description, 821 vesp_find_error (mMyStatus));

822 Object_release (ptSavedInfo->oRequest, &tMyEnv); 823 if (tMyEnv._major != NO_EXCEPTION) {

824 vesp_log_info (VESP_CAT_ALL, "Problem", "Object_release"); 825 log_unparsable ("Error: %s", tMyEnv.vesp_error_description);

826 }

827 Object_release (ptSavedInfo->oSession, &tMyEnv); 828 if (tMyEnv._major != NO_EXCEPTION) {

829 vesp_log_info (VESP_CAT_ALL, "Problem", "Object_release"); 830 log_unparsable ("Error: %s", tMyEnv.vesp_error_description);

831 }

832 vesp_free (ptSavedInfo);

833 /* No request, can't send anything to client. Any return from inside 834 this function goes to the toolkit, not the client. */

835 return VESP_SUCCESS;

836 }

837 /* Check that the client session still exists before sending a response.

838 Bad things will happen if you try to send a response using a client 839 session that's already been cleaned up by the toolkit. */

840 mMyStatus = Session_exist (ptSavedInfo->oSession, &tMyEnv); 841 if (tMyEnv._major != NO_EXCEPTION || mMyStatus != VESP_SUCCESS) { 842 vesp_log_info (VESP_CAT_ALL, "Problem", "Session_exist");

843 log_unparsable ("Error: %s, Status: %s", tMyEnv.vesp_error_description, 844 vesp_find_error (mMyStatus));

845 Object_release (ptSavedInfo->oRequest, &tMyEnv); 846 if (tMyEnv._major != NO_EXCEPTION) {

847 vesp_log_info (VESP_CAT_ALL, "Problem", "Object_release"); 848 log_unparsable ("Error: %s", tMyEnv.vesp_error_description);

849 }

850 Object_release (ptSavedInfo->oSession, &tMyEnv); 851 if (tMyEnv._major != NO_EXCEPTION) {

852 vesp_log_info (VESP_CAT_ALL, "Problem", "Object_release"); 853 log_unparsable ("Error: %s", tMyEnv.vesp_error_description);

854 }

855 vesp_free (ptSavedInfo); 856 return VESP_SUCCESS;

857 }

858 /* OK - so we have a valid environment and a valid client session let's

859 send the response. Here's where the result of the request comes into 860 play - if the environment has an exception set, we can't use any of

861 the output values, but our user data is unmodified.

862 Notice that we're sending a response to a method that returns

863 something other than ORBStatus, so the values that we're assigning to 864 tReturnToClient._type and tReturnToClient._value change accordingly.

865 */

866 tReturnToClient._type = "void"; 867 tReturnToClient._value = NULL;

868 /* The important thing is that the toolkit checks the type you are trying

869 to return against the return type that is expected in the original 870 request, so they have to match. */

871 if (NO_EXCEPTION == ptEnv->_major) {

872 /* Fill in the output data using the pointer we saved from earlier. */ 873 ptRequestData = (SeqCouple *) ptSavedInfo->pxUserData;

874 for (i = 0; i < ptOutputData->_length; i++) { 875 char *pcName = ptOutputData->_buffer[i].name; 876 char *pcValue = ptOutputData->_buffer[i].value;

877 vesp_couple_seq_add_couple_values (ptRequestData, pcName, pcValue);

878 }

879 } else {

880 vesp_set_exception (ptRequestEnv, ptEnv->_major, ptEnv->_minor, 881 ptEnv->vesp_error_description);

882 }

883 mMyStatus = Request_send_deferred_response (ptSavedInfo->oRequest, 884 &tMyEnv,

885 &tReturnToClient);

886 /* There's not much we can do if this fails. */

Server_set_client_terminate_routine

Issue 1.0 June 2002 163

895 if (tMyEnv._major != NO_EXCEPTION) {

896 vesp_log_info (VESP_CAT_ALL, "Problem", "Object_release"); 897 log_unparsable ("Error: %s", tMyEnv.vesp_error_description);

898 }

899 Object_release (ptSavedInfo->oSession, &tMyEnv); 900 if (tMyEnv._major != NO_EXCEPTION) {

901 vesp_log_info (VESP_CAT_ALL, "Problem", "Object_release"); 902 log_unparsable ("Error: %s", tMyEnv.vesp_error_description);

903 }

904 vesp_free (ptSavedInfo);

905 /* Thank you, drive through. */ 906 return VESP_SUCCESS;

907 }

Server_set_client_terminate_routine

Syntax

void Server_set_client_terminate_routine( routine ) ORBStatus (*routine) ( Object object );

Description Set the routine to be called when client fails.

In document Ocupar, resistir y producir (página 55-61)