//
// Copyright (C) 2008 Institut fuer Telematik, Universitaet Karlsruhe (TH)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//

/**
 * @file MyGlobalDhtTestMap.h
 * @author Ingmar Baumgart, Dilum Bandara
 * @version 0.1
 * @date 06/22/2010
 */

#ifndef __MY_GLOBAL_KQ_H__
#define __MY_GLOBAL_KQ_H__

//#include <map>
#include <omnetpp.h>
#include <OverlayKey.h>
#include <BinaryValue.h>
#include <stdio.h>

class GlobalStatistics;

/**
 * Module with a global view on all keys & queries (used by MyDHTTestApp)
 */
class MyGlobalKQ : public cSimpleModule
{
public:
    MyGlobalKQ();
    ~MyGlobalKQ();

    /*
     * Returns a key from the key file (in order as defined in file)
     *
     * @return A key, if key is UNSPECIFIED_KEY then peer should not ask for
	 * any further keys
     */
    const OverlayKey& getKey();

    /*
     * Returns a key to be used in a query from query file (in order as defined in file)
     *
     * @return A key, if key is UNSPECIFIED_KEY then peer should not ask for
	 * any further keys & should get ready to stop simulation
     */
    const OverlayKey& getQuery(int groupId);

private:
    void initialize();
    void handleMessage(cMessage* msg);
    void finish();
    GlobalStatistics* globalStatistics; /**< pointer to GlobalStatistics module in this node */

	bool useMultipleQueryFiles;
    const char *keyFile;
    const char *queryFile1;
    const char *queryFile2;
    const char *queryFile3;
    const char *queryFile4;
    const char *queryFile5;
    const char *queryFile6;
    const char *queryFile7;
    const char *queryFile8;
    const char *queryFile9;
    const char *queryFile10;

	FILE *pKeyFile;
	FILE *pQueryFile1;
	FILE *pQueryFile2;
	FILE *pQueryFile3;
	FILE *pQueryFile4;
	FILE *pQueryFile5;
	FILE *pQueryFile6;
	FILE *pQueryFile7;
	FILE *pQueryFile8;
	FILE *pQueryFile9;
	FILE *pQueryFile10;
	int keyCount ;
	OverlayKey key;
	char buffer[50];
};

#endif
