[ https://issues.apache.org/jira/browse/MINIFICPP-558?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16688416#comment-16688416 ]
ASF GitHub Bot commented on MINIFICPP-558: ------------------------------------------ Github user arpadboda commented on a diff in the pull request: https://github.com/apache/nifi-minifi-cpp/pull/437#discussion_r233942801 --- Diff: extensions/coap/controllerservice/CoapConnector.cpp --- @@ -0,0 +1,189 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "CoapConnector.h" +#include <openssl/err.h> +#include <openssl/ssl.h> +#include <string> +#include <memory> +#include <set> +#include "core/Property.h" +#include "CoapConnector.h" +#include "io/validation.h" +#include "properties/Configure.h" + +namespace org { +namespace apache { +namespace nifi { +namespace minifi { +namespace controllers { + +static core::Property RemoteServer; +static core::Property Port; +static core::Property MaxQueueSize; + +core::Property CoapConnectorService::RemoteServer(core::PropertyBuilder::createProperty("Remote Server")->withDescription("Remote CoAP server")->isRequired(true)->build()); +core::Property CoapConnectorService::Port(core::PropertyBuilder::createProperty("Remote Port")->withDescription("Remote CoAP server port")->isRequired(true)->build()); +core::Property CoapConnectorService::MaxQueueSize(core::PropertyBuilder::createProperty("Max Queue Size")->withDescription("Max queue size for received data ")->isRequired(true)->build()); + +void CoapConnectorService::initialize() { + if (initialized_) + return; + + callback_pointers ptrs; + ptrs.data_received = receiveMessage; + ptrs.received_error = receiveError; + init_coap_api(this, &ptrs); + + std::lock_guard<std::mutex> lock(initialization_mutex_); + + ControllerService::initialize(); + + initializeProperties(); + + initialized_ = true; +} + +void CoapConnectorService::onEnable() { + std::string port_str; + if (getProperty(RemoteServer.getName(), host_) && !host_.empty() && getProperty(Port.getName(), port_str) && !port_str.empty()) { + core::Property::StringToInt(port_str, port_); + } else { + // this is the case where we aren't being used in the context of a single controller service. + if (configuration_->get("nifi.c2.agent.coap.host", host_) && configuration_->get("nifi.c2.agent.coap.port", port_str)) { + core::Property::StringToInt(port_str, port_); + } + + } +} + +CoapConnectorService::CoAPMessage CoapConnectorService::sendPayload(uint8_t type, const std::string endpoint, unsigned char *payload, size_t size) { + struct coap_context_t* ctx=NULL; + struct coap_session_t* session=NULL; + + coap_address_t dst_addr, src_addr; + coap_uri_t uri; + uri.host.s = reinterpret_cast<unsigned char *>(const_cast<char*>(host_.c_str())); --- End diff -- Uri.host is coap_str_const_t, which has "s" as const member, so there is no need of const cast here, just reinterpret cast to "const unsigned char *". > Move PayloadSerializer in preparation for Coap > ---------------------------------------------- > > Key: MINIFICPP-558 > URL: https://issues.apache.org/jira/browse/MINIFICPP-558 > Project: NiFi MiNiFi C++ > Issue Type: Bug > Reporter: Mr TheSegfault > Assignee: Mr TheSegfault > Priority: Major > Fix For: 0.6.0 > > > Move PayloadSerializer -- This message was sent by Atlassian JIRA (v7.6.3#76005)