Example #1
0
//--------------------------------------------------------------------------------------------------
void allParametersRespond
(
    ServerCmdRef_t _cmdRef,
    uint32_t b,
    size_t outputNumElements,
    uint32_t* outputPtr,
    char* response,
    char* more
)
{
    LE_ASSERT(_cmdRef != NULL);

    // Get the message related data
    le_msg_MessageRef_t _msgRef = (le_msg_MessageRef_t)_cmdRef;
    _Message_t* _msgPtr = le_msg_GetPayloadPtr(_msgRef);
    __attribute__((unused)) uint8_t* _msgBufPtr = _msgPtr->buffer;

    // Ensure the passed in msgRef is for the correct message
    LE_ASSERT(_msgPtr->id == _MSGID_allParameters);

    // Ensure that this Respond function has not already been called
    LE_FATAL_IF( !le_msg_NeedsResponse(_msgRef), "Response has already been sent");


    // Pack any "out" parameters
    _msgBufPtr = PackData( _msgBufPtr, &b, sizeof(uint32_t) );
    _msgBufPtr = PackData( _msgBufPtr, &outputNumElements, sizeof(size_t) );
    _msgBufPtr = PackData( _msgBufPtr, outputPtr, outputNumElements*sizeof(uint32_t) );
    _msgBufPtr = PackString( _msgBufPtr, response );
    _msgBufPtr = PackString( _msgBufPtr, more );

    // Return the response
    LE_DEBUG("Sending response to client session %p", le_msg_GetSession(_msgRef));
    le_msg_Respond(_msgRef);
}
Example #2
0
void Client::InternalSendMessage(const google::protobuf::Message& _message) {
  if (state_ != CONNECTED) {
    LOG(ERROR) << "Client is not connected. Dropping message" << std::endl;

    return;
  }

  // Generate a zero rid.
  REQID rid = REQID_Generator::generate_zero_reqid();

  // Make the outgoing packet
  sp_int32 byte_size = _message.ByteSize();
  sp_uint32 sop = OutgoingPacket::SizeRequiredToPackString(_message.GetTypeName()) + REQID_size +
                  OutgoingPacket::SizeRequiredToPackProtocolBuffer(byte_size);
  auto opkt = new OutgoingPacket(sop);
  CHECK_EQ(opkt->PackString(_message.GetTypeName()), 0);
  CHECK_EQ(opkt->PackREQID(rid), 0);
  CHECK_EQ(opkt->PackProtocolBuffer(_message, byte_size), 0);

  Connection* conn = static_cast<Connection*>(conn_);
  if (conn->sendPacket(opkt, NULL) != 0) {
    LOG(ERROR) << "Some problem sending message thru the connection. Dropping message" << std::endl;
    delete opkt;
    return;
  }
  return;
}
Example #3
0
void Client::SendResponse(REQID _id, const google::protobuf::Message& _response) {
  sp_int32 byte_size = _response.ByteSize();
  sp_uint32 data_size = OutgoingPacket::SizeRequiredToPackString(_response.GetTypeName()) +
                        REQID_size + OutgoingPacket::SizeRequiredToPackProtocolBuffer(byte_size);
  auto opkt = new OutgoingPacket(data_size);
  CHECK_EQ(opkt->PackString(_response.GetTypeName()), 0);
  CHECK_EQ(opkt->PackREQID(_id), 0);
  CHECK_EQ(opkt->PackProtocolBuffer(_response, byte_size), 0);
  InternalSendResponse(opkt);
  return;
}
Example #4
0
static MessageData 
PackSingleAttribute(MessageData data, WSMAttribute *attr_list, int num)
{
    register int i;

    data = PackListNum(data, num);
    for (i = 0; i < num; i++, attr_list++) {
	data = PackString(data, XrmQuarkToString(attr_list->nameq));
	data = PackCARD8(data, (CARD8) attr_list->size);
	data = PackBoolean(data, attr_list->is_list);
    }
    return(data);
}
Example #5
0
/*----------------------------------------------------------------------*
  |                                 SendDefineCommand                     |
 *----------------------------------------------------------------------*/
