Beispiel #1
0
/*
 * listview_get_tool - ツール情報の取得
 */
static TOOL_INFO *listview_get_tool(const HWND hListView, int *cnt)
{
	TOOL_INFO *ti;
	TOOL_INFO *new_ti;
	int i;

	if ((*cnt = ListView_GetItemCount(hListView)) == 0) {
		return NULL;
	}

	// 項目の作成
	if ((new_ti = mem_calloc(sizeof(TOOL_INFO) * *cnt)) == NULL) {
		*cnt = 0;
		return NULL;
	}

	for (i = 0; i < *cnt; i++) {
		if ((ti = (TOOL_INFO *)listview_get_lparam(hListView, i)) == NULL) {
			continue;
		}
		(new_ti + i)->title = alloc_copy(ti->title);
		(new_ti + i)->lib_file_path = alloc_copy(ti->lib_file_path);
		(new_ti + i)->func_name = alloc_copy(ti->func_name);
		(new_ti + i)->cmd_line = alloc_copy(ti->cmd_line);
		(new_ti + i)->call_type = ti->call_type;
		(new_ti + i)->copy_paste = ti->copy_paste;
		(new_ti + i)->old = ti->old;
		(new_ti + i)->modifiers = ti->modifiers;
		(new_ti + i)->virtkey = ti->virtkey;
	}
	return new_ti;
}
Beispiel #2
0
/*
 * listview_set_tool - ListViewにツール情報を追加する
 */
static void listview_set_tool(const HWND hListView, TOOL_INFO *ti, const BOOL copy)
{
	LV_ITEM lvi;
	TOOL_INFO *new_ti;
	int i;

	if (copy == TRUE) {
		if ((new_ti = mem_calloc(sizeof(TOOL_INFO))) == NULL) {
			return;
		}
		new_ti->title = alloc_copy(ti->title);
		new_ti->lib_file_path = alloc_copy(ti->lib_file_path);
		new_ti->func_name = alloc_copy(ti->func_name);
		new_ti->cmd_line = alloc_copy(ti->cmd_line);
		new_ti->call_type = ti->call_type;
		new_ti->copy_paste = ti->copy_paste;
		new_ti->old = ti->old;
		new_ti->modifiers = ti->modifiers;
		new_ti->virtkey = ti->virtkey;
	} else {
		new_ti = ti;
	}

	lvi.mask = LVIF_TEXT | LVIF_PARAM;
	lvi.iItem = ListView_GetItemCount(hListView);
	lvi.iSubItem = 0;
	lvi.pszText = TEXT("");
	lvi.cchTextMax = BUF_SIZE - 1;
	lvi.iImage = 0;
	lvi.lParam = (LPARAM)new_ti;
	i = ListView_InsertItem(hListView, &lvi);

	listview_set_text(hListView, i);
}
Beispiel #3
0
Pixmap::Pixmap(Coord x1, Coord y1, Coord x2, Coord y2)
{
   uint32 w, h;
   w = x2 - x1 + 1;
   h = y2 - y1 + 1;
   alloc_copy(0, w, h);
}
Beispiel #4
0
/*
 * listview_get_filter - フィルタ情報の取得
 */
static FILTER_INFO *listview_get_filter(const HWND hListView, int *cnt)
{
	FILTER_INFO *fi;
	FILTER_INFO *new_fi;
	int i;

	if ((*cnt = ListView_GetItemCount(hListView)) == 0) {
		return NULL;
	}

	// 項目の作成
	if ((new_fi = mem_calloc(sizeof(FILTER_INFO) * *cnt)) == NULL) {
		*cnt = 0;
		return NULL;
	}

	for (i = 0; i < *cnt; i++) {
		if ((fi = (FILTER_INFO *)listview_get_lparam(hListView, i)) == NULL) {
			continue;
		}
		(new_fi + i)->format_name = alloc_copy(fi->format_name);
		(new_fi + i)->action = fi->action;
		(new_fi + i)->save = fi->save;
		(new_fi + i)->limit_size = fi->limit_size;
	}
	return new_fi;
}
Beispiel #5
0
/*
 * listview_set_filter - ListViewにフィルタ情報を追加する
 */
static void listview_set_filter(const HWND hListView, FILTER_INFO *fi, const BOOL copy)
{
	LV_ITEM lvi;
	FILTER_INFO *new_fi;
	int i;

	if (copy == TRUE) {
		if ((new_fi = mem_calloc(sizeof(FILTER_INFO))) == NULL) {
			return;
		}
		new_fi->format_name = alloc_copy(fi->format_name);
		new_fi->action = fi->action;
		new_fi->save = fi->save;
		new_fi->limit_size = fi->limit_size;
	} else {
		new_fi = fi;
	}

	lvi.mask = LVIF_TEXT | LVIF_PARAM;
	lvi.iItem = ListView_GetItemCount(hListView);
	lvi.iSubItem = 0;
	lvi.pszText = TEXT("");
	lvi.cchTextMax = BUF_SIZE - 1;
	lvi.iImage = 0;
	lvi.lParam = (LPARAM)new_fi;
	i = ListView_InsertItem(hListView, &lvi);

	listview_set_text(hListView, i);
}
Beispiel #6
0
Pixmap& Pixmap::operator = (uint8 *area)
{
   uint32 w, h;
   w = ((uint16 *)area)[0];
   h = ((uint16 *)area)[1];
   alloc_copy(area+4, w, h);
   return *this;
}
Beispiel #7
0
/*
 * data_item_copy - アイテムのコピーを作成
 */
DATA_INFO *data_item_copy(const DATA_INFO *di, const BOOL next_copy, const BOOL move_flag, TCHAR *err_str)
{
    DATA_INFO *new_di;

    if (di == NULL) {
        return NULL;
    }
    if ((new_di = (DATA_INFO *)mem_calloc(sizeof(DATA_INFO))) == NULL) {
        message_get_error(GetLastError(), err_str);
        return NULL;
    }
    new_di->struct_size = sizeof(DATA_INFO);
    new_di->type = di->type;
    new_di->title = alloc_copy(di->title);
    new_di->format_name = alloc_copy(di->format_name);
    new_di->format_name_hash = di->format_name_hash;
    new_di->format = di->format;
    new_di->modified.dwLowDateTime = di->modified.dwLowDateTime;
    new_di->modified.dwHighDateTime = di->modified.dwHighDateTime;
    new_di->window_name = alloc_copy(di->window_name);
    new_di->plugin_string = alloc_copy(di->plugin_string);
    new_di->plugin_param = di->plugin_param;
    if (move_flag == TRUE) {
        new_di->hkey_id = di->hkey_id;
        new_di->op_modifiers = di->op_modifiers;
        new_di->op_virtkey = di->op_virtkey;
        new_di->op_paste = di->op_paste;
    }
    // データのコピー
    if (di->data != NULL && (new_di->data = format_copy_data(di->format_name, di->data, &new_di->size)) == NULL) {
        new_di->data = clipboard_copy_data(di->format, di->data, &new_di->size);
    }

    // 子アイテムのコピー
    if (di->child != NULL && (new_di->child = data_item_copy(di->child, TRUE, move_flag, err_str)) == NULL) {
        data_free(new_di);
        return NULL;
    }
    // 次アイテムのコピー
    if (next_copy == TRUE && di->next != NULL &&
            (new_di->next = data_item_copy(di->next, TRUE, move_flag, err_str)) == NULL) {
        data_free(new_di);
        return NULL;
    }
    return new_di;
}
Beispiel #8
0
/*
 * data_create_folder - フォルダの作成
 */
DATA_INFO *data_create_folder(const TCHAR *title, TCHAR *err_str)
{
    DATA_INFO *new_item;

    // アイテムの確保
    if ((new_item = (DATA_INFO *)mem_calloc(sizeof(DATA_INFO))) == NULL) {
        message_get_error(GetLastError(), err_str);
        return NULL;
    }
    new_item->struct_size = sizeof(DATA_INFO);
    new_item->title = alloc_copy(title);
    new_item->type = TYPE_FOLDER;
    return new_item;
}
Beispiel #9
0
int main(int argc, char const *argv[])
{
        const char* path  = argv[1];
        char* buf         = NULL;
        FILE* elf         = fopen("arm.elf",      "r");
        FILE* patch       = fopen("patched", "w");
        ssize_t fsize     = 0;

        if (argc != 1) {
                fprintf(stderr, "Invalid number of arguments\n"
                                "Specify only the input file\n");
                return -1;
        }
        if (elf == NULL || patch == NULL) {
                perror("Failed to open executable or create copy");
                goto fail;
        }

        fsize = alloc_copy(elf, &buf);
        if (fsize == -1) {
                perror("Failed to get file to buffer");
                goto fail;
        }

        ((unsigned char*)buf)[OFFSET] = (unsigned char)0xd0;
        if (fwrite(buf, fsize, 1, patch) != 1) {
                perror("Failed to save patched copy");
                goto fail;
        }

        fclose(elf);
        fclose(patch);
        free(buf);
        return 0;

fail:
        if (elf) {
                fclose(elf);
                elf = NULL;
        }
        if (patch) {
                fclose(patch);
                patch = NULL;
        }
        if (buf) {
                free(buf);
                buf = NULL;
        }
        return -1;
}
Beispiel #10
0
/*
 * data_create_item - アイテムの作成
 */
