File: tkfunc.C

package info (click to toggle)
speaker 1.0.1-4
  • links: PTS
  • area: main
  • in suites: woody
  • size: 264 kB
  • ctags: 174
  • sloc: cpp: 1,521; tcl: 786; makefile: 91; sh: 22
file content (145 lines) | stat: -rw-r--r-- 3,637 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/************************************************************
*  Interface between Tcl/Tk and spk interface routines
************************************************************/

#include "incall.h"

extern "C" {
#include "tk.h"
}

ConfigInfo conf;
CommandSet Cmds;
Locks      MLock;
VModem     Modem;
int        OnLine = 0;

/**********************************************************
*  Initialize everything
**********************************************************/
int initSpkApp(Tcl_Interp* interp)
{
   conf.ReadConfig(CONFIG_FILE);
   MLock.Init(&conf);
   Cmds.Init(&conf);
   if (!MLock.MakeLockFile()) 
   {
      interp->result = "Could not lock port!";
      return TCL_ERROR;
   }
   if (!Modem.Init(&conf))
   {
      interp->result = "Could not initialize the modem!";
      return TCL_ERROR;
   }

   MLock.RemoveLockFile();
   return TCL_OK;
}

/**********************************************************
*  "dial" callback
**********************************************************/
int spkDialCmd(ClientData /*clientData*/, Tcl_Interp* interp,
               int argc, char** argv) 
{
   if (argc < 2) 
   {
      interp->result = "wrong # args";
      return TCL_ERROR;
   }

   // Initialize the modem and pick up line
   if (!OnLine)
   {
      if (!MLock.MakeLockFile()) 
      {
         interp->result = "Could not lock port!";
         return TCL_ERROR;
      }
      if (!Modem.InitRead())
      {
         interp->result = "Could not initialize the port!";
         return TCL_ERROR;
      }
      Modem.ExecuteSequence(Cmds.GetSequence("SPEAKER_ON"));
      sleep(1);
      OnLine = 1;
   }

   char bufcmd[256];
   int  place, length;
   CommandSequence* sq;
   sq = Cmds.GetSequence("DIAL");
   strcpy(bufcmd, sq->GetCommand());
   place = strlen(bufcmd);
   bufcmd[place+1] = 0;

   for (int i = 1; i < argc; i++)
   {
      length = strlen(argv[i]);
      for (int j = 0; j < length; j++)
      {
         if (argv[i][j] == '[')
         {
            if (strncmp(&(argv[i][j]),"[PAUSE]", 7) == 0)
            {
               sleep(1);
               j += 6;
            }
            if (strncmp(&(argv[i][j]),"[FLASH]", 7) == 0)
            {
               bufcmd[place] = '!';
//               printf("Dialing: \"%s\"\n", bufcmd);
               Modem.MsgExchange(bufcmd, sq->GetAnswer());
               j += 6;
            }
         } else
         {
            bufcmd[place] = argv[i][j];
//            printf("Dialing: \"%s\"\n", bufcmd);
            Modem.MsgExchange(bufcmd, sq->GetAnswer());
         }
      }
   }
   return TCL_OK;
}

/**********************************************************
*  "hangup" callback
**********************************************************/
int spkHangupCmd(ClientData /*clientData*/, Tcl_Interp* interp,
               int argc, char** /*argv*/) 
{
   if (argc != 1) 
   {
      interp->result = "wrong # args";
      return TCL_ERROR;
   }
//   printf("Hanging up...\n");

   if (OnLine)
   {
      Modem.ExecuteSequence(Cmds.GetSequence("SPEAKER_OFF"));
      Modem.StopRead();
      MLock.RemoveLockFile();
      OnLine = 0;
   }
   return TCL_OK;
}

/************************************************************
*   GSPK_AppInit --
*       Initialization for gspk
************************************************************/
int GSPK_Init(Tcl_Interp *interp)
{
   initSpkApp(interp);

   Tcl_CreateCommand(interp, "dial", spkDialCmd,
                     (ClientData) NULL, (Tcl_CmdDeleteProc*) NULL);

   Tcl_CreateCommand(interp, "hangup", spkHangupCmd,
                     (ClientData) NULL, (Tcl_CmdDeleteProc*) NULL);
   return TCL_OK;
}