std::unique_ptr Jobs::GetJobTopic()

in src/jobs/Jobs.cpp [164:199]


    std::unique_ptr<Utf8String> Jobs::GetJobTopic(JobExecutionTopicType topicType,
                                                  JobExecutionTopicReplyType replyType,
                                                  const util::String &jobId) {
        if (thing_name_.empty()) {
            return nullptr;
        }

        if ((topicType == JOB_NOTIFY_TOPIC || topicType == JOB_NOTIFY_NEXT_TOPIC) && replyType != JOB_REQUEST_TYPE) {
            return nullptr;
        }

        if ((topicType == JOB_GET_PENDING_TOPIC || topicType == JOB_START_NEXT_TOPIC ||
            topicType == JOB_NOTIFY_TOPIC || topicType == JOB_NOTIFY_NEXT_TOPIC) && !jobId.empty()) {
            return nullptr;
        }

        const bool requireJobId = BaseTopicRequiresJobId(topicType);
        if (jobId.empty() && requireJobId) {
            return nullptr;
        }

        const util::String operation = GetOperationForBaseTopic(topicType);
        if (operation.empty()) {
            return nullptr;
        }

        const util::String suffix = GetSuffixForTopicType(replyType);

        if (requireJobId) {
            return Utf8String::Create(BASE_THINGS_TOPIC + thing_name_ + "/jobs/" + jobId + '/' + operation + suffix);
        } else if (topicType == JOB_WILDCARD_TOPIC) {
            return Utf8String::Create(BASE_THINGS_TOPIC + thing_name_ + "/jobs/#");
        } else {
            return Utf8String::Create(BASE_THINGS_TOPIC + thing_name_ + "/jobs/" + operation + suffix);
        }
    };