/*
 *            Copyright (c) 1998-2000 by NETsilicon Inc.
 *
 *  This software is copyrighted by and is the sole property of 
 *  NETsilicon.  All rights, title, ownership, or other interests
 *  in the software remain the property of NETsilicon.  This
 *  software may only be used in accordance with the corresponding
 *  license agreement.  Any unauthorized use, duplication, transmission,  
 *  distribution, or disclosure of this software is expressly forbidden.
 *
 *  This Copyright notice may not be removed or modified without prior
 *  written consent of NETsilicon.
 *
 *  NETsilicon, reserves the right to modify this software
 *  without notice.
 *
 *  NETsilicon
 *  411 Waverley Oaks Road                  USA 781.647.1234
 *  Suite 227                               http://www.netsilicon.com
 *  Waltham, MA 02452                       AmericaSales@netsilicon.com
 *
 *************************************************************************
 *
 *     Module Name: appdown.cxx
 *         Version: 1.00
 *   Original Date: 08/23/99	
 *          Author: Julia Rakhvalska
 *        Language: Ansi C++
 * Compile Options: 
 * Compile defines: 
 *       Libraries: 
 *    Link Options: 
 *
 *    Entry Points: 
 *
 * Description.
 * =======================================================================
 * This file contains the PrintApplicationDown class implementation.
 *                                                                        
 * Edit Date/Ver   Edit Description
 * ==============  ===================================================
 *
 *
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "appdown.h"

#include "bsp_api.h"
#include "appconf_api.h"


/*
 *  Function: ApplicationDownCnt::ApplicationDownCnt()
 *
 *  Description:
 *      This is a default constructor
 *
 *  Parameters:
 *      none
 *
 */
ApplicationDownCnt::ApplicationDownCnt()
{
    ticks = 0; 
    cnt = 0;                                // Clear ticks & cnt
    
    if ((name = new char[strlen(NAGetAppDialogAppName())+1]))
        memcpy(name,NAGetAppDialogAppName(),strlen(NAGetAppDialogAppName())+1);   // initialize application name
}

/*
 *  Function: ApplicationDownCnt::~ApplicationDownCnt()
 *
 *  Description:
 *     Destructor
 *
 */
ApplicationDownCnt::~ApplicationDownCnt()
{
    delete [] name;
}


/*
 *  Functions: int ApplicationDownCnt::Update()
 *
 *  Description:
 *      This routine counts ticks and seconds since BSP started.
 *
 *  Parameters:
 *      none
 *
 *  Return Values:
 *      1	- second count changed
 *      0	- second count has not changed
 */
int ApplicationDownCnt::Update()
{
    if (++ticks % NABspTicksPerSecond == 0)
    {
        cnt++;
        return 1;
    }
    return 0;
}

/*
 *  Functions: void ApplicationDownCnt::Name(pchar &_name)
 *
 *  Description:
 *      This routine returns the application name.
 *      It allocates a buffer for it and returns the pointer to this buffer in _name
 *
 *  Parameters:
 *      _name       a reference to the name to return
 *
 *  Return Values:
 *      none
 */
void ApplicationDownCnt::Name(pchar &_name)
{
    if ((_name = new char[strlen(name)+1]))
        memcpy(_name,name,strlen(name)+1);   // initialize application name
}
