arpadboda commented on a change in pull request #573: minificpp-873 Implmented. URL: https://github.com/apache/nifi-minifi-cpp/pull/573#discussion_r288943581
########## File path: extensions/windows-event-log/CollectorInitiatedSubscription.cpp ########## @@ -0,0 +1,789 @@ +/** + * @file CollectorInitiatedSubscription.cpp + CollectorInitiatedSubscription class implementation + * + * 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 "CollectorInitiatedSubscription.h" +#include <vector> +#include <queue> +#include <map> +#include <vector> +#include <set> +#include <sstream> +#include <stdio.h> +#include <string> +#include <iostream> +#include <memory> +#include <codecvt> + +#include "io/DataStream.h" +#include "core/ProcessContext.h" +#include "core/ProcessSession.h" +#include "utils/ScopeGuard.h" + +#pragma comment(lib, "wevtapi.lib") +#pragma comment(lib, "Wecapi.lib") + +namespace org { +namespace apache { +namespace nifi { +namespace minifi { +namespace processors { + +#define LOG_SUBSCRIPTION_ERROR(error) logError(__LINE__, error) +#define LOG_SUBSCRIPTION_WINDOWS_ERROR(info) logWindowsError(__LINE__, info) + +struct ISupportedProperty { + void virtual Init(const std::shared_ptr<core::ProcessContext>& context) = 0; +}; + +class SuportedProperties { + std::vector<ISupportedProperty*> vISupportedProperty_; + std::set<core::Property> sSupportedProperties_; + +public: + template <typename T> + void add(T& t) + { + vISupportedProperty_.emplace_back(&t); + sSupportedProperties_.insert(t); + } + + void init(const std::shared_ptr<core::ProcessContext>& context) { + for (auto pProp : vISupportedProperty_) { + pProp->Init(context); + } + } + + operator std::set<core::Property>() const + { + return sSupportedProperties_; + } +}; + +static SuportedProperties s_supportedProperties; + +template <typename T> +class SupportedProperty: public ISupportedProperty, public core::Property { + T t_; + +public: + template <typename ...Args> + SupportedProperty(const Args& ...args) : core::Property(args...) { + s_supportedProperties.add(*this); + } + + void Init(const std::shared_ptr<core::ProcessContext>& context) override; + + T value() { + return t_; + } +}; + +void SupportedProperty<std::wstring>::Init(const std::shared_ptr<core::ProcessContext>& context) { + std::string val; + context->getProperty(getName(), val); + + t_ = std::wstring(val.begin(), val.end()); +}; + +void SupportedProperty<uint64_t>::Init(const std::shared_ptr<core::ProcessContext>& context) { + context->getProperty(getName(), t_); +}; + +struct TimeProperty { + int64_t time_{}; + + operator int64_t() { + return time_; + } +}; + +void SupportedProperty<TimeProperty>::Init(const std::shared_ptr<core::ProcessContext>& context) { + std::string strTime; + context->getProperty(getName(), strTime); + + int64_t time{}; + core::TimeUnit unit; + core::Property::StringToTime(strTime, time, unit); + core::Property::ConvertTimeUnitToMS(time, unit, time); + + t_.time_ = time; +}; + +static auto to_string(const std::wstring& str) { + return std::string(str.begin(), str.end()); +} + +static auto to_wstring(const std::string& str) { Review comment: Auto return type is C++14. Just checked our readme and it doesn't specify any compiler requirements for Window. I'm fine with requiring MSVC 14 or later on Win as we don't really have to be backward compatible on this platform, but the readme should be amended to clearly state this. Moreover, this function seems to be unreferenced. :) ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
