<commit_before>//******************************************************************
//
// Copyright 2016 Samsung Electronics All Rights Reserved.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
// Licensed 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 <stdio.h>
#include <unistd.h>
#include "pthread.h"

#include "ocstack.h"
#include "NSCommon.h"
#include "NSConsumerInterface.h"

#ifdef WITH_CLOUD
#include "NSConstants.h"
#include "NSConsumerCommon.h"
#include "cloud_connector.h"
#include "oic_malloc.h"

#define CLOUD_CONTEXT_VALUE 0x99
#define CLOUD_PRESENCE_SUBSCRIBE_QUERY ""          // refer to IoTivity Cloud Module Sample

#define CLOUD_HOST_ADDRESS ""                      // refer to IoTivity Cloud Module Sample
#define CLOUD_IOTIVITYNS_SESSION ""                // refer to IoTivity Cloud Module Sample
#endif

void onDiscoverNotification(NSProvider * provider)
{
    printf("notification resource discovered\n");
    printf("subscribe result %d\n", NSSubscribe(provider));
    printf("startSubscribing\n");
}

void onProviderChanged(NSProvider * provider, NSResponse response)
{
    printf("Provider changed: %d\n", response);
    printf("subscribed provider Id : %s\n", provider->providerId);
}

void onNotificationPosted(NSMessage * notification)
{
    printf("id : %lld\n", (long long int)notification->messageId);
    printf("title : %s\n", notification->title);
    printf("content : %s\n", notification->contentText);
    printf("source : %s\n", notification->sourceName);
    NSConsumerSendSyncInfo(notification->providerId, notification->messageId, NS_SYNC_READ);
}

void onNotificationSync(NSSyncInfo * sync)
{
    printf("Sync ID : %lld\n", (long long int)sync->messageId);
    printf("Sync STATE : %d\n", sync->state);
}


#ifdef WITH_CLOUD
OCStackApplicationResult handleLoginoutCB(void *ctx,
        OCDoHandle handle,
        OCClientResponse *clientResponse)<commit_msg>Modify notification consumer example code<commit_after>//******************************************************************
//
// Copyright 2016 Samsung Electronics All Rights Reserved.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
// Licensed 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 <stdio.h>
#include <unistd.h>
#include "pthread.h"

#include "ocstack.h"
#include "NSCommon.h"
#include "NSConsumerInterface.h"

#ifdef WITH_CLOUD
#include "NSConstants.h"
#include "NSConsumerCommon.h"
#include "cloud_connector.h"
#include "oic_malloc.h"

#define CLOUD_CONTEXT_VALUE 0x99
#define CLOUD_PRESENCE_SUBSCRIBE_QUERY ""          // refer to IoTivity Cloud Module Sample

#define CLOUD_HOST_ADDRESS ""                      // refer to IoTivity Cloud Module Sample
#define CLOUD_IOTIVITYNS_SESSION ""                // refer to IoTivity Cloud Module Sample
#endif

void onDiscoverNotification(NSProvider * provider)
{
    printf("notification resource discovered\n");
    printf("subscribe result %d\n", NSSubscribe(provider));
    printf("startSubscribing\n");
}

void onProviderChanged(NSProvider * provider, NSResponse response)
{
    printf("Provider changed: %d\n", response);
    printf("subscribed provider Id : %s\n", provider->providerId);

    if (response == NS_TOPIC)
    {
        printf ("Provider Topic Updated\n");
        if (provider->topicLL)
        {
            NSTopicLL * iter = provider->topicLL;
            while (iter)
            {
                printf("Topic Name: %s\t Topic State: %d\n", iter->topicName, iter->state);
                iter = iter->next;
            }
        }

        printf("3. Get Topics\n");
        printf("4. Select Topics\n");
        printf("input: ");

        int num = 0;
        char dummy = '\0';
        scanf("%d", &num);
        fflush(stdin);
        scanf("%c", &dummy);
        fflush(stdin);

        switch (num)
        {
            case 3:
                printf("3. Get Topics\n");
                NSConsumerGetInterestTopics(provider);
                break;
            case 4:
                printf("4. Select Topics\n");
                if (provider->topicLL)
                {
                    NSTopicLL * iter = provider->topicLL;
                    int i = 0;
                    while (iter)
                    {
                        iter->state = (i++)%2;
                        printf("Topic Name: %s\t Topic State: %d\n", iter->topicName, iter->state);
                        iter = iter->next;
                    }
                }
                NSConsumerSelectInterestTopics(provider);
                break;
        }
    }
}

void onNotificationPosted(NSMessage * notification)
{
    printf("id : %lld\n", (long long int)notification->messageId);
    printf("title : %s\n", notification->title);
    printf("content : %s\n", notification->contentText);
    printf("source : %s\n", notification->sourceName);
    if (notification->topic)
    {
        printf("topic : %s\n", notification->topic);
    }
    NSConsumerSendSyncInfo(notification->providerId, notification->messageId, NS_SYNC_READ);
}

void onNotificationSync(NSSyncInfo * sync)
{
    printf("Sync ID : %lld\n", (long long int)sync->messageId);
    printf("Sync STATE : %d\n", sync->state);
}


#ifdef WITH_CLOUD
OCStackApplicationResult handleLoginoutCB(void *ctx,
        OCDoHandle handle,
        OCClientResponse *clientResponse)
{'fraction_non_alphanumeric': 0.17245085995085996, 'fraction_numerical': 0.004914004914004914, 'mean_word_length': 2.675507900677201, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '254409', 'n_tokens_mistral': 1945, 'n_tokens_neox': 1832, 'n_words': 495}