void 
SendDefineCommand (int parID, int commID, char *cmdName, char *cmdDefault)
{
  Time    time;
  XtPointer msg,save;
  int     size=0;
  CARD32  selection = 0L;
  CARD32 commandID = 0L;
  CARD32 parentID = 0L;

  commandID += commID;
  parentID += parID;
  time = GetTimestamp(dsp);

  selection += atoms.own_selection;
  size += sizeof(CARD32);  /* command id */
  size += sizeof(CARD32); /* selection */
  size += sizeof(CARD32);  /* parent id */
  size += sizeof(CARD16) + (strlen(cmdName) * sizeof(CARD8)); /* name */
  size += sizeof(CARD16) + (strlen(cmdDefault) * sizeof(CARD8)); /* defalault label */

  save = msg = (XtPointer) XtMalloc(size);

  
  msg = PackCARD32(msg, (CARD32) commandID);
  msg = PackCARD32(msg, (CARD32) selection);
  msg = PackCARD32(msg, (CARD32) parentID);
  msg = PackString(msg, (String) cmdName);
  msg = PackString(msg, (String) cmdDefault);

  PRINT("DefineCommand: %d, %d, %d, '%s', '%s'\n",
	 commandID, selection, parentID, cmdName, cmdDefault);
  SendMessage(DEFINE, save, size, time);


}	
Example #6
0
static void AsyncResponse_TestCallback
(
    uint32_t data,
    const char* name,
    int dataFile,
    void* contextPtr
)
{
    le_msg_MessageRef_t _msgRef;
    _Message_t* _msgPtr;
    _ServerData_t* serverDataPtr = (_ServerData_t*)contextPtr;

    // This is a one-time handler; if the server accidently calls it a second time, then
    // the client sesssion ref would be NULL.
    if ( serverDataPtr->clientSessionRef == NULL )
    {
        LE_FATAL("Handler passed to TestCallback() can't be called more than once");
    }

    // Will not be used if no data is sent back to client
    __attribute__((unused)) uint8_t* _msgBufPtr;

    // Create a new message object and get the message buffer
    _msgRef = le_msg_CreateMsg(serverDataPtr->clientSessionRef);
    _msgPtr = le_msg_GetPayloadPtr(_msgRef);
    _msgPtr->id = _MSGID_TestCallback;
    _msgBufPtr = _msgPtr->buffer;

    // Always pack the client context pointer first
    _msgBufPtr = PackData( _msgBufPtr, &(serverDataPtr->contextPtr), sizeof(void*) );

    // Pack the input parameters
    _msgBufPtr = PackData( _msgBufPtr, &data, sizeof(uint32_t) );
    _msgBufPtr = PackString( _msgBufPtr, name );
    le_msg_SetFd(_msgRef, dataFile);

    // Send the async response to the client
    LE_DEBUG("Sending message to client session %p : %ti bytes sent",
             serverDataPtr->clientSessionRef,
             _msgBufPtr-_msgPtr->buffer);
    SendMsgToClient(_msgRef);

    // The registered handler has been called, so no longer need the server data.
    // Explicitly set clientSessionRef to NULL, so that we can catch if this function gets
    // accidently called again.
    serverDataPtr->clientSessionRef = NULL;
    le_mem_Release(serverDataPtr);
}
Example #7
0
/*----------------------------------------------------------------------*
 |                                 SendRename                           |
 *----------------------------------------------------------------------*/
