PageRenderTime 26ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/Windows/secollab-minisip-android-abfb2ce0694b/minisip/minisip/gui/openglgui/OpenGlGui.cxx

https://bitbucket.org/a30151/mikey-sakke
C++ | 305 lines | 195 code | 79 blank | 31 comment | 32 complexity | 7bcf6e15ce7c33d7dbbde143a565179f MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause, LGPL-2.1, GPL-2.0
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License as published by
  4. * the Free Software Foundation; either version 2 of the License, or
  5. * (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU Library General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program; if not, write to the Free Software
  14. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. /* Copyright (C) 2004
  17. *
  18. * Authors: Erik Eliasson <eliasson@it.kth.se>
  19. * Johan Bilien <jobi@via.ecp.fr>
  20. */
  21. #include<config.h>
  22. #include<stdio.h>
  23. #include<stdlib.h>
  24. #include<vector>
  25. #include"OpenGlGui.h"
  26. #include<libminisip/media/MediaCommandString.h>
  27. #include<libmutil/MemObject.h>
  28. #include<libmutil/stringutils.h>
  29. #include<libmsip/SipCommandString.h>
  30. #include<libminisip/signaling/sip/DefaultDialogHandler.h>
  31. #include<libminisip/media/video/display/VideoDisplay.h>
  32. #include <sys/socket.h>
  33. #include <sys/types.h>
  34. #include <sys/stat.h>
  35. #include <sys/un.h>
  36. using namespace std;
  37. #if 0
  38. class IrInput : public Runnable{
  39. public:
  40. IrInput(Gui* handler);
  41. void start();
  42. void stop();
  43. void run();
  44. private:
  45. bool doStop;
  46. MRef<Semaphore*> quitSignal;
  47. Thread *thread;
  48. Gui* handler;
  49. };
  50. IrInput::IrInput(Gui* h){
  51. quitSignal=new Semaphore();
  52. thread=NULL;
  53. doStop=false;
  54. handler=h;
  55. }
  56. void IrInput::start(){
  57. doStop=false;
  58. thread=new Thread(this);
  59. }
  60. void IrInput::stop(){
  61. quitSignal->dec();
  62. }
  63. static int iropen(){
  64. struct sockaddr_un addr;
  65. addr.sun_family=AF_UNIX;
  66. strcpy(addr.sun_path,"/dev/lircd");
  67. int fd=socket(AF_UNIX,SOCK_STREAM,0);
  68. if(fd==-1) {
  69. cerr <<"EEEE: COULD NOT CREATE SOCKET"<<endl;
  70. return -1;
  71. };
  72. if(connect(fd,(struct sockaddr *)&addr,sizeof(addr))==-1) {
  73. close(fd);
  74. return -1;
  75. };
  76. return fd;
  77. }
  78. static string parseBuf(string s, bool &isRepeat){
  79. int len=s.size();
  80. int i=0;
  81. while (i<len && s[i]!=' ') //pass first digits
  82. i++;
  83. i++; //pass space
  84. if (len>i+2 && s[i]=='0' && s[i+1]=='0')
  85. isRepeat=false;
  86. else
  87. isRepeat=true;
  88. while (i<len && s[i]!=' ') //pass repeat counter
  89. i++;
  90. i++; //pass space
  91. string ret;
  92. while (i<len && s[i]!=' ')
  93. ret=ret+s[i++];
  94. return ret;
  95. }
  96. void IrInput::run(){
  97. cerr <<"EEEE: doing IrInput::run"<<endl;
  98. int fd=-1;
  99. do{
  100. if (fd==-1)
  101. fd=iropen();
  102. if (fd>0){
  103. // cerr <<"EEEE: opened IR connection"<<endl;
  104. }
  105. if (fd!=-1){
  106. int n;
  107. char buf[129];
  108. // cerr <<"EEEE: waiting for IR data..."<<endl;
  109. n=read(fd,buf,128);
  110. // cerr <<"EEEE: got IR data"<<endl;
  111. if(n==-1 || n==0) {
  112. fd=-1;
  113. };
  114. buf[n]=0;
  115. string s(buf);
  116. // cerr <<"------------> DATA <"<<s<<">"<<endl;
  117. bool repeat=false;
  118. string key=parseBuf(s, repeat);
  119. if (key.size()>0)
  120. handler->handleCommand("gui",CommandString("","key",key, repeat?"REPEAT":"FIRST"));
  121. }
  122. if (!doStop&&fd==-1){ //Sleep 10s and then re-try to open
  123. for (int i=0; i<20 && !doStop; i++)
  124. Thread::msleep(500);
  125. }
  126. }while(!doStop);
  127. quitSignal->inc();
  128. }
  129. #endif
  130. OpenGlGui::OpenGlGui(bool fullscreen) {
  131. startFullscreen=fullscreen;
  132. thread=NULL;
  133. // inCall=false;
  134. quitSem = new Semaphore();
  135. // IrInput* ir = new IrInput(this);
  136. // ir->start();
  137. }
  138. void OpenGlGui::start(){
  139. thread = new Thread(this);
  140. }
  141. void OpenGlGui::join(){
  142. display->handleCommand( CommandString("", "wait_quit") );
  143. }
  144. void OpenGlGui::run(){
  145. cerr <<"EEEE: OpenGlGui::run started"<<endl;
  146. VideoDisplayRegistry::getInstance();
  147. display = VideoDisplayRegistry::getInstance()->createDisplay( 960, 640, true, startFullscreen);
  148. massert(display);
  149. display->setCallback(this);
  150. display->handleCommand(CommandString("","set_texture_path","/tmp/") );
  151. display->handleCommand(CommandString("","make_proxy") );
  152. display->handleCommand(CommandString("","enable_menu") );
  153. // display->start();
  154. // Thread::msleep(50000);
  155. //Un-block any thread waiting for us to quit
  156. quitSem->inc();
  157. cerr <<"EEEE: ......................... run quitting"<<endl;
  158. }
  159. void OpenGlGui::waitQuit(){
  160. quitSem->dec();
  161. }
  162. void OpenGlGui::displayErrorMessage(string msg){
  163. // displayMessage(msg, red);
  164. }
  165. CommandString OpenGlGui::handleCommandResp(string subsystem, const CommandString&cmd){
  166. if (cmd.getOp()=="invite"){
  167. return sendCommandResp("sip", cmd);
  168. }
  169. massert(false);
  170. }
  171. void OpenGlGui::handleCommand(const CommandString &cmd){
  172. cerr << "OpenGlGui::handleCommand: Got "<<cmd.getString() << endl;
  173. if (cmd.getOp()=="remote_user_not_found"){
  174. display->handleCommand(cmd);
  175. }
  176. if (cmd.getOp()=="key"){
  177. display->handleCommand(cmd);
  178. }
  179. if (cmd.getOp()=="remote_ringing"){
  180. display->handleCommand(cmd);
  181. }
  182. if (cmd.getOp()=="remote_presence_update"){
  183. display->handleCommand(cmd);
  184. }
  185. if (cmd.getOp()=="incoming_available"){
  186. sendCommand( "media",CommandString("","start_ringing") );
  187. display->handleCommand(cmd);
  188. }
  189. if (cmd.getOp()=="invite"){
  190. CommandString resp=sendCommandResp("sip", cmd);
  191. }
  192. if (cmd.getOp()=="invite_ok"){
  193. CommandString cmdstr( cmd.getDestinationId(),
  194. MediaCommandString::set_session_sound_settings,
  195. "senders", "ON");
  196. sendCommand("media", cmdstr);
  197. display->handleCommand(cmd);
  198. }
  199. if (cmd.getOp()=="accept_invite" || cmd.getOp()=="reject_invite"){
  200. sendCommand( "media",CommandString("","stop_ringing") );
  201. sendCommand("sip", cmd);
  202. CommandString cmdstr( cmd.getDestinationId(),
  203. MediaCommandString::set_session_sound_settings,
  204. "senders", "ON");
  205. sendCommand("media",cmdstr);
  206. }
  207. if (cmd.getOp()=="hang_up"){
  208. cerr <<"EEEE: got hangup from opengl for callid "<< cmd.getDestinationId()<<endl;
  209. sendCommand("sip", cmd);
  210. }
  211. }
  212. bool OpenGlGui::configDialog( MRef<SipSoftPhoneConfiguration *> /*conf*/ ){
  213. cout << "ERROR: OpenGlGui::configDialog is not implemented"<< endl;
  214. return false;
  215. }
  216. void OpenGlGui::setSipSoftPhoneConfiguration(MRef<SipSoftPhoneConfiguration *>sipphoneconfig){
  217. config = sipphoneconfig;
  218. display->setPhoneConfig(config);
  219. }
  220. void OpenGlGui::setCallback(MRef<CommandReceiver*> callback){
  221. Gui::setCallback(callback);
  222. MRef<Semaphore *> localSem = semSipReady;
  223. if( localSem ){
  224. localSem->inc();
  225. }
  226. }