DATA_INFO *data_create_item(const TCHAR *title, const BOOL set_date, TCHAR *err_str)
{
    DATA_INFO *new_item;

    // アイテムの確保
    if ((new_item = (DATA_INFO *)mem_calloc(sizeof(DATA_INFO))) == NULL) {
        message_get_error(GetLastError(), err_str);
        return NULL;
    }
    new_item->struct_size = sizeof(DATA_INFO);
    new_item->type = TYPE_ITEM;
    new_item->title = alloc_copy(title);
    if (set_date == TRUE) {
        data_set_modified(new_item);
    }
    return new_item;
}
Beispiel #11
0
/*
 * data_create_data - データの作成
 */
DATA_INFO *data_create_data(const UINT format, TCHAR *format_name, const HANDLE data, const DWORD size, const BOOL init, TCHAR *err_str)
{
    DATA_INFO *new_item;

    // アイテムの確保
    if ((new_item = (DATA_INFO *)mem_calloc(sizeof(DATA_INFO))) == NULL) {
        message_get_error(GetLastError(), err_str);
        return NULL;
    }
    new_item->struct_size = sizeof(DATA_INFO);
    new_item->type = TYPE_DATA;
    new_item->format = (format != 0) ? format : clipboard_get_format(0, format_name);
    new_item->format_name = alloc_copy(format_name);
    new_item->format_name_hash = str2hash(new_item->format_name);
    new_item->data = data;
    new_item->size = size;
    format_initialize_item(new_item, (data == NULL) ? init : FALSE);
    return new_item;
}
Beispiel #12
0
/*
 * menu_get_keyname - キー名を取得
 */
