Jack Hansdampf / mbed-mqtt-GSOE1

Dependents:   ESP8266MQTT

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers TestTask.cpp Source File

TestTask.cpp

00001 /**************************************************************************************
00002  * Copyright (c) 2016, Tomoaki Yamaguchi
00003  *
00004  * All rights reserved. This program and the accompanying materials
00005  * are made available under the terms of the Eclipse Public License v1.0
00006  * and Eclipse Distribution License v1.0 which accompany this distribution.
00007  *
00008  * The Eclipse Public License is available at
00009  *    http://www.eclipse.org/legal/epl-v10.html
00010  * and the Eclipse Distribution License is available at
00011  *   http://www.eclipse.org/org/documents/edl-v10.php.
00012  *
00013  * Contributors:
00014  *    Tomoaki Yamaguchi - initial API and implementation 
00015  **************************************************************************************/
00016 #include <unistd.h>
00017 #include <cassert>
00018 #include "TestTask.h"
00019 #include "Threading.h"
00020 #include "TestProcess.h"
00021 using namespace std;
00022 using namespace MQTTSNGW;
00023 
00024 TestTask::TestTask(TestProcess* proc)
00025 {
00026     proc->attach((Thread*)this);
00027     _proc = proc;
00028 }
00029 
00030 TestTask::~TestTask()
00031 {
00032 
00033 }
00034 
00035 void TestTask::initialize(int argc, char** argv)
00036 {
00037     printf("Task initialize complite.\n");
00038 }
00039 
00040 void TestTask::run(void)
00041 {
00042     int evcnt = 0;
00043     EventQue* evQue = _proc->getEventQue();
00044     uint16_t duration = 0;
00045 
00046 
00047     while (true)
00048     {
00049         Event* ev = evQue->timedwait(5000);
00050         evcnt++;
00051         if ( ev->getEventType() == EtTimeout )
00052         {
00053             assert(EVENT_CNT + 1 == evcnt);
00054             delete ev;
00055             printf("[ OK ]\n");
00056             break;
00057         }
00058         MQTTSNPacket* packet = ev->getMQTTSNPacket();
00059         packet->getDISCONNECT(&duration);
00060         delete ev;
00061     }
00062 
00063     while(true)
00064     {
00065         if ( CHK_SIGINT)
00066         {
00067             printf("\nTest  Task           [ OK ]\n");
00068             return;
00069         }
00070         printf("Enter CTRL+C\n");
00071         sleep(1);
00072     }
00073 }