/*
 *               Copyright (C) 2007, BroadOn Communications Corp.
 *
 *  These coded instructions, statements, and computer programs contain
 *  unpublished  proprietary information of BroadOn Communications Corp.,
 *  and  are protected by Federal copyright law. They may not be disclosed
 *  to  third  parties or copied or duplicated in any form, in whole or in
 *  part, without the prior written consent of BroadOn Communications Corp.
 *
 */


#ifndef __NUP_H__
#define __NUP_H__


#include <es.h>


#ifdef __cplusplus
extern "C" {
#endif


/* Name-value pairs for NUP_Init */
typedef struct {
    const char *name;
    const char *value;
} NUPNameValue;

typedef void* (*NUPAlloc) (u32 size, u32 align);
typedef void (*NUPFree) (void *p);

#define NUP_ALLOC                   "alloc"
#define NUP_FREE                    "free"
#define NUP_LOG_LEVEL               "log_level"
#define NUP_HOSTNAME                "hostname"
#define NUP_COUNTRY                 "country"
#define NUP_REGION                  "region"
#define NUP_THREAD_PRIO             "threadprio"
#define NUP_CLIENT_CERT             "client_cert"
#define NUP_CLIENT_CERT_SIZE        "client_cert_size"
#define NUP_CLIENT_KEY              "client_key"
#define NUP_CLIENT_KEY_SIZE         "client_key_size"
#define NUP_ROOT_CA_CERT            "root_ca_cert"
#define NUP_ROOT_CA_CERT_SIZE       "root_ca_cert_size"
#define NUP_HTTP_RESPONSE_BUF_SIZE  "http_response_buf_size"


/* Log levels for NUP_Init */
#define NUP_LOG_NONE    0
#define NUP_LOG_FINEST  1
#define NUP_LOG_FINER   2
#define NUP_LOG_FINE    3
#define NUP_LOG_INFO    4
#define NUP_LOG_WARN    5
#define NUP_LOG_ERR     6


/* Return values */
typedef s32 NUPError;

/*
 * "totalBytes" and "currentBytes" are only meaningful when content
 * is being downloaded (i.e. when "totalBytes" > 0)
 */
typedef struct {
    NUPError status;    // Error/status code, defined below
    u64 totalBytes;     // Total number of bytes to be downloaded
    u64 currentBytes;   // Number of bytes downloaded so far
    s32 extErr;         // Error returned by an external module
} NUPProgress;

#define NUP_ERROR_OK                    0
#define NUP_ERROR_INVALID               -5001
#define NUP_ERROR_INTERNAL              -5002
#define NUP_ERROR_BUSY                  -5003
#define NUP_ERROR_NOT_BUSY              -5004
#define NUP_ERROR_NOT_DONE              -5005
#define NUP_ERROR_HTTP                  -5006
#define NUP_ERROR_HTTP_STATUS           -5007
#define NUP_ERROR_DATA_RECV             -5008
#define NUP_ERROR_NET_TICKET            -5009
#define NUP_ERROR_NET_TMD               -5010
#define NUP_ERROR_WS_RECV               -5011
#define NUP_ERROR_SOAP                  -5012
#define NUP_ERROR_SOAP_STATUS           -5013
#define NUP_ERROR_MAX                   -5014
#define NUP_ERROR_IMPORT_TICKET         -5015
#define NUP_ERROR_IMPORT_TITLE_INIT     -5016
#define NUP_ERROR_IMPORT_TITLE_DONE     -5017
#define NUP_ERROR_IMPORT_CONTENT_BEGIN  -5018
#define NUP_ERROR_IMPORT_CONTENT_DATA   -5019
#define NUP_ERROR_IMPORT_CONTENT_END    -5020
#define NUP_ERROR_NEED_UPDATE           -5021   /* Internal use only */
#define NUP_ERROR_SYSTEM_TITLE_MISSING  -5022
#define NUP_ERROR_NOT_FOUND             -5023
#define NUP_ERROR_FS                    -5024
#define NUP_ERROR_FS_FULL               -5025
#define NUP_ERROR_TITLE_VERSION         -5026
#define NUP_ERROR_ES                    -5027
#define NUP_ERROR_SSL                   -5028


/* Buffer size limits */
#define NUP_HOSTNAME_BUF_SIZE   256
#define NUP_COUNTRY_BUF_SIZE    32
#define NUP_REGION_BUF_SIZE     32

/* Maximum number of title updates returned by the server */
#define NUP_MAX_TITLE_UPDATE_COUNT  128


/* The APIs are not thread-safe */
NUPError NUP_Init(const NUPNameValue *args, u32 nArgs);

NUPError NUP_CheckAsync(u32 attr, ESTitleId *titleIds, u32 *nTitleIds);

NUPError NUP_DownloadAsync(u32 attr, const ESTitleId *titleIds, u32 nTitleIds);

NUPError NUP_GetProgress(NUPProgress *progress);

NUPError NUP_CleanUp(void);


#ifdef __cplusplus
}
#endif /* __cplusplus */


#endif /* __NUP_H__ */