TCHAR *menu_get_keyname(const UINT modifiers, const UINT virtkey)
{
	TCHAR buf[BUF_SIZE];
	UINT scan_code;
	int ext_flag = 0;

	*buf = TEXT('\0');
	if (modifiers & MOD_CONTROL) {
		lstrcat(buf, TEXT("Ctrl+"));
	}
	if (modifiers & MOD_SHIFT) {
		lstrcat(buf, TEXT("Shift+"));
	}
	if (modifiers & MOD_ALT) {
		lstrcat(buf, TEXT("Alt+"));
	}
	if (modifiers & MOD_WIN) {
		lstrcat(buf, TEXT("Win+"));
	}
	if (virtkey == 0 || (scan_code = MapVirtualKey(virtkey, 0)) <= 0) {
		// なし
		return NULL;
	}
	if (virtkey == VK_APPS ||
		virtkey == VK_PRIOR ||
		virtkey == VK_NEXT ||
		virtkey == VK_END ||
		virtkey == VK_HOME ||
		virtkey == VK_LEFT ||
		virtkey == VK_UP ||
		virtkey == VK_RIGHT ||
		virtkey == VK_DOWN ||
		virtkey == VK_INSERT ||
		virtkey == VK_DELETE ||
		virtkey == VK_NUMLOCK) {
		ext_flag = 1 << 24;
	}
	GetKeyNameText((scan_code << 16) | ext_flag, buf + lstrlen(buf), BUF_SIZE - lstrlen(buf) - 1);
	return alloc_copy(buf);
}
M2MResource& M2MResource::operator=(const M2MResource& other)
{
    if (this != &other) { // protect against invalid self-assignment
        _has_multiple_instances = other._has_multiple_instances;
        if(!other._resource_instance_list.empty()){
            M2MResourceInstance* ins = NULL;
            M2MResourceInstanceList::const_iterator it;
            it = other._resource_instance_list.begin();
            for (; it!=other._resource_instance_list.end(); it++ ) {
                ins = *it;
                _resource_instance_list.push_back(new M2MResourceInstance(*ins));
            }
        }
        if(other._delayed_token) {
            _delayed_token = (uint8_t*)alloc_copy(other._delayed_token,other._delayed_token_len);
            if(_delayed_token) {
                _delayed_token_len = other._delayed_token_len;
            }
        }
    }
    return *this;
}
sn_coap_hdr_s* M2MResource::handle_post_request(nsdl_s *nsdl,
                                                sn_coap_hdr_s *received_coap_header,
                                                M2MObservationHandler */*observation_handler*/,
                                                bool &/*execute_value_updated*/)
{
    tr_debug("M2MResource::handle_post_request()");
    sn_coap_msg_code_e msg_code = COAP_MSG_CODE_RESPONSE_CHANGED; // 2.04
    sn_coap_hdr_s * coap_response = sn_nsdl_build_response(nsdl,
                                                           received_coap_header,
                                                           msg_code);
    // process the POST if we have registered a callback for it
    if(received_coap_header) {
        if ((operation() & SN_GRS_POST_ALLOWED) != 0) {
            M2MResource::M2MExecuteParameter *exec_params = new M2MResource::M2MExecuteParameter();
            if (exec_params) {
                exec_params->_object_name = object_name();
                exec_params->_resource_name = name();
                exec_params->_object_instance_id = object_instance_id();
            }
            uint16_t coap_content_type = 0;
            if(received_coap_header->payload_ptr) {
                if(received_coap_header->content_type_ptr) {
                    for(uint8_t i = 0; i < received_coap_header->content_type_len; i++) {
                        coap_content_type = (coap_content_type << 8) + (received_coap_header->content_type_ptr[i] & 0xFF);
                    }
                }
                if(coap_content_type == 0) {
                    if (exec_params){
                        exec_params->_value = alloc_string_copy(received_coap_header->payload_ptr,
                                                                received_coap_header->payload_len);
                        if (exec_params->_value) {
                            exec_params->_value_length = received_coap_header->payload_len;
                        }
                    }
                } else {
                    msg_code = COAP_MSG_CODE_RESPONSE_UNSUPPORTED_CONTENT_FORMAT;
                }
            }
            if(COAP_MSG_CODE_RESPONSE_CHANGED == msg_code) {
                tr_debug("M2MResource::handle_post_request - Execute resource function");
                execute(exec_params);
                if(_delayed_response) {
                    coap_response->msg_type = COAP_MSG_TYPE_ACKNOWLEDGEMENT;
                    coap_response->msg_code = COAP_MSG_CODE_EMPTY;
                    coap_response->msg_id = received_coap_header->msg_id;
                    if(received_coap_header->token_len) {
                        free(_delayed_token);
                        _delayed_token_len = 0;

                        _delayed_token = alloc_copy(received_coap_header->token_ptr, _delayed_token_len);
                        if(_delayed_token) {
                            _delayed_token_len = received_coap_header->token_len;
                        }
                    }
                } else {
                    uint32_t length = 0;
                    get_value(coap_response->payload_ptr, length);
                    coap_response->payload_len = length;
                }
            }
            delete exec_params;
        } else { // if ((object->operation() & SN_GRS_POST_ALLOWED) != 0)
            tr_error("M2MResource::handle_post_request - COAP_MSG_CODE_RESPONSE_METHOD_NOT_ALLOWED");
            msg_code = COAP_MSG_CODE_RESPONSE_METHOD_NOT_ALLOWED; // 4.05
        }
    } else { //if(object && received_coap_header)
        tr_error("M2MResource::handle_post_request - COAP_MSG_CODE_RESPONSE_METHOD_NOT_ALLOWED");
        msg_code = COAP_MSG_CODE_RESPONSE_METHOD_NOT_ALLOWED; // 4.01
    }
    if(coap_response) {
        coap_response->msg_code = msg_code;
    }
    return coap_response;
}
sn_coap_hdr_s* M2MResource::handle_put_request(nsdl_s *nsdl,
                                               sn_coap_hdr_s *received_coap_header,
                                               M2MObservationHandler *observation_handler,
                                               bool &execute_value_updated)
{
    tr_debug("M2MResource::handle_put_request()");
    sn_coap_msg_code_e msg_code = COAP_MSG_CODE_RESPONSE_CHANGED; // 2.04
    sn_coap_hdr_s * coap_response = NULL;
    if(_has_multiple_instances) {
        coap_response = sn_nsdl_build_response(nsdl,
                                               received_coap_header,
                                               msg_code);
        // process the PUT if we have registered a callback for it
        if(received_coap_header) {
            uint16_t coap_content_type = 0;
            bool content_type_present = false;
            if(received_coap_header->content_type_ptr) {
                if(coap_response) {
                    content_type_present = true;
                    coap_response->content_type_ptr = alloc_copy(received_coap_header->content_type_ptr,
                                                                    received_coap_header->content_type_len);
                    if(coap_response->content_type_ptr) {
                        coap_response->content_type_len = received_coap_header->content_type_len;
                        for(uint8_t i = 0; i < coap_response->content_type_len; i++) {
                            coap_content_type = (coap_content_type << 8) +
                                    (coap_response->content_type_ptr[i] & 0xFF);
                        }
                    }
                }
            }
            if(received_coap_header->options_list_ptr &&
               received_coap_header->options_list_ptr->uri_query_ptr) {
                char *query = (char*)alloc_string_copy(received_coap_header->options_list_ptr->uri_query_ptr,
                                                        received_coap_header->options_list_ptr->uri_query_len);
                if (query){
                    msg_code = COAP_MSG_CODE_RESPONSE_CHANGED;
                    tr_debug("M2MResource::handle_put_request() - Query %s", query);
                    // if anything was updated, re-initialize the stored notification attributes
                    if (!handle_observation_attribute(query)){
                        tr_debug("M2MResource::handle_put_request() - Invalid query");
                        msg_code = COAP_MSG_CODE_RESPONSE_BAD_REQUEST; // 4.00
                    }
                    free(query);
                }
            } else if ((operation() & SN_GRS_PUT_ALLOWED) != 0) {
                if(!content_type_present &&
                   M2MBase::coap_content_type() == COAP_CONTENT_OMA_TLV_TYPE) {
                    coap_content_type = COAP_CONTENT_OMA_TLV_TYPE;
                }

                tr_debug("M2MResource::handle_put_request() - Request Content-Type %d", coap_content_type);

                if(COAP_CONTENT_OMA_TLV_TYPE == coap_content_type) {
                    M2MTLVDeserializer *deserializer = new M2MTLVDeserializer();
                    if(deserializer) {
                        M2MTLVDeserializer::Error error = M2MTLVDeserializer::None;
                        error = deserializer->deserialize_resource_instances(received_coap_header->payload_ptr,
                                                                             received_coap_header->payload_len,
                                                                             *this,
                                                                             M2MTLVDeserializer::Put);
                        switch(error) {
                            case M2MTLVDeserializer::None:
                                if(observation_handler) {
                                    String value = "";
                                    if (received_coap_header->uri_path_ptr != NULL &&
                                        received_coap_header->uri_path_len > 0) {

                                        value.append_raw((char*)received_coap_header->uri_path_ptr,received_coap_header->uri_path_len);
                                    }
                                    execute_value_updated = true;
                                }
                                msg_code = COAP_MSG_CODE_RESPONSE_CHANGED;
                                break;
                            case M2MTLVDeserializer::NotFound:
                                msg_code = COAP_MSG_CODE_RESPONSE_NOT_FOUND;
                                break;
                            case M2MTLVDeserializer::NotAllowed:
                                msg_code = COAP_MSG_CODE_RESPONSE_METHOD_NOT_ALLOWED;
                                break;
                            case M2MTLVDeserializer::NotValid:
                                msg_code = COAP_MSG_CODE_RESPONSE_BAD_REQUEST;
                                break;
                        }
                        delete deserializer;
                    }
                } else {
                    msg_code =COAP_MSG_CODE_RESPONSE_UNSUPPORTED_CONTENT_FORMAT;
                } // if(COAP_CONTENT_OMA_TLV_TYPE == coap_content_type)
            } else {
                // Operation is not allowed.
                tr_error("M2MResource::handle_put_request() - COAP_MSG_CODE_RESPONSE_METHOD_NOT_ALLOWED");
                msg_code = COAP_MSG_CODE_RESPONSE_METHOD_NOT_ALLOWED;
            }
        } else {
            msg_code = COAP_MSG_CODE_RESPONSE_METHOD_NOT_ALLOWED;
        }
        if(coap_response) {
            coap_response->msg_code = msg_code;
        }
    } else {        
        coap_response = M2MResourceInstance::handle_put_request(nsdl,
                            received_coap_header,
                            observation_handler,
                            execute_value_updated);
    }
    return coap_response;
}
sn_coap_hdr_s* M2MResource::handle_get_request(nsdl_s *nsdl,
                                               sn_coap_hdr_s *received_coap_header,
                                               M2MObservationHandler *observation_handler)
{
    tr_debug("M2MResource::handle_get_request()");
    sn_coap_msg_code_e msg_code = COAP_MSG_CODE_RESPONSE_CONTENT;
    sn_coap_hdr_s * coap_response = NULL;
    if(_has_multiple_instances) {
        coap_response = sn_nsdl_build_response(nsdl,
                                               received_coap_header,
                                               msg_code);
        if(received_coap_header) {
            // process the GET if we have registered a callback for it
            if ((operation() & SN_GRS_GET_ALLOWED) != 0) {
                if(coap_response) {
                    uint16_t coap_content_type = 0;
                    bool content_type_present = false;
                    if(received_coap_header->content_type_ptr){
                        content_type_present = true;
                        coap_response->content_type_ptr = alloc_copy(received_coap_header->content_type_ptr,
                                                                     received_coap_header->content_type_len);
                        if(coap_response->content_type_ptr) {
                            coap_response->content_type_len = received_coap_header->content_type_len;
                            for(uint8_t i = 0; i < coap_response->content_type_len; i++) {
                                coap_content_type = (coap_content_type << 8) +
                                        (coap_response->content_type_ptr[i] & 0xFF);
                            }
                        }
                    }

                    if(!content_type_present &&
                       M2MBase::coap_content_type() == COAP_CONTENT_OMA_TLV_TYPE) {
                        coap_content_type = COAP_CONTENT_OMA_TLV_TYPE;
                    }

                    tr_debug("M2MResource::handle_get_request() - Request Content-Type %d", coap_content_type);
                    if (!coap_response->content_type_ptr) {
                        coap_response->content_type_ptr =
                                m2m::String::convert_integer_to_array(coap_content_type,
                                    coap_response->content_type_len);
                        if (coap_response->content_type_ptr) {
                            set_coap_content_type(coap_content_type);
                        }
                    }
                    uint8_t *data = NULL;
                    uint32_t data_length = 0;
                    // fill in the CoAP response payload
                    if(COAP_CONTENT_OMA_TLV_TYPE == coap_content_type) {
                        M2MTLVSerializer *serializer = new M2MTLVSerializer();
                        if(serializer) {
                            data = serializer->serialize(this, data_length);
                            delete serializer;
                        }
                    } else {
                        msg_code = COAP_MSG_CODE_RESPONSE_UNSUPPORTED_CONTENT_FORMAT; // Content format not supported
                    }

                    coap_response->payload_len = data_length;
                    coap_response->payload_ptr = data;

                    coap_response->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s));
                    memset(coap_response->options_list_ptr, 0, sizeof(sn_coap_options_list_s));

                    coap_response->options_list_ptr->max_age_ptr =
                            m2m::String::convert_integer_to_array(max_age(),
                                coap_response->options_list_ptr->max_age_len);

                    if(received_coap_header->token_ptr) {
                        tr_debug("M2MResource::handle_get_request - Sets Observation Token to resource");
                        set_observation_token(received_coap_header->token_ptr,
                                              received_coap_header->token_len);
                    }

                    if(received_coap_header->options_list_ptr) {
                        if(received_coap_header->options_list_ptr->observe) {
                            if (is_observable()) {
                                uint32_t number = 0;
                                uint8_t observe_option = 0;
                                if(received_coap_header->options_list_ptr->observe_ptr) {
                                    observe_option = *received_coap_header->options_list_ptr->observe_ptr;
                                }
                                if(START_OBSERVATION == observe_option) {
                                    tr_debug("M2MResource::handle_get_request - Starts Observation");
                                    // If the observe length is 0 means register for observation.
                                    if(received_coap_header->options_list_ptr->observe_len != 0) {
                                        for(int i=0;i < received_coap_header->options_list_ptr->observe_len; i++) {
                                            number = (*(received_coap_header->options_list_ptr->observe_ptr + i) & 0xff) <<
                                                     8*(received_coap_header->options_list_ptr->observe_len- 1 - i);
                                            }
                                    }
                                    // If the observe value is 0 means register for observation.
                                    if(number == 0) {
                                        tr_debug("M2MResource::handle_get_request - Put Resource under Observation");
                                        M2MResourceInstanceList::const_iterator it;
                                        it = _resource_instance_list.begin();
                                        for (; it!=_resource_instance_list.end(); it++ ) {
                                            tr_debug("M2MResource::handle_get_request - set_resource_observer");
                                            (*it)->set_resource_observer(this);
                                            (*it)->add_observation_level(M2MBase::R_Attribute);
                                        }
                                        set_under_observation(true,observation_handler);
                                        M2MBase::add_observation_level(M2MBase::R_Attribute);
                                        coap_response->options_list_ptr->observe_ptr =
                                                m2m::String::convert_integer_to_array(observation_number(),
                                                      coap_response->options_list_ptr->observe_len);
                                    }
                                } else if (STOP_OBSERVATION == observe_option) {
                                    tr_debug("M2MResource::handle_get_request - Stops Observation");
                                    set_under_observation(false,NULL);
                                    M2MBase::remove_observation_level(M2MBase::R_Attribute);
                                    M2MResourceInstanceList::const_iterator it;
                                    it = _resource_instance_list.begin();
                                    for (; it!=_resource_instance_list.end(); it++ ) {
                                        (*it)->set_resource_observer(NULL);
                                    }
                                }
                                msg_code = COAP_MSG_CODE_RESPONSE_CONTENT;
                            }
                            else {
                                msg_code = COAP_MSG_CODE_RESPONSE_METHOD_NOT_ALLOWED;
                            }
                        }
                    }
                }
            } else {
                tr_error("M2MResource::handle_get_request - Return COAP_MSG_CODE_RESPONSE_METHOD_NOT_ALLOWED");
                // Operation is not allowed.
                msg_code = COAP_MSG_CODE_RESPONSE_METHOD_NOT_ALLOWED;
            }
        }
        if(coap_response) {
            coap_response->msg_code = msg_code;
        }
    } else {
        coap_response = M2MResourceInstance::handle_get_request(nsdl,
                            received_coap_header,
                            observation_handler);
    }
    return coap_response;
}
Beispiel #17
0
/*
 * set_viewer_proc - ビューア設定のプロシージャ
 */
