chatsession.h
上传用户:zslianheng
上传日期:2013-04-03
资源大小:946k
文件大小:2k
源码类别:

Linux/Unix编程

开发平台:

Visual C++

  1. /***************************************************************************
  2.  *                                                                         *
  3.  *   This program is free software; you can redistribute it and/or modify  *
  4.  *   it under the terms of the GNU General Public License as published by  *
  5.  *   the Free Software Foundation; either version 2 of the License, or     *
  6.  *   (at your option) any later version.                                   *
  7.  *                                                                         *
  8.  *   copyright            : (C) 2002 by Zhang Yong                         *
  9.  *   email                : z-yong163@163.com                              *
  10.  ***************************************************************************/
  11. #ifndef _CHAT_SESSION_H
  12. #define _CHAT_SESSION_H
  13. #include "tcpsessionbase.h"
  14. #include "speechcodec.h"
  15. class ChatSessionListener {
  16. public:
  17. virtual void onClose() = 0;
  18. virtual void onChatText(const char *text) = 0;
  19. virtual void onSpeechData(const char *frame, int n) = 0;
  20. };
  21. class ChatSession : public TcpSessionListener {
  22. public:
  23. ChatSession(TcpSessionBase *s);
  24. ~ChatSession();
  25. void setListener(ChatSessionListener *l) {
  26. listener = l;
  27. }
  28. int getBitsPerSample() {
  29. return currentCodec->getBitsPerSample();
  30. }
  31. int getFrameSize() {
  32. return (getBitsPerSample() * currentCodec->getSamplesPerFrame() / 8);
  33. }
  34. void sendChatText(const char *text);
  35. void sendSpeechData(const char *speech, int n);
  36. void onSpeechData(InPacket &in);
  37. TcpSessionBase *tcp;
  38. private:
  39. virtual bool onPacketReceived(InPacket &);
  40. virtual void onSend() {}
  41. virtual void onClose();
  42. void onChatText(InPacket &);
  43. ChatSessionListener *listener;
  44. SpeechCodec *currentCodec;
  45. };
  46. #endif