/****************************************************************************

   mod_dav_pgsql (DASL) for apache 2.X
   CopyRight(C) 2005 SolutionBox Inc. All Rights reserved.
   CopyRight(C) 2006 Netomi Inc. All Rights reserved.
   Author : elenoa lazyfake (elenoa@solutionbox.co.kr)

   $Id: share.h,v 1.6 2007/03/19 08:43:12 elenoa Exp $

   Redistribution and use in source and binary forms, with or with out
   modification, are not permitted in outside of SolutionBox Inc.

 ****************************************************************************/

#ifndef __SHARE_STATISTIC_H__
#define __SHARE_STATISTIC_H__

#define STAT_STAMP(a)          (((a) + 299) / 300)
#define STAT_LOC(a)            ((a) - (((a) >> 1) << 1))
#define OUTB                   0
#define INB                    1
#define MTU                    1500
#define MSS                    1460
//#define CONTENT_TO_TRAFFIC(s)  (s + (((s) + MSS - 1) / MSS) * (MTU - MSS))
//#define CONTENT_TO_TRAFFIC(s)  ((((s) + MSS - 1) / MSS) * MTU)
#define CONTENT_TO_TRAFFIC(s)  ((int)(s * 1.1))

#ifndef __OPENDISK_SOLUTION_NOT_USE_TS__

struct service_network_stat {
	int nServiceSeq;
	int nUserSeq;
	uint32_t timestamp; // 5분 단위 1씩 증가.

	uint64_t down_content_size;    // 누적시 down content size 누적
	uint64_t up_content_size;   // 누적시 up contents size 누적
	uint64_t down_traffic;        // 누적시 (down_content_size * 1.1)를 누적
	uint64_t up_traffic;        // 누적시 (up_traffic * 1.1)를 누적
};

/* transfer statistics */
int dav_initialize_shared_statistic(dav_repos_server_conf *dsc, server_rec *s, apr_pool_t *p);
void dav_cleanup_shared_statistic();

int dav_shared_ts_access_statistic(request_rec *r);

void dav_shared_ts_open_stream(request_rec *r, int bound);
void dav_shared_ts_close_stream(request_rec *r, int bound);
void dav_shared_ts_transfer_data(request_rec *r, int bound, apr_size_t size, apr_size_t org_size);


#endif // !__OPENDISK_SOLUTION_NOT_USE_TS__

#endif // __SHARE_STATISTIC_H__
