/* * $Id: commandcontrol.h,v 1.5 2007/06/25 06:19:21 ozawa Exp $ * * Copyright 2003- ONGS Inc. All rights reserved. * * author: Masanori OZAWA (ozawa@ongs.co.jp) * version: $Revision: 1.5 $ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY ONGS INC ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL ONGS INC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * The views and conclusions contained in the software and documentation are * those of the authors and should not be interpreted as representing official * policies, either expressed or implied, of the ONGS Inc. * */ #ifndef ___COMMANDCONTROL_H #define ___COMMANDCONTROL_H #include "glib.h" #include "../include/commandid.h" /** * プロセス間で送受信するコマンドの生成・破棄・送受信処理を * 全て一括管理します。 */ class CommandControl { public: /** * コンストラクタ */ CommandControl(); /** * デストラクタ */ ~CommandControl(); /** * コマンドをキューに追加します。 * * @param nCommandID コマンドID * @param nFileID 操作対象のファイルID * @param nExtraFlag 拡張情報 * @param nDataLen pData の長さ(byte) * @param pData コマンドに固有のデータ */ void addCommand(u_int32_t nCommandID, u_int32_t nFileID, u_int32_t nExtraFlag, u_int32_t nDataLen, void *pData); /** * コマンドを破棄します。 * * @param lpCommand コマンド */ void destroyCommand(LP_COMMAND lpCommand); /** * 先頭のコマンドを1つキューから取り出します。 * * @return コマンド */ LP_COMMAND getCommand(); /** * コマンドを受信します。 * * @param nIn 入力用デスクリプタ * @return 受信したコマンド。コマンドができない場合は NULL。 */ LP_COMMAND receiveCommand(int nIn); /** * コマンドを送信します。 * * @param nOut 出力用デスクリプタ * @param lpCommand コマンド */ void sendCommand(int nOut, const LP_COMMAND lpCommand); /** * 送信コマンドおよび、受信コマンドが発生するまで待機します。 * * @param nIn 入力用デスクリプタ * @param utime 最大待機時間をマイクロ秒単位で指定します。 * 0を指定するとコマンドが発生するまで待機します。 * @return コマンドが発生した場合は true を戻します。 */ bool wait(int nIn, unsigned long utime); private: /** * コマンドキュー */ GQueue* m_pCommands; /** * 同期処理用ミューテックス */ GMutex* m_pMutex; }; #endif