void 
SendRenameCommand(Window window, int commID, char *new_name)
{	
  Time time;
  XtPointer msg, save;
  CARD32  commandID = 0L;
  CARD32  count = 1L;
  CARD32  windowBit = 1<<30;
/*  CARD32  iconBit = 1<<31;*/
  char   str[128];
  int     size=0;

  commandID += commID;

  time = GetTimestamp(dsp);
  /*
   *  Fixup the window id receiving the client command.
   *  Top 2 bits:
   *  	10 - Icon only
   *	01 - Window only
   *	11 - Both Icon and Window
   *	00 - Reserved (Don't Use!)
   *
   *  Bottom 30 bits:
   *	0x3fffffff - All windows and/or icons
   *	0x00000000 - Root window menu
   */

  size += sizeof(CARD32);  /* command id */
  size += sizeof(CARD16) + (strlen(new_name) * sizeof(CARD8));
  size += sizeof(CARD32);  /* count */
  size += sizeof(CARD32);  /* window */

  save = msg = (XtPointer) XtMalloc(size);

  window |= windowBit;

  msg = PackCARD32(msg, (CARD32)commandID);
  msg = PackString(msg, (String) new_name);
  msg = PackCARD32(msg, (CARD32)count);
  msg = PackCARD32(msg, (CARD32)window);
  
  PRINT("RenameCommand #%d to %s on window %x (%u).\n", commandID,
	new_name, window, window);

  SendMessage(RENAME, save, size, time);
}
Example #8
0
void Client::InternalSendRequest(google::protobuf::Message* _request, void* _ctx, sp_int64 _msecs) {
  auto iter = requestResponseMap_.find(_request->GetTypeName());
  CHECK(iter != requestResponseMap_.end());
  const sp_string& _expected_response_type = iter->second;
  if (state_ != CONNECTED) {
    delete _request;
    responseHandlers[_expected_response_type](NULL, WRITE_ERROR);
    return;
  }

  // Generate the rid.
  REQID rid = message_rid_gen_->generate();

  // Insert into context map
  context_map_[rid] = std::make_pair(_expected_response_type, _ctx);

  // Make the outgoing packet
  sp_int32 byte_size = _request->ByteSize();
  sp_uint32 sop = OutgoingPacket::SizeRequiredToPackString(_request->GetTypeName()) + REQID_size +
                  OutgoingPacket::SizeRequiredToPackProtocolBuffer(byte_size);
  auto opkt = new OutgoingPacket(sop);
  CHECK_EQ(opkt->PackString(_request->GetTypeName()), 0);
  CHECK_EQ(opkt->PackREQID(rid), 0);
  CHECK_EQ(opkt->PackProtocolBuffer(*_request, byte_size), 0);

  // delete the request
  delete _request;

  Connection* conn = static_cast<Connection*>(conn_);
  if (conn->sendPacket(opkt, NULL) != 0) {
    context_map_.erase(rid);
    delete opkt;
    responseHandlers[_expected_response_type](NULL, WRITE_ERROR);
    return;
  }
  if (_msecs > 0) {
    auto cb = [rid, this](EventLoop::Status s) { this->OnPacketTimer(rid, s); };
    CHECK_GT(eventLoop_->registerTimer(std::move(cb), false, _msecs), 0);
  }
  return;
}
Example #9
0
static void Handle_allParameters
(
    le_msg_MessageRef_t _msgRef

)
{
    // Get the message buffer pointer
    uint8_t* _msgBufPtr = ((_Message_t*)le_msg_GetPayloadPtr(_msgRef))->buffer;

    // Needed if we are returning a result or output values
    uint8_t* _msgBufStartPtr = _msgBufPtr;

    // Unpack the input parameters from the message
    common_EnumExample_t a;
    _msgBufPtr = UnpackData( _msgBufPtr, &a, sizeof(common_EnumExample_t) );

    size_t dataNumElements;
    _msgBufPtr = UnpackData( _msgBufPtr, &dataNumElements, sizeof(size_t) );

    uint32_t data[dataNumElements];
    _msgBufPtr = UnpackData( _msgBufPtr, data, dataNumElements*sizeof(uint32_t) );

    size_t outputNumElements;
    _msgBufPtr = UnpackData( _msgBufPtr, &outputNumElements, sizeof(size_t) );
    if ( outputNumElements > 10 )
    {
        LE_DEBUG("Adjusting outputNumElements from %zd to 10", outputNumElements);
        outputNumElements = 10;
    }

    char label[21];
    _msgBufPtr = UnpackString( _msgBufPtr, label, 21 );

    size_t responseNumElements;
    _msgBufPtr = UnpackData( _msgBufPtr, &responseNumElements, sizeof(size_t) );

    size_t moreNumElements;
    _msgBufPtr = UnpackData( _msgBufPtr, &moreNumElements, sizeof(size_t) );


    // Define storage for output parameters
    uint32_t b;

    uint32_t output[outputNumElements];
    char response[responseNumElements]; response[0]=0;
    char more[moreNumElements]; more[0]=0;

    // Call the function
    allParameters ( a, &b, data, dataNumElements, output, &outputNumElements, label, response, responseNumElements, more, moreNumElements );


    // Re-use the message buffer for the response
    _msgBufPtr = _msgBufStartPtr;


    // Pack any "out" parameters
    _msgBufPtr = PackData( _msgBufPtr, &b, sizeof(uint32_t) );
    _msgBufPtr = PackData( _msgBufPtr, &outputNumElements, sizeof(size_t) );
    _msgBufPtr = PackData( _msgBufPtr, output, outputNumElements*sizeof(uint32_t) );
    _msgBufPtr = PackString( _msgBufPtr, response );
    _msgBufPtr = PackString( _msgBufPtr, more );

    // Return the response
    LE_DEBUG("Sending response to client session %p : %ti bytes sent",
             le_msg_GetSession(_msgRef),
             _msgBufPtr-_msgBufStartPtr);
    le_msg_Respond(_msgRef);
}
Example #10
0
//--------------------------------------------------------------------------------------------------
BugTestRef_t AddBugTest
(
    const char* newPathPtr,
        ///< [IN]

    BugTestFunc_t handlerPtr,
        ///< [IN]

    void* contextPtr
        ///< [IN]
)
{
    le_msg_MessageRef_t _msgRef;
    le_msg_MessageRef_t _responseMsgRef;
    _Message_t* _msgPtr;

    // Will not be used if no data is sent/received from server.
    __attribute__((unused)) uint8_t* _msgBufPtr;

    BugTestRef_t _result;

    // Range check values, if appropriate
    if ( strlen(newPathPtr) > 512 ) LE_FATAL("strlen(newPathPtr) > 512");


    // Create a new message object and get the message buffer
    _msgRef = le_msg_CreateMsg(GetCurrentSessionRef());
    _msgPtr = le_msg_GetPayloadPtr(_msgRef);
    _msgPtr->id = _MSGID_AddBugTest;
    _msgBufPtr = _msgPtr->buffer;

    // Pack the input parameters
    _msgBufPtr = PackString( _msgBufPtr, newPathPtr );
    // The input parameters are stored in the client data object, and it is
    // a pointer to this object that is passed down.
    // Create a new client data object and fill it in
    _ClientData_t* _clientDataPtr = le_mem_ForceAlloc(_ClientDataPool);
    _clientDataPtr->handlerPtr = (le_event_HandlerFunc_t)handlerPtr;
    _clientDataPtr->contextPtr = contextPtr;
    _clientDataPtr->callersThreadRef = le_thread_GetCurrent();
    contextPtr = _clientDataPtr;
    _msgBufPtr = PackData( _msgBufPtr, &contextPtr, sizeof(void*) );

    // Send a request to the server and get the response.
    LE_DEBUG("Sending message to server and waiting for response");
    _responseMsgRef = le_msg_RequestSyncResponse(_msgRef);
    // It is a serious error if we don't get a valid response from the server
    LE_FATAL_IF(_responseMsgRef == NULL, "Valid response was not received from server");

    // Process the result and/or output parameters, if there are any.
    _msgPtr = le_msg_GetPayloadPtr(_responseMsgRef);
    _msgBufPtr = _msgPtr->buffer;

    // Unpack the result first
    _msgBufPtr = UnpackData( _msgBufPtr, &_result, sizeof(_result) );
    // Put the handler reference result into the client data object, and
    // then return a safe reference to the client data object as the reference.
    _clientDataPtr->handlerRef = (le_event_HandlerRef_t)_result;
    _LOCK
    _result = le_ref_CreateRef(_HandlerRefMap, _clientDataPtr);
    _UNLOCK

    // Unpack any "out" parameters


    // Release the message object, now that all results/output has been copied.
    le_msg_ReleaseMsg(_responseMsgRef);

    return _result;
}
Example #11
0
//--------------------------------------------------------------------------------------------------
void allParameters
(
    common_EnumExample_t a,
        ///< [IN]
        ///< first one-line comment
        ///< second one-line comment

    uint32_t* bPtr,
        ///< [OUT]

    const uint32_t* dataPtr,
        ///< [IN]

    size_t dataNumElements,
        ///< [IN]

    uint32_t* outputPtr,
        ///< [OUT]
        ///< some more comments here
        ///< and some comments here as well

    size_t* outputNumElementsPtr,
        ///< [INOUT]

    const char* label,
        ///< [IN]

    char* response,
        ///< [OUT]
        ///< comments on final parameter, first line
        ///< and more comments

    size_t responseNumElements,
        ///< [IN]

    char* more,
        ///< [OUT]
        ///< This parameter tests a bug fix

    size_t moreNumElements
        ///< [IN]
)
{
    le_msg_MessageRef_t _msgRef;
    le_msg_MessageRef_t _responseMsgRef;
    _Message_t* _msgPtr;

    // Will not be used if no data is sent/received from server.
    __attribute__((unused)) uint8_t* _msgBufPtr;



    // Range check values, if appropriate
    if ( dataNumElements > 10 ) LE_FATAL("dataNumElements > 10");
    if ( strlen(label) > 20 ) LE_FATAL("strlen(label) > 20");


    // Create a new message object and get the message buffer
    _msgRef = le_msg_CreateMsg(GetCurrentSessionRef());
    _msgPtr = le_msg_GetPayloadPtr(_msgRef);
    _msgPtr->id = _MSGID_allParameters;
    _msgBufPtr = _msgPtr->buffer;

    // Pack the input parameters
    _msgBufPtr = PackData( _msgBufPtr, &a, sizeof(common_EnumExample_t) );
    _msgBufPtr = PackData( _msgBufPtr, &dataNumElements, sizeof(size_t) );
    _msgBufPtr = PackData( _msgBufPtr, dataPtr, dataNumElements*sizeof(uint32_t) );
    _msgBufPtr = PackData( _msgBufPtr, outputNumElementsPtr, sizeof(size_t) );
    _msgBufPtr = PackString( _msgBufPtr, label );
    _msgBufPtr = PackData( _msgBufPtr, &responseNumElements, sizeof(size_t) );
    _msgBufPtr = PackData( _msgBufPtr, &moreNumElements, sizeof(size_t) );

    // Send a request to the server and get the response.
    LE_DEBUG("Sending message to server and waiting for response");
    _responseMsgRef = le_msg_RequestSyncResponse(_msgRef);
    // It is a serious error if we don't get a valid response from the server
    LE_FATAL_IF(_responseMsgRef == NULL, "Valid response was not received from server");

    // Process the result and/or output parameters, if there are any.
    _msgPtr = le_msg_GetPayloadPtr(_responseMsgRef);
    _msgBufPtr = _msgPtr->buffer;


    // Unpack any "out" parameters
    _msgBufPtr = UnpackData( _msgBufPtr, bPtr, sizeof(uint32_t) );
    _msgBufPtr = UnpackData( _msgBufPtr, outputNumElementsPtr, sizeof(size_t) );
    _msgBufPtr = UnpackData( _msgBufPtr, outputPtr, *outputNumElementsPtr*sizeof(uint32_t) );
    _msgBufPtr = UnpackDataString( _msgBufPtr, response, responseNumElements*sizeof(char) );
    _msgBufPtr = UnpackDataString( _msgBufPtr, more, moreNumElements*sizeof(char) );

    // Release the message object, now that all results/output has been copied.
    le_msg_ReleaseMsg(_responseMsgRef);
}
Example #12
0
MessageData 
_WSMPackReply(Display *dpy, int screen_num,
	      WSMReply *reply, unsigned long *msg_data_len)
{
    WSMAttribute *attr;
    WSMWinInfo *win_info;
    WSMWinEntry *win_entry;
    register int i;
    long size;
    MessageData data, save;

    *msg_data_len = 0;		/* default value. */

    switch (reply->any.type) {
    case WSM_CONNECT:
	size = sizeof(CARD8);
	break;
    case WSM_EXTENSIONS:
	size = COUNT_SIZE;
	for (i = 0; i < reply->extensions.num_extensions; i++) {
	    size += (strlen(reply->extensions.extensions[i]) + COUNT_SIZE);
	}
	break;
    case WSM_CONFIG_FMT:
	size = BOOL_SIZE;	/* accept_diffs. */
	size += COUNT_SIZE;	/* The count of global attributes. */
	attr = reply->config_format.global_formats;
	for (i = 0; i < reply->config_format.num_global_formats; i++)  {
	    /*
	     * Bytes in string
	     */
	    size += strlen(XrmQuarkToString(attr[i].nameq)) * sizeof(CARD8);
	    /*
	     * len of string + size + is_list.
	     */
	    size += COUNT_SIZE + sizeof(CARD8) + BOOL_SIZE; 
	}
	size += COUNT_SIZE;	/* The count of window attributes. */
	attr = reply->config_format.window_formats;
	for (i = 0; i < reply->config_format.num_window_formats; i++)  {
	    /*
	     * Bytes in string
	     */
	    size += strlen(XrmQuarkToString(attr[i].nameq)) * sizeof(CARD8);
	    /*
	     * len of string + size + is_list.
	     */
	    size += COUNT_SIZE + sizeof(CARD8) + BOOL_SIZE; 
	}
	size += COUNT_SIZE;	/* The count of icon attributes. */
	attr = reply->config_format.icon_formats;
	for (i = 0; i < reply->config_format.num_icon_formats; i++)  {
	    /*
	     * Bytes in string
	     */
	    size += strlen(XrmQuarkToString(attr[i].nameq)) * sizeof(CARD8);
	    /*
	     * len of string + size + is_list.
	     */
	    size += COUNT_SIZE + sizeof(CARD8) + BOOL_SIZE; 
	}
	break;
    case WSM_GET_STATE:
	size = COUNT_SIZE;	/* The count of window info. */
	win_info = reply->get_state.win_info_list;
	for (i = 0; i < reply->get_state.num_win_info_list; i++,win_info++)
	    size += WinInfoSizePacked(dpy, screen_num, win_info);
	break;
    case WSM_SET_STATE:
	size = 0;
	break;
    case WSM_REG_WINDOW:
	size = WinDataSizePacked(dpy, screen_num, 
				 reply->register_window.window_data,
				 reply->register_window.num_window_data,
				 WSM_WINDOW_FMT);
	break;
    case WSM_WM_GET_BACKGROUND_WINDOW:
	size = sizeof(CARD32);
	break;
    case WSM_WM_SET_BACKGROUND_WINDOW:
	size = sizeof(CARD32);
	break;
    case WSM_WM_WINDOWS:
	size = COUNT_SIZE;	/* The count of window entries. */
	win_entry = reply->wm_windows.win_entry_list;
	for (i = 0; i < reply->wm_windows.num_win_entry_list; i++,win_entry++)
	    size += WinEntrySizePacked(dpy, screen_num, win_entry);
	break;
    case WSM_WM_FOCUS:
	size = sizeof(CARD32);
	break;
    case WSM_WM_POINTER:
	size  = sizeof(CARD32); /* window */
	size += sizeof(CARD32); /* flag */
	break;
    default:
	/*
	 * ||| Error Message.
	 */
	return(NULL);
    }

    save = data = (MessageData) XtMalloc(size);

    switch (reply->any.type) {
    case WSM_CONNECT:
	(void) PackCARD8(data, (CARD8) (reply->connect.version & 0xFF));
	break;
    case WSM_EXTENSIONS:
	data = PackListNum(data, reply->extensions.num_extensions);
	for (i = 0; i < reply->extensions.num_extensions; i++) 
	    data = PackString(data, reply->extensions.extensions[i]);
	break;
    case WSM_CONFIG_FMT:
	PackConfigFormat(data, &(reply->config_format));
	break;
    case WSM_GET_STATE:
	win_info = reply->get_state.win_info_list;
	data = PackListNum(data, reply->get_state.num_win_info_list);
	for (i = 0; i < reply->get_state.num_win_info_list; i++, win_info++)
	    data = PackWinInfo(dpy, screen_num, data, win_info);
	break;
    case WSM_SET_STATE:
	break;
    case WSM_REG_WINDOW:
	data = PackWinData(dpy, screen_num, data, 
			   reply->register_window.window_data,
			   reply->register_window.num_window_data,
			   WSM_WINDOW_FMT);
	break;
    case WSM_WM_GET_BACKGROUND_WINDOW:
	(void) PackWindow(data, reply->get_background.window);
	break;
    case WSM_WM_SET_BACKGROUND_WINDOW:
	(void) PackWindow(data, reply->set_background.window);
	break;
    case WSM_WM_WINDOWS:
	win_entry = reply->wm_windows.win_entry_list;
	data = PackListNum(data, reply->wm_windows.num_win_entry_list);
	for (i = 0; i < reply->wm_windows.num_win_entry_list; i++, win_entry++)
	    data = PackWinEntry(dpy, screen_num, data, win_entry);
	break;
    case WSM_WM_FOCUS:
	(void) PackWindow(data, reply->wm_focus.window);
	break;
    case WSM_WM_POINTER:
	(void) PackWindow(data, reply->wm_pointer.window);
	(void) PackCARD32(data, reply->wm_pointer.location_flag);
	break;
    default:
	break;
    }
    
    *msg_data_len = size;
    return(save);
}/* _WSMPackReply */
Example #13
0
MessageData 
_WSMPackRequest(Display *dpy, int screen_num, WSMRequest *request,
		unsigned long *msg_data_len, WSMErrorCode *error)
{
    MessageData data, save;
    int i;
    long size;
    WSMWinInfo *win_info;
    WSMConfigFormatData *global_attrs, *win_attrs, *icon_attrs;

    *msg_data_len = 0;		/* default value. */

    global_attrs = _WSMGetConfigFormat(dpy, screen_num, WSM_GLOBAL_FMT);
    win_attrs = _WSMGetConfigFormat(dpy, screen_num, WSM_WINDOW_FMT);
    icon_attrs = _WSMGetConfigFormat(dpy, screen_num, WSM_ICON_FMT);

    *error = WSM_SUCCESS;

    if (_WSMRequiresConfigFormat(request->any.type) && 
	(global_attrs->num_attrs == 0) && 
	(win_attrs->num_attrs == 0) && (icon_attrs->num_attrs == 0))
    {
	*error = WSM_ERROR_NO_CONFIG_FORMAT;
	return(NULL);
    }
    if (((request->any.type == WSM_CONNECT) ||
	 (request->any.type == WSM_CONFIG_FMT)) &&
	((global_attrs->num_attrs != 0) ||
	 (win_attrs->num_attrs != 0) || (icon_attrs->num_attrs != 0)))
    {
	*error = WSM_ERROR_ALREADY_HAVE_CONFIG_FORMAT;
	return(NULL);
    }

    /* before sending extensions make sure screen_info config format
       is cleared */
    /* may want to remove this and leave it up to application writer */
    if ((request->any.type == WSM_EXTENSIONS) && 
	((global_attrs->num_attrs != 0) ||
	 (win_attrs->num_attrs != 0) || (icon_attrs->num_attrs != 0)))
      {
	_WSMClearConfigScreenInfo(dpy,screen_num);
      }
    /*
     *  Calculate the size of the request.
     */
    switch (request->any.type) {
    case WSM_CONNECT:
	size = COUNT_SIZE;
	size += sizeof(CARD8) * request->connect.num_versions;
	break;
    case WSM_EXTENSIONS:
	size = COUNT_SIZE;
	for (i = 0; i < request->extensions.num_extensions; i++) {
	    size += (strlen(request->extensions.extension_suggestions[i]) +
		     COUNT_SIZE);
	}
	break;
    case WSM_CONFIG_FMT:
	size = 0;
	break;
    case WSM_GET_STATE:
	size = sizeof(CARD32) + BOOL_SIZE;
	break;
    case WSM_SET_STATE:
	size = COUNT_SIZE;	/* The count of window info. */
	win_info = request->set_state.win_info_list;
	for (i = 0; i < request->set_state.num_win_info_list; i++,win_info++)
	    size += WinInfoSizePacked(dpy, screen_num, win_info);
	break;
    case WSM_REG_WINDOW:
	size = sizeof(CARD32);
	break;
    case WSM_WM_GET_BACKGROUND_WINDOW:
	size = sizeof(CARD16);
	break;
    case WSM_WM_SET_BACKGROUND_WINDOW:
	size = sizeof(CARD32);
	break;
    case WSM_WM_WINDOWS:
	size = sizeof(CARD32); /* flag */
	size += COUNT_SIZE;    /* prop count */
	size += request->wm_windows.num_window_properties * sizeof(Window);
	size += COUNT_SIZE;    /* num match attributes */
	for (i=0; i<request->wm_windows.num_match_attributes; i++)
	  {
	    size += COUNT_SIZE; /* num attributes */
	    size += 2 *
	            request->wm_windows.match_attributes[i]->num_attributes *
		    sizeof(WindowProperty);
	  }
	break;
    case WSM_WM_FOCUS:
	size = 0;
	break;
    case WSM_WM_POINTER:
	size = 0;
	break;
    default:
	return(NULL);
    }

    save = data = (MessageData) XtMalloc(size);

    /*
     * Fill in the message.
     */
    switch (request->any.type) {
    case WSM_CONNECT:
	data = PackListNum(data, request->connect.num_versions);
	for (i = 0; i < request->connect.num_versions; i++) 
	    data = PackCARD8(data, (CARD8) request->connect.known_versions[i]);
	break;
    case WSM_EXTENSIONS:
	data = PackListNum(data, request->extensions.num_extensions);
	for (i = 0; i < request->extensions.num_extensions; i++) 
	    data=PackString(data,request->extensions.extension_suggestions[i]);
	break;
    case WSM_CONFIG_FMT:
	break;
    case WSM_GET_STATE:
	data = PackWindow(data, request->get_state.window);
	(void) PackBoolean(data, request->get_state.diffs_allowed);
	break;
    case WSM_SET_STATE:
	win_info = request->set_state.win_info_list;
	data = PackListNum(data, request->set_state.num_win_info_list);
	for (i = 0; i < request->set_state.num_win_info_list; i++, win_info++)
	    data = PackWinInfo(dpy, screen_num, data, win_info);
	break;
    case WSM_REG_WINDOW:
	(void) PackWindow(data, request->register_window.window);
	break;
    case WSM_WM_GET_BACKGROUND_WINDOW:
	(void) PackCARD16(data, request->get_background.screen);
	break;
    case WSM_WM_SET_BACKGROUND_WINDOW:
	(void) PackWindow(data, request->set_background.window);
	break;
    case WSM_WM_WINDOWS:
	{
	  int i, j;

	  data = PackCARD32(data, request->wm_windows.location_flag);
	  data = PackListNum(data, request->wm_windows.num_window_properties);
	  for (i=0; i<request->wm_windows.num_window_properties; i++)
	    data = PackProperty(data, request->wm_windows.window_properties[i]);

	  data = PackListNum(data, request->wm_windows.num_match_attributes);
	  for (i = 0;  i < request->wm_windows.num_match_attributes;  i++)
	    {
	      AttributePair *match_attr;

	      match_attr = request->wm_windows.match_attributes[i];
	      data = PackListNum(data, match_attr->num_attributes);

	      for (j = 0;  j < match_attr->num_attributes;  j++)
		data = PackProperty(data, match_attr->allowed_attributes[j]);

	      for (j = 0;  j < match_attr->num_attributes;  j++)
		data = PackProperty(data, match_attr->prohibited_attributes[j]);
	    }
	}
	break;
    case WSM_WM_FOCUS:
	break;
    case WSM_WM_POINTER:
	break;
    default:
	break;
    }
    
    *msg_data_len = size;
    return(save);
} /* _WSMPackRequest */