BOOL CALLBACK set_viewer_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	TCHAR buf[BUF_SIZE];
	TCHAR tmp[BUF_SIZE];
	TCHAR *p, *r;
	int i;

	switch (uMsg) {
	case WM_INITDIALOG:
		CheckDlgButton(hDlg, IDC_CHECK_TOGGLE, option.viewer_toggle);
		CheckDlgButton(hDlg, IDC_CHECK_CLIP_EXPAND, option.tree_clip_expand);
		CheckDlgButton(hDlg, IDC_CHECK_HISTORY_EXPAND, option.tree_history_expand);
		CheckDlgButton(hDlg, IDC_CHECK_REGIST_EXPAND, option.tree_regist_expand);
		CheckDlgButton(hDlg, IDC_CHECK_FOLDER_EXPAND, option.tree_folder_expand);

		SendMessage(GetDlgItem(hDlg, IDC_LIST_FROM), LB_ADDSTRING, 0,
			(LPARAM)message_get_res(IDS_VIEWER_CLIPBOARD));
		SendMessage(GetDlgItem(hDlg, IDC_LIST_FROM), LB_ADDSTRING, 0,
			(LPARAM)message_get_res(IDS_VIEWER_HISTORY));
		SendMessage(GetDlgItem(hDlg, IDC_LIST_FROM), LB_ADDSTRING, 0,
			(LPARAM)message_get_res(IDS_VIEWER_REGIST));

		for (p = option.tree_root_order; *p != TEXT('\0'); p++) {
			switch (*p) {
			// クリップボード
			case TEXT('0'):
				r = message_get_res(IDS_VIEWER_CLIPBOARD);
				break;
			// 履歴
			case TEXT('1'):
				r = message_get_res(IDS_VIEWER_HISTORY);
				break;
			// 登録アイテム
			case TEXT('2'):
				r = message_get_res(IDS_VIEWER_REGIST);
				break;
			}
			if (SendMessage(GetDlgItem(hDlg, IDC_LIST_TO), LB_FINDSTRING, -1, (LPARAM)r) == -1) {
				SendMessage(GetDlgItem(hDlg, IDC_LIST_TO), LB_ADDSTRING, 0, (LPARAM)r);
			}
		}
		if (SendMessage(GetDlgItem(hDlg, IDC_LIST_TO), LB_GETCOUNT, 0, 0) <= 0) {
			SendMessage(GetDlgItem(hDlg, IDC_LIST_TO), LB_ADDSTRING, 0,
				(LPARAM)message_get_res(IDS_VIEWER_CLIPBOARD));
			SendMessage(GetDlgItem(hDlg, IDC_LIST_TO), LB_ADDSTRING, 0,
				(LPARAM)message_get_res(IDS_VIEWER_HISTORY));
			SendMessage(GetDlgItem(hDlg, IDC_LIST_TO), LB_ADDSTRING, 0,
				(LPARAM)message_get_res(IDS_VIEWER_REGIST));
		}

		switch (option.list_default_action) {
		case 0:
		default:
			CheckDlgButton(hDlg, IDC_RADIO_DEF_OPEN, 1);
			break;
		case 1:
			CheckDlgButton(hDlg, IDC_RADIO_DEF_CLIPBOARD, 1);
			break;
		case 2:
			CheckDlgButton(hDlg, IDC_RADIO_DEF_SAVE, 1);
			break;
		}
		break;

	case WM_NOTIFY:
		return OptionNotifyProc(hDlg, uMsg, wParam, lParam);

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDC_LIST_FROM:
			if (HIWORD(wParam) == LBN_DBLCLK) {
				SendMessage(hDlg, WM_COMMAND, IDC_BUTTON_ADD, 0);
			}
			break;

		case IDC_LIST_TO:
			if (HIWORD(wParam) == LBN_DBLCLK) {
				SendMessage(hDlg, WM_COMMAND, IDC_BUTTON_DELETE, 0);
			}
			break;

		case IDC_BUTTON_ADD:
			if ((i = SendMessage(GetDlgItem(hDlg, IDC_LIST_FROM), LB_GETCURSEL, 0, 0)) == -1) {
				break;
			}
			SendMessage(GetDlgItem(hDlg, IDC_LIST_FROM), LB_GETTEXT, i, (LPARAM)buf);

			if ((i = SendMessage(GetDlgItem(hDlg, IDC_LIST_TO), LB_FINDSTRING, -1, (LPARAM)buf)) != -1) {
				SendMessage(GetDlgItem(hDlg, IDC_LIST_TO), LB_DELETESTRING, i, 0);
			}
			SendMessage(GetDlgItem(hDlg, IDC_LIST_TO), LB_ADDSTRING, 0, (LPARAM)buf);
			break;

		case IDC_BUTTON_DELETE:
			if ((i = SendMessage(GetDlgItem(hDlg, IDC_LIST_TO), LB_GETCURSEL, 0, 0)) == -1) {
				break;
			}
			SendMessage(GetDlgItem(hDlg, IDC_LIST_TO), LB_DELETESTRING, i, 0);
			break;

		case IDOK:
			option.viewer_toggle = IsDlgButtonChecked(hDlg, IDC_CHECK_TOGGLE);
			option.tree_clip_expand = IsDlgButtonChecked(hDlg, IDC_CHECK_CLIP_EXPAND);
			option.tree_history_expand = IsDlgButtonChecked(hDlg, IDC_CHECK_HISTORY_EXPAND);
			option.tree_regist_expand = IsDlgButtonChecked(hDlg, IDC_CHECK_REGIST_EXPAND);
			option.tree_folder_expand = IsDlgButtonChecked(hDlg, IDC_CHECK_FOLDER_EXPAND);

			p = tmp;
			for (i = 0; i < SendMessage(GetDlgItem(hDlg, IDC_LIST_TO), LB_GETCOUNT, 0, 0); i++) {
				SendMessage(GetDlgItem(hDlg, IDC_LIST_TO), LB_GETTEXT, i, (LPARAM)buf);
				if (lstrcmp(buf, message_get_res(IDS_VIEWER_CLIPBOARD)) == 0) {
					*(p++) = TEXT('0');
				} else if (lstrcmp(buf, message_get_res(IDS_VIEWER_HISTORY)) == 0) {
					*(p++) = TEXT('1');
				} else if (lstrcmp(buf, message_get_res(IDS_VIEWER_REGIST)) == 0) {
					*(p++) = TEXT('2');
				}
			}
			*p = TEXT('\0');
			mem_free(&option.tree_root_order);
			option.tree_root_order = alloc_copy(tmp);

			if (IsDlgButtonChecked(hDlg, IDC_RADIO_DEF_CLIPBOARD) == 1) {
				option.list_default_action = 1;
			} else if (IsDlgButtonChecked(hDlg, IDC_RADIO_DEF_SAVE) == 1) {
				option.list_default_action = 2;
			} else {
				option.list_default_action = 0;
			}
			prop_ret = 1;
			break;

		case IDPCANCEL:
			break;
		}
		break;

	default:
		return FALSE;
	}
	return TRUE;
}
Beispiel #18
0
Pixmap& Pixmap::operator = (const Pixmap& p)
{
   alloc_copy(p.image+4, p.width(), p.height());
   return *this;
}
Beispiel #19
0
/*
 * select_tools_proc - ツール選択ウィンドウプロシージャ
 */
static BOOL CALLBACK select_tools_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	HWND pWnd;
	TOOL_INFO *ti;
	TCHAR buf[BUF_SIZE];
	static TCHAR lib_path[BUF_SIZE];
	int call_type;
	int i, j;
	static int old;

	switch (uMsg) {
	case WM_INITDIALOG:
		SetWindowText(hDlg, message_get_res(IDS_TOOL_SELECT_TITLE));
		SetWindowText(GetDlgItem(hDlg, IDC_STATIC_MSG), message_get_res(IDS_TOOL_SELECT_MSG));

		if (dll_to_list(hDlg, (TCHAR *)lParam, &old) == FALSE) {
			EndDialog(hDlg, FALSE);
			break;
		}
		// リストビューのスタイルの設定
		SetWindowLong(GetDlgItem(hDlg, IDC_LIST_HEADER), GWL_STYLE,
			GetWindowLong(GetDlgItem(hDlg, IDC_LIST_HEADER), GWL_STYLE) & ~LVS_SINGLESEL);

		lstrcpy(lib_path, (TCHAR *)lParam);

		EnableWindow(GetDlgItem(hDlg, IDOK), FALSE);
		break;

	case WM_CLOSE:
		EndDialog(hDlg, FALSE);
		break;

	case WM_NOTIFY:
		listview_notify_proc(hDlg, lParam, GetDlgItem(hDlg, IDC_LIST_HEADER));
		break;

	case WM_LV_EVENT:
		switch (wParam) {
		case LVN_ITEMCHANGED:
			if (ListView_GetSelectedCount(GetDlgItem(hDlg, IDC_LIST_HEADER)) <= 0) {
				EnableWindow(GetDlgItem(hDlg, IDOK), FALSE);
			} else {
				EnableWindow(GetDlgItem(hDlg, IDOK), TRUE);
			}
			break;
		}
		break;

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDCANCEL:
			SendMessage(hDlg, WM_CLOSE, 0, 0);
			break;

		case IDC_BUTTON_EDIT:
		case IDOK:
			pWnd = PropSheet_GetCurrentPageHwnd(GetParent(hDlg));

			i = -1;
			while ((i = ListView_GetNextItem(GetDlgItem(hDlg, IDC_LIST_HEADER), i, LVNI_SELECTED)) != -1) {
				if ((ti = mem_calloc(sizeof(TOOL_INFO))) != NULL) {
					// 設定取得
					ti->lib_file_path = alloc_copy(lib_path);

					ListView_GetItemText(GetDlgItem(hDlg, IDC_LIST_HEADER), i, 0, buf, BUF_SIZE - 1);
					ti->title = alloc_copy(buf);
					ListView_GetItemText(GetDlgItem(hDlg, IDC_LIST_HEADER), i, 1, buf, BUF_SIZE - 1);
					ti->func_name = alloc_copy(buf);
					ListView_GetItemText(GetDlgItem(hDlg, IDC_LIST_HEADER), i, 2, buf, BUF_SIZE - 1);
					ti->cmd_line = alloc_copy(buf);

					call_type = listview_get_lparam(GetDlgItem(hDlg, IDC_LIST_HEADER), i);
					if (old == 1) {
						j = CALLTYPE_VIEWER;
						if (!(call_type & OLD_CALLTYPE_MENU)) {
							j |= CALLTYPE_MENU;
							ti->copy_paste = 1;
						}
						if (call_type & OLD_CALLTYPE_ADD_HISTORY) {
							j |= CALLTYPE_ADD_HISTORY;
						}
						if (call_type & OLD_CALLTYPE_ITEM_TO_CLIPBOARD) {
							j |= CALLTYPE_ITEM_TO_CLIPBOARD;
						}
						if (call_type & OLD_CALLTYPE_START) {
							j |= CALLTYPE_START;
						}
						if (call_type & OLD_CALLTYPE_END) {
							j |= CALLTYPE_END;
						}
						ti->call_type = j;
					} else {
						ti->copy_paste = (call_type & CALLTYPE_MENU_COPY_PASTE) ? 1 : 0;
						ti->call_type = call_type & ~CALLTYPE_MENU_COPY_PASTE;
					}
					ti->old = old;

					// 新規追加
					listview_set_tool(GetDlgItem(pWnd, IDC_LIST_TOOL), ti, FALSE);
				}
			}
			EndDialog(hDlg, TRUE);
			break;
		}
		break;

	case WM_GET_VERSION:
		// バージョン取得
		return APP_VAR;

	case WM_GET_WORKPATH:
		// 作業ディレクトリ取得
		if (lParam == 0) {
			break;
		}
		lstrcpy((TCHAR *)lParam, work_path);
		break;

	default:
		return FALSE;
	}
	return TRUE;
}
Beispiel #20
0
/*
 * menu_create_info - メニュー情報の作成
 */
static MENU_ITEM_INFO *menu_create_info(MENU_INFO *menu_info, const int menu_cnt,
										DATA_INFO *history_di, DATA_INFO *regist_di,
										int *id, int *ret_cnt)
{
	MENU_ITEM_INFO *mii;
	DATA_INFO *di;
	int i, j, t;
	int cnt;

	// メニュー項目数の取得
	for (i = 0, *ret_cnt = 0; i < menu_cnt; i++) {
		switch ((menu_info + i)->content) {
		case MENU_CONTENT_SEPARATOR:
		case MENU_CONTENT_POPUP:
		case MENU_CONTENT_VIEWER:
		case MENU_CONTENT_OPTION:
		case MENU_CONTENT_CLIPBOARD_WATCH:
		case MENU_CONTENT_APP:
		case MENU_CONTENT_CANCEL:
		case MENU_CONTENT_EXIT:
			(*ret_cnt)++;
			break;

		case MENU_CONTENT_HISTORY:
		case MENU_CONTENT_HISTORY_DESC:
			for (di = history_di, cnt = 0; di != NULL &&
				(menu_info + i)->min > 0 && cnt < (menu_info + i)->min - 1; di = di->next, cnt++);
			for (; di != NULL &&
				((menu_info + i)->max <= 0 || cnt < (menu_info + i)->max); di = di->next, (*ret_cnt)++, cnt++);
			break;

		case MENU_CONTENT_REGIST:
		case MENU_CONTENT_REGIST_DESC:
			di = regist_path_to_item(regist_di, (menu_info + i)->path);
			for (; di != NULL; di = di->next, (*ret_cnt)++)
				;
			break;

		case MENU_CONTENT_TOOL:
			if ((menu_info + i)->path != NULL && *(menu_info + i)->path != TEXT('\0')) {
				if (tool_title_to_index((menu_info + i)->path) != -1) {
					(*ret_cnt)++;
				}
			} else {
				for (t = 0; t < option.tool_cnt; t++) {
					if ((option.tool_info + t)->call_type & CALLTYPE_MENU) {
						(*ret_cnt)++;
					}
				}
			}
			break;
		}
	}

	// メニュー項目情報の確保
	if ((mii = mem_calloc(sizeof(MENU_ITEM_INFO) * (*ret_cnt))) == NULL) {
		*ret_cnt = 0;
		return NULL;
	}

	// メニュー項目情報の作成
	for (i = 0, j = 0; i < menu_cnt; i++) {
		switch ((menu_info + i)->content) {
		case MENU_CONTENT_SEPARATOR:
			// 区切り
			(mii + j)->id = 0;
			(mii + j)->flag = MF_SEPARATOR | MF_OWNERDRAW;
			(mii + j)->item = (LPCTSTR)(mii + j);
			j++;
			break;

		case MENU_CONTENT_HISTORY:
			// 履歴 (昇順)
			if (menu_create_datainfo(history_di, mii, j, id, 1, (menu_info + i)->min, (menu_info + i)->max) == TRUE) {
				for (di = history_di, cnt = 0; di != NULL &&
					(menu_info + i)->min > 0 && cnt < (menu_info + i)->min - 1; di = di->next, cnt++);
				for (; di != NULL &&
					((menu_info + i)->max <= 0 || cnt < (menu_info + i)->max); di = di->next, j++, cnt++);
			}
			break;

		case MENU_CONTENT_HISTORY_DESC:
			// 履歴 (降順)
			if (menu_create_datainfo(history_di, mii, j, id, -1, (menu_info + i)->min, (menu_info + i)->max) == TRUE) {
				for (di = history_di, cnt = 0; di != NULL &&
					(menu_info + i)->min > 0 && cnt < (menu_info + i)->min - 1; di = di->next, cnt++)
					;
				for (; di != NULL &&
					((menu_info + i)->max <= 0 || cnt < (menu_info + i)->max); di = di->next, j++, cnt++)
					;
			}
			break;

		case MENU_CONTENT_REGIST:
			// 登録アイテム (昇順)
			di = regist_path_to_item(regist_di, (menu_info + i)->path);
			if (di != NULL && menu_create_datainfo(di, mii, j, id, 1, 0, 0) == TRUE) {
				for (; di != NULL; di = di->next, j++)
					;
			}
			break;

		case MENU_CONTENT_REGIST_DESC:
			// 登録アイテム (降順)
			di = regist_path_to_item(regist_di, (menu_info + i)->path);
			if (di != NULL && menu_create_datainfo(di, mii, j, id, -1, 0, 0) == TRUE) {
				for (; di != NULL; di = di->next, j++)
					;
			}
			break;

		case MENU_CONTENT_POPUP:
			// ポップアップメニュー
			(mii + j)->flag = MF_POPUP | MF_OWNERDRAW;
			(mii + j)->item = (LPCTSTR)(mii + j);
			(mii + j)->text = alloc_copy((menu_info + i)->title);
			(mii + j)->icon = menu_read_icon((menu_info + i)->icon_path, (menu_info + i)->icon_index, option.menu_icon_size);
			(mii + j)->free_icon = TRUE;
			(mii + j)->mii = menu_create_info(
				(menu_info + i)->mi, (menu_info + i)->mi_cnt,
				history_di, regist_di, id, &(mii + j)->mii_cnt);
			j++;
			break;

		case MENU_CONTENT_VIEWER:
			// ビューア
			(mii + j)->id = ID_MENUITEM_VIEWER;
			(mii + j)->flag = MF_OWNERDRAW;
			(mii + j)->item = (LPCTSTR)(mii + j);
			(mii + j)->text = alloc_copy(((menu_info + i)->title == NULL || *(menu_info + i)->title == TEXT('\0')) ?
				message_get_res(IDS_MENU_VIEWER) : (menu_info + i)->title);
			(mii + j)->icon = menu_read_icon((menu_info + i)->icon_path, (menu_info + i)->icon_index, option.menu_icon_size);
			(mii + j)->free_icon = TRUE;
			j++;
			break;

		case MENU_CONTENT_OPTION:
			// オプション
			(mii + j)->id = ID_MENUITEM_OPTION;
			(mii + j)->flag = MF_OWNERDRAW;
			(mii + j)->item = (LPCTSTR)(mii + j);
			(mii + j)->text = alloc_copy(((menu_info + i)->title == NULL || *(menu_info + i)->title == TEXT('\0')) ?
				message_get_res(IDS_MENU_OPTION) : (menu_info + i)->title);
			(mii + j)->icon = menu_read_icon((menu_info + i)->icon_path, (menu_info + i)->icon_index, option.menu_icon_size);
			(mii + j)->free_icon = TRUE;
			j++;
			break;

		case MENU_CONTENT_CLIPBOARD_WATCH:
			// クリップボード監視切り替え
			(mii + j)->id = ID_MENUITEM_CLIPBOARD_WATCH;
			(mii + j)->flag = MF_OWNERDRAW | ((option.main_clipboard_watch == 1) ? MF_CHECKED : 0);
			(mii + j)->item = (LPCTSTR)(mii + j);
			(mii + j)->text = alloc_copy(((menu_info + i)->title == NULL || *(menu_info + i)->title == TEXT('\0')) ?
				message_get_res(IDS_MENU_CLIPBOARD_WATCH) : (menu_info + i)->title);
			(mii + j)->icon = menu_read_icon((menu_info + i)->icon_path, (menu_info + i)->icon_index, option.menu_icon_size);
			(mii + j)->free_icon = TRUE;
			j++;
			break;

		case MENU_CONTENT_TOOL:
			// ツール
			if ((menu_info + i)->path != NULL && *(menu_info + i)->path != TEXT('\0')) {
				if ((t = tool_title_to_index((menu_info + i)->path)) != -1) {
					(mii + j)->id = ID_MENUITEM_DATA + ((*id)++);
					(mii + j)->flag = MF_OWNERDRAW;
					(mii + j)->item = (LPCTSTR)(mii + j);
					if ((menu_info + i)->title != NULL && *(menu_info + i)->title != TEXT('\0')) {
						(mii + j)->text = alloc_copy((menu_info + i)->title);
					} else {
						(mii + j)->text = alloc_copy((option.tool_info + t)->title);
					}
					if (option.menu_show_hotkey == 1) {
						(mii + j)->hkey = menu_get_keyname((option.tool_info + t)->modifiers, (option.tool_info + t)->virtkey);
					}
					(mii + j)->icon = menu_read_icon((menu_info + i)->icon_path, (menu_info + i)->icon_index, option.menu_icon_size);
					(mii + j)->free_icon = TRUE;
					(mii + j)->ti = option.tool_info + t;
					j++;
				}
			} else {
				for (t = 0; t < option.tool_cnt; t++) {
					if (!((option.tool_info + t)->call_type & CALLTYPE_MENU)) {
						continue;
					}
					if (lstrcmp((option.tool_info + t)->title, TEXT("-")) == 0) {
						(mii + j)->id = 0;
						(mii + j)->flag = MF_SEPARATOR | MF_OWNERDRAW;
						(mii + j)->item = (LPCTSTR)(mii + j);
					} else {
						(mii + j)->id = ID_MENUITEM_DATA + ((*id)++);
						(mii + j)->flag = MF_OWNERDRAW;
						(mii + j)->item = (LPCTSTR)(mii + j);
						(mii + j)->text = alloc_copy((option.tool_info + t)->title);
						if (option.menu_show_hotkey == 1) {
							(mii + j)->hkey = menu_get_keyname((option.tool_info + t)->modifiers, (option.tool_info + t)->virtkey);
						}
						(mii + j)->ti = option.tool_info + t;
					}
					j++;
				}
			}
			break;

		case MENU_CONTENT_APP:
			// アプリケーション実行
			(mii + j)->id = ID_MENUITEM_DATA + ((*id)++);
			(mii + j)->flag = MF_OWNERDRAW;
			(mii + j)->item = (LPCTSTR)(mii + j);
			(mii + j)->text = alloc_copy((menu_info + i)->title);
			if (*(menu_info + i)->icon_path != TEXT('\0')) {
				(mii + j)->icon = menu_read_icon((menu_info + i)->icon_path, (menu_info + i)->icon_index, option.menu_icon_size);
			} else {
				(mii + j)->icon = menu_read_icon((menu_info + i)->path, 0, option.menu_icon_size);
			}
			(mii + j)->free_icon = TRUE;
			// メニュー情報を設定
			(mii + j)->mi = menu_info + i;
			j++;
			break;

		case MENU_CONTENT_CANCEL:
			// キャンセル
			(mii + j)->id = IDCANCEL;
			(mii + j)->flag = MF_OWNERDRAW;
			(mii + j)->item = (LPCTSTR)(mii + j);
			(mii + j)->text = alloc_copy(((menu_info + i)->title == NULL || *(menu_info + i)->title == TEXT('\0')) ?
				message_get_res(IDS_MENU_CANCEL) : (menu_info + i)->title);
			(mii + j)->icon = menu_read_icon((menu_info + i)->icon_path, (menu_info + i)->icon_index, option.menu_icon_size);
			(mii + j)->free_icon = TRUE;
			j++;
			break;

		case MENU_CONTENT_EXIT:
			// 終了
			(mii + j)->id = ID_MENUITEM_EXIT;
			(mii + j)->flag = MF_OWNERDRAW;
			(mii + j)->item = (LPCTSTR)(mii + j);
			(mii + j)->text = alloc_copy(((menu_info + i)->title == NULL || *(menu_info + i)->title == TEXT('\0')) ?
				message_get_res(IDS_MENU_EXIT) : (menu_info + i)->title);
			(mii + j)->icon = menu_read_icon((menu_info + i)->icon_path, (menu_info + i)->icon_index, option.menu_icon_size);
			(mii + j)->free_icon = TRUE;
			j++;
			break;
		}
	}
	return mii;
}
Beispiel #21
0
/*
 * menu_create_datainfo - メニュー情報にデータを展開
 */
static BOOL menu_create_datainfo(DATA_INFO *set_di,
								MENU_ITEM_INFO *mii, int menu_index, int *id,
								const int step, const int min, const int max)
{
	DATA_INFO *di;
	DATA_INFO *cdi;
	MENU_ITEM_INFO *cmi;
	TCHAR buf[BUF_SIZE * 2];
	TCHAR tmp[BUF_SIZE];
	TCHAR *p;
	int cnt;
	int i, j;
	int m, n;

	// 初期位置移動
	for (m = 0; set_di != NULL && min > 0 && m < min - 1; set_di = set_di->next, m++)
		;
	if (step < 0) {
		// 降順
		for (di = set_di, i = 0, n = m; di != NULL && (max <= 0 || n < max); di = di->next, i++, n++)
			;
		i += menu_index - 1;
	} else {
		// 昇順
		i = menu_index;
	}

	for (di = set_di,j = 0; di != NULL && (max <= 0 || m < max); di = di->next, i += step, m++) {
		(mii + i)->id = ID_MENUITEM_DATA + ((*id)++);
		(mii + i)->item = (LPCTSTR)(mii + i);
		(mii + i)->set_di = di;

		switch (di->type) {
		case TYPE_FOLDER:
			// 階層表示
			(mii + i)->flag = MF_POPUP | MF_OWNERDRAW;
			(mii + i)->show_di = di;

			for (cdi = di->child, cnt = 0; cdi != NULL; cdi = cdi->next, cnt++)
				;
			// メニュー項目情報の確保
			if ((cmi = mem_calloc(sizeof(MENU_ITEM_INFO) * cnt)) == NULL) {
				return FALSE;
			}
			(mii + i)->mii = cmi;
			(mii + i)->mii_cnt = cnt;
			menu_create_datainfo(di->child, cmi, 0, id, step, 0, 0);
			break;

		case TYPE_ITEM:
			// アイテム
			(mii + i)->flag = MF_OWNERDRAW;
			(mii + i)->show_di = format_get_priority_highest(di);
			break;

		case TYPE_DATA:
			// データ
			(mii + i)->flag = MF_OWNERDRAW;
			(mii + i)->show_di = di;
			break;
		}

		// メニューに表示するタイトルを取得
		format_get_menu_title((mii + i)->show_di);
		// タイトルを設定
		if (di->title != NULL) {
			if (lstrcmp(di->title, TEXT("-")) == 0) {
				// 区切り
				(mii + i)->id = 0;
				(mii + i)->flag = MF_SEPARATOR | MF_OWNERDRAW;
				(mii + i)->item = (LPCTSTR)(mii + i);
				continue;
			} else if (option.menu_intact_item_title == 0) {
				menu_create_text(j++, di->title, buf);
				(mii + i)->text = alloc_copy(buf);
			} else {
				(mii + i)->text = alloc_copy(di->title);
			}

		} else if ((mii + i)->show_di->menu_title != NULL) {
			menu_create_text(j++, (mii + i)->show_di->menu_title, buf);
			(mii + i)->text = alloc_copy(buf);

		} else if ((mii + i)->show_di->format_name != NULL) {
			// 形式名
			p = tmp;
			*(p++) = TEXT('(');
			lstrcpyn(p, (mii + i)->show_di->format_name, BUF_SIZE - 3);
			p += lstrlen(p);
			*(p++) = TEXT(')');
			*(p++) = TEXT('\0');
			menu_create_text(j++, tmp, buf);
			(mii + i)->text = alloc_copy(buf);
			(mii + i)->show_format = TRUE;

		} else {
			(mii + i)->text = alloc_copy(TEXT(""));
		}

		if (option.menu_show_hotkey == 1) {
			// ホットキー取得
			(mii + i)->hkey = menu_get_keyname(di->op_modifiers, di->op_virtkey);
		}

		if (option.menu_show_icon == 1) {
			// メニューに表示するアイコンを取得
			format_get_menu_icon((mii + i)->show_di);
			if ((mii + i)->show_di->menu_icon == NULL) {
				(mii + i)->icon = (di->type == TYPE_FOLDER) ? icon_menu_folder : icon_menu_default;
			} else {
				(mii + i)->icon = (mii + i)->show_di->menu_icon;
			}
			(mii + i)->free_icon = FALSE;

			// メニューに表示するビットマップを取得
			if (option.menu_show_bitmap == 1) {
				format_get_menu_bitmap((mii + i)->show_di);
			}
			(mii + i)->show_bitmap = (option.menu_show_bitmap == 1 &&
				(mii + i)->show_di->menu_bitmap != NULL) ? TRUE : FALSE;
		}
	}
	return TRUE;
}
Beispiel #22
0
sn_coap_hdr_s* M2MObject::handle_post_request(nsdl_s *nsdl,
                                              sn_coap_hdr_s *received_coap_header,
                                              M2MObservationHandler *observation_handler,
                                              bool &execute_value_updated)
{
    tr_debug("M2MObject::handle_post_request()");    
    sn_coap_msg_code_e msg_code = COAP_MSG_CODE_RESPONSE_CHANGED; // 2.04
    // process the POST if we have registered a callback for it    
    sn_coap_hdr_s *coap_response = sn_nsdl_build_response(nsdl,
                                      received_coap_header,
                                      msg_code);

    if(received_coap_header) {
        if ((operation() & SN_GRS_POST_ALLOWED) != 0) {
            if(received_coap_header->payload_ptr) {
                tr_debug("M2MObject::handle_post_request() - Update Object with new values");
                uint16_t coap_content_type = 0;
                bool content_type_present = false;
                if(received_coap_header->content_type_ptr) {
                    content_type_present = true;
                    if(coap_response) {
                        coap_response->content_type_ptr = (uint8_t*)alloc_copy(received_coap_header->content_type_ptr,
                                                                                received_coap_header->content_type_len);
                        if(coap_response->content_type_ptr) {
                            coap_response->content_type_len = received_coap_header->content_type_len;
                            for(uint8_t i = 0; i < coap_response->content_type_len; i++) {
                                coap_content_type = (coap_content_type << 8) +
                                        (coap_response->content_type_ptr[i] & 0xFF);
                            }
                        }
                    }
                } // if(received_coap_header->content_type_ptr)
                if(!content_type_present &&
                   M2MBase::coap_content_type() == COAP_CONTENT_OMA_TLV_TYPE) {
                    coap_content_type = COAP_CONTENT_OMA_TLV_TYPE;
                }

                tr_debug("M2MObject::handle_post_request() - Request Content-Type %d", coap_content_type);

                if(COAP_CONTENT_OMA_TLV_TYPE == coap_content_type) {
                    uint16_t instance_id = 0;
                    // Check next free instance id
                    for(instance_id = 0; instance_id <= _max_instance_count; instance_id++) {
                        if(NULL == object_instance(instance_id)) {
                            break;
                        }
                        if(instance_id == _max_instance_count) {
                            msg_code = COAP_MSG_CODE_RESPONSE_METHOD_NOT_ALLOWED;
                            break;
                        }
                    }
                    if(COAP_MSG_CODE_RESPONSE_CHANGED == msg_code) {
                        M2MTLVDeserializer *deserializer = new M2MTLVDeserializer();
                        bool is_obj_instance = false;
                        bool obj_instance_exists = false;
                        if (deserializer) {
                            is_obj_instance = deserializer->is_object_instance(received_coap_header->payload_ptr);
                            if (is_obj_instance) {
                                instance_id = deserializer->instance_id(received_coap_header->payload_ptr);
                                tr_debug("M2MObject::handle_post_request() - instance id in TLV: %d", instance_id);
                                // Check if instance id already exists
                                if (object_instance(instance_id)){
                                    obj_instance_exists = true;
                                }
                            }
                        }
                        if (!obj_instance_exists) {
                            M2MObjectInstance *obj_instance = create_object_instance(instance_id);
                            if(obj_instance) {
                                obj_instance->set_operation(M2MBase::GET_PUT_ALLOWED);
                            }

                            if(deserializer) {
                                String obj_name = "";
                                M2MTLVDeserializer::Error error = M2MTLVDeserializer::None;
                                if(is_obj_instance) {
                                    tr_debug("M2MObject::handle_post_request() - TLV data contains ObjectInstance");
                                    error = deserializer->deserialise_object_instances(received_coap_header->payload_ptr,
                                                                               received_coap_header->payload_len,
                                                                               *this,
                                                                               M2MTLVDeserializer::Post);
                                } else if(deserializer->is_resource(received_coap_header->payload_ptr) ||
                                          deserializer->is_multiple_resource(received_coap_header->payload_ptr)) {
                                    tr_debug("M2MObject::handle_post_request() - TLV data contains Resources");
                                    error = deserializer->deserialize_resources(received_coap_header->payload_ptr,
                                                                                received_coap_header->payload_len,
                                                                                *obj_instance,
                                                                                M2MTLVDeserializer::Post);
                                } else {
                                    error = M2MTLVDeserializer::NotValid;
                                }
                                switch(error) {
                                    case M2MTLVDeserializer::None:
                                        if(observation_handler) {
                                            execute_value_updated = true;
                                        }
                                        coap_response->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s));
                                        if (coap_response->options_list_ptr) {
                                            memset(coap_response->options_list_ptr, 0, sizeof(sn_coap_options_list_s));

                                            obj_name = M2MBase::name();
                                            obj_name.push_back('/');
                                            obj_name.append_int(instance_id);

                                            coap_response->options_list_ptr->location_path_len = obj_name.length();
                                            if (coap_response->options_list_ptr->location_path_len != 0) {
                                                coap_response->options_list_ptr->location_path_ptr =
                                                        (uint8_t*)malloc(coap_response->options_list_ptr->location_path_len);
                                                if (coap_response->options_list_ptr->location_path_ptr) {
                                                    memcpy(coap_response->options_list_ptr->location_path_ptr,
                                                           obj_name.c_str(),
                                                           coap_response->options_list_ptr->location_path_len);
                                                }
                                            }
                                        }
                                        msg_code = COAP_MSG_CODE_RESPONSE_CREATED;
                                        break;
                                    case M2MTLVDeserializer::NotAllowed:
                                        msg_code = COAP_MSG_CODE_RESPONSE_METHOD_NOT_ALLOWED;
                                        break;
                                    case M2MTLVDeserializer::NotValid:
                                        msg_code = COAP_MSG_CODE_RESPONSE_BAD_REQUEST;
                                        break;
                                    case M2MTLVDeserializer::NotFound:
                                        msg_code = COAP_MSG_CODE_RESPONSE_NOT_FOUND;
                                        break;
                                }                                
                            }
                        } else {
                            tr_debug("M2MObject::handle_post_request() - COAP_MSG_CODE_RESPONSE_BAD_REQUEST");
                            msg_code = COAP_MSG_CODE_RESPONSE_BAD_REQUEST;
                        }
                        delete deserializer;
                    }
                } else {
                    msg_code =COAP_MSG_CODE_RESPONSE_UNSUPPORTED_CONTENT_FORMAT;
                } // if(COAP_CONTENT_OMA_TLV_TYPE == coap_content_type)
            } else {
                tr_error("M2MObject::handle_post_request - COAP_MSG_CODE_RESPONSE_BAD_REQUEST - Missing Payload");
                msg_code = COAP_MSG_CODE_RESPONSE_BAD_REQUEST; //
            }
        } else { // if ((object->operation() & SN_GRS_POST_ALLOWED) != 0)
            tr_error("M2MObject::handle_post_request - COAP_MSG_CODE_RESPONSE_METHOD_NOT_ALLOWED");
            msg_code = COAP_MSG_CODE_RESPONSE_METHOD_NOT_ALLOWED; // 4.05
        }
    } else { //if(received_coap_header)
        tr_error("M2MObject::handle_post_request - COAP_MSG_CODE_RESPONSE_METHOD_NOT_ALLOWED");
        msg_code = COAP_MSG_CODE_RESPONSE_METHOD_NOT_ALLOWED; // 4.05
    }

    if(coap_response) {
        coap_response->msg_code = msg_code;
    }
    return coap_response;
}
Beispiel #23
0
 void copyTo(Other& o){
         assert(o.nsys() == Base::nsys() && o.nbod() == Base::nbod());
         alloc_copy(BodyAllocator(),typename Other::BodyAllocator(),Base::bodies().begin(),Base::bodies().end(),o.bodies().begin());
         alloc_copy(SysAllocator(),typename Other::SysAllocator(),Base::systems().begin(),Base::systems().end(),o.systems().begin());
 }
Beispiel #24
0
/*
 * tooltip_proc - ツールチップ
 */
static LRESULT CALLBACK tooltip_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	NONCLIENTMETRICS ncMetrics;
	PAINTSTRUCT ps;
	DRAWTEXTPARAMS dtp;
	RECT rect;
	POINT pt;
	HDC hdc;
	HFONT hRetFont;
	TOOLTIP_INFO *ti;

	switch (msg) {
	case WM_CREATE:
		if ((ti = mem_calloc(sizeof(TOOLTIP_INFO))) == NULL) {
			return -1;
		}
		if (*option.tooltip_font_name != TEXT('\0')) {
			// フォント作成
			ti->hfont = font_create(option.tooltip_font_name,
				option.tooltip_font_size, option.tooltip_font_charset, option.tooltip_font_weight,
				(option.tooltip_font_italic == 0) ? FALSE : TRUE, FALSE);
		} else {
			ncMetrics.cbSize = sizeof(NONCLIENTMETRICS);
			if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
				sizeof(NONCLIENTMETRICS), &ncMetrics, 0) == TRUE) {
				// デフォルトのフォント作成
				ti->hfont = CreateFontIndirect(&ncMetrics.lfStatusFont);
			}
		}
		// tooltip info to window long
		SetWindowLong(hWnd, GWL_USERDATA, (LPARAM)ti);
		break;

	case WM_CLOSE:
		DestroyWindow(hWnd);
		break;

	case WM_DESTROY:
		if ((ti = (TOOLTIP_INFO *)GetWindowLong(hWnd, GWL_USERDATA)) != NULL) {
			if (ti->hfont != NULL) {
				DeleteObject(ti->hfont);
				ti->hfont = NULL;
			}
			if (ti->buf != NULL) {
				mem_free(&ti->buf);
			}
			mem_free(&ti);
		}
		return DefWindowProc(hWnd, msg, wParam, lParam);

	case WM_SETTINGCHANGE:
		if ((ti = (TOOLTIP_INFO *)GetWindowLong(hWnd, GWL_USERDATA)) == NULL ||
			*option.tooltip_font_name != TEXT('\0') ||
			wParam != SPI_SETNONCLIENTMETRICS) {
			break;
		}
		if (ti->hfont != NULL) {
			DeleteObject(ti->hfont);
			ti->hfont = NULL;
		}
		ncMetrics.cbSize = sizeof(NONCLIENTMETRICS);
		if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
			sizeof(NONCLIENTMETRICS), &ncMetrics, 0) == TRUE) {
			// デフォルトのフォント作成
			ti->hfont = CreateFontIndirect(&ncMetrics.lfStatusFont);
		}
		break;

#ifdef TOOLTIP_ANIMATE
	case WM_PRINT:
		// テキスト描画
		if ((ti = (TOOLTIP_INFO *)GetWindowLong(hWnd, GWL_USERDATA)) == NULL) {
			break;
		}
		// 非クライアントエリアの描画
		DefWindowProc(hWnd, msg, wParam, lParam);

		// ツールチップの描画
		GetClientRect(hWnd, (LPRECT)&rect);
		SetRect(&rect, rect.left + 1, rect.top + 1, rect.right + 1, rect.bottom + 1);
		tooltip_draw_text(ti, (HDC)wParam, &rect);
		break;
#endif

	case WM_PAINT:
		// テキスト描画
		if ((ti = (TOOLTIP_INFO *)GetWindowLong(hWnd, GWL_USERDATA)) == NULL) {
			break;
		}
		hdc = BeginPaint(hWnd, &ps);

		// ツールチップの描画
		GetClientRect(hWnd, (LPRECT)&rect);
		tooltip_draw_text(ti, hdc, &rect);

		EndPaint(hWnd, &ps);
		break;

	case WM_MOUSEMOVE:
	case WM_LBUTTONDOWN:
	case WM_MBUTTONDOWN:
	case WM_RBUTTONDOWN:
	case WM_SETCURSOR:
	case WM_TOOLTIP_HIDE:
		// ツールチップ非表示
		KillTimer(hWnd, ID_SHOW_TIMER);
		KillTimer(hWnd, ID_MOUSE_TIMER);
		ShowWindow(hWnd, SW_HIDE);

		if ((ti = (TOOLTIP_INFO *)GetWindowLong(hWnd, GWL_USERDATA)) != NULL && ti->buf != NULL) {
			mem_free(&ti->buf);
		}
		break;

	case WM_TOOLTIP_SHOW:
		// ツールチップ表示
		KillTimer(hWnd, ID_SHOW_TIMER);
		KillTimer(hWnd, ID_MOUSE_TIMER);
		ShowWindow(hWnd, SW_HIDE);
		if (lParam == 0 ||
			((TOOLTIP_INFO *)lParam)->buf == NULL || *((TOOLTIP_INFO *)lParam)->buf == TEXT('\0')) {
			break;
		}
		if ((ti = (TOOLTIP_INFO *)GetWindowLong(hWnd, GWL_USERDATA)) == NULL) {
			break;
		}

		// 座標設定
		ti->top = ((TOOLTIP_INFO *)lParam)->top;
		ti->pt.x = ((TOOLTIP_INFO *)lParam)->pt.x;
		ti->pt.y = ((TOOLTIP_INFO *)lParam)->pt.y;

		// ウィンドウ取得
		if (ti->pt.x == 0 && ti->pt.y == 0) {
			GetCursorPos(&pt);
			ti->hWnd = WindowFromPoint(pt);
		} else {
			ti->hWnd = NULL;
		}

		// テキスト設定
		if (ti->buf != NULL) {
			mem_free(&ti->buf);
		}
		ti->buf = alloc_copy(((TOOLTIP_INFO *)lParam)->buf);

		// ツールチップ表示
		SetTimer(hWnd, ID_SHOW_TIMER, wParam, NULL);
		break;

	case WM_TIMER:
		switch (wParam) {
		case ID_SHOW_TIMER:
			KillTimer(hWnd, wParam);
			if ((ti = (TOOLTIP_INFO *)GetWindowLong(hWnd, GWL_USERDATA)) == NULL || ti->buf == NULL) {
				SendMessage(hWnd, WM_TOOLTIP_HIDE, 0, 0);
				break;
			}

			// 表示位置取得 (マウス位置)
			if (ti->pt.x == 0 && ti->pt.y == 0) {
				GetCursorPos(&ti->pt);
				ti->top = tooltip_get_cursor_height(GetCursor()) + 1;
				if (ti->hWnd != WindowFromPoint(ti->pt)) {
					SendMessage(hWnd, WM_TOOLTIP_HIDE, 0, 0);
					break;
				}
			}

			// サイズ取得
			hdc = GetDC(hWnd);
			hRetFont = SelectObject(hdc, (ti->hfont != NULL) ? ti->hfont : GetStockObject(DEFAULT_GUI_FONT));
			SetRectEmpty(&rect);

			ZeroMemory(&dtp, sizeof(DRAWTEXTPARAMS));
			dtp.cbSize = sizeof(DRAWTEXTPARAMS);
			dtp.iTabLength = option.tooltip_tab_length;
			DrawTextEx(hdc, ti->buf, lstrlen(ti->buf), &rect,
				DT_CALCRECT | DT_EDITCONTROL | DT_NOCLIP | DT_EXPANDTABS | DT_TABSTOP | DT_NOPREFIX, &dtp);

			SelectObject(hdc, hRetFont);
			ReleaseDC(hWnd, hdc);

			// ウィンドウサイズ設定
			SetRect(&rect,
				ti->pt.x,
				ti->pt.y + ti->top,
				rect.right + (option.tooltip_margin_x * 2) + 2,
				rect.bottom + (option.tooltip_margin_y * 2) + 2);

			// 横位置の補正
			if (rect.left + rect.right > GetSystemMetrics(SM_CXSCREEN)) {
				rect.left = GetSystemMetrics(SM_CXSCREEN) - rect.right;
			}
			if (rect.left < 0) {
				rect.left = 0;
			}

			// 縦位置の補正
			if (rect.top + rect.bottom > GetSystemMetrics(SM_CYSCREEN)) {
				rect.top = ti->pt.y - rect.bottom;
			}
			if (rect.top < 0) {
				rect.top = GetSystemMetrics(SM_CYSCREEN) - rect.bottom;
			}
			if (rect.top < 0) {
				rect.top = 0;
			}

			// ウィンドウの位置とサイズを設定
			SetWindowPos(hWnd, HWND_TOPMOST,
				rect.left, rect.top, rect.right, rect.bottom,
				SWP_NOACTIVATE);

#ifdef TOOLTIP_ANIMATE
			{
				HANDLE user32_lib;
				FARPROC AnimateWindow;
				BOOL effect_flag;

				// ウィンドウ表示
				SystemParametersInfo(SPI_GETTOOLTIPANIMATION, 0, &effect_flag, 0);
				if (effect_flag == TRUE) {
					SystemParametersInfo(SPI_GETTOOLTIPFADE, 0, &effect_flag, 0);
					user32_lib = LoadLibrary(TEXT("user32.dll"));
					if (user32_lib != NULL) {
						AnimateWindow = GetProcAddress(user32_lib, "AnimateWindow");
						if (AnimateWindow != NULL) {
							// アニメーション表示
							AnimateWindow(hWnd, 200, (effect_flag == TRUE) ? AW_BLEND : (AW_SLIDE | AW_VER_POSITIVE));
						}
						FreeLibrary(user32_lib);
					}
				}
			}
#endif
			ShowWindow(hWnd, SW_SHOWNOACTIVATE);
			SetTimer(hWnd, ID_MOUSE_TIMER, MOUSE_INTERVAL, NULL);
			break;

		case ID_MOUSE_TIMER:
			if ((ti = (TOOLTIP_INFO *)GetWindowLong(hWnd, GWL_USERDATA)) == NULL ||
				ti->hWnd == NULL || IsWindowVisible(hWnd) == FALSE) {
				KillTimer(hWnd, wParam);
				break;
			}
			// マウスの下のウィンドウをチェック
			GetCursorPos(&pt);
			if (ti->pt.x != pt.x && ti->pt.y != pt.y && ti->hWnd != WindowFromPoint(pt)) {
				SendMessage(hWnd, WM_TOOLTIP_HIDE, 0, 0);
				break;
			}
			break;
		}
		break;

	default:
		return DefWindowProc(hWnd, msg, wParam, lParam);
	}
	return 0;
}