//
//  HA_SocketDeviceObject.h
//  HA_server
//
//  Created by hark on 2013/07/06.
//  Copyright (c) 2013年 hark. All rights reserved.
//

#ifndef __HA_server__HA_SocketDeviceObject__
#define __HA_server__HA_SocketDeviceObject__

#ifdef __cplusplus
#include <iostream>
#include "HA_Object.h"
#include "HA_buffer.h"
#include "HA_device.h"
#include "librasp-netapi.h"
#include "libkm-netapi.h"

#define SELECTED_NONE 0x00
#define RASP_API      0x01
#define KM_API        0x02

namespace HARKAndroid {
    
typedef struct _SOCKET_DEVICE_
{
    int device_type;
    int api_type;
    //int fd;
    int channels;
    int bits;
    //int interface_no;
    //int address;
    //int max_packet_size;
} SOCKET_DEVICE_t;

class SocketDeviceObject : public DeviceObject {
private:
    pthread_t thread_id;
    ::pthread_mutex_t Being_Stopped_mutex;
    bool BeingStopped;

    SOCKET_DEVICE_t socket_device_info;

    std::string hostname;
        
public:
	WS_HANDLE_t    *SocketRaspDeviceHandle;
	WS_KM_HANDLE_t *SocketKmDeviceHandle;

    SocketDeviceObject(const SocketDeviceObject&);
    SocketDeviceObject();
    SocketDeviceObject(const char * const hostname);
    SocketDeviceObject(const char * const filename, const int length, const int advance);
    virtual ~SocketDeviceObject();
    SocketDeviceObject& operator = (const SocketDeviceObject&);
    
    int open();
    int start(BufferObject&);
    int stop();
    int close();
    int allclose();
    
    int SetBeingStopped();
    int ResetBeingStopped();
    bool isBeingStopped();

    int SetHostName(const char * const arghostname) {
        hostname = arghostname;
        return(0);
    };
    int GetApiType(){
    	return socket_device_info.api_type;
    }
    int GetChannels(){
    	return socket_device_info.channels;
    }
    int GetBits(){
    	return socket_device_info.bits;
    }
    
    BufferObject *buffer;

};

} // end of namespace

#endif // __cpusplus

#endif /* defined(__HA_server__HA_SocketDeviceObject__) */
