25f494ef8098227dd80cea0adc6d492fbee3917b
[scilab.git] / scilab / modules / action_binding / sci_gateway / cpp / sci_notify.cpp
1 /*
2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2009 - DIGITEO - Vincent COUVERT
4 *
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution.  The terms
8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
10 *
11 */
12 /*--------------------------------------------------------------------------*/
13 #include "Signal.hxx"
14
15 extern "C"
16 {
17 #include "gw_action_binding.h"
18 #include "stack-c.h"
19 #include "api_common.h"
20 #include "api_string.h"
21 #include "localization.h"
22 #include "Scierror.h"
23 #include "MALLOC.h"
24 #include "freeArrayOfString.h"
25 #include "getScilabJavaVM.h"
26 #include "api_oldstack.h"
27 }
28 /*--------------------------------------------------------------------------*/
29 using namespace org_scilab_modules_action_binding_utils;
30 /*--------------------------------------------------------------------------*/
31 int sci_notify(char *fname, int*_piKey)
32 {
33         CheckRhs(1,1);
34         CheckLhs(0,1);
35
36         int m1 = 0, n1 = 0;
37         int *piAddressVarOne = NULL;
38         char **pStVarOne = NULL;
39         int *lenStVarOne = NULL;
40         int iType = 0;
41         SciErr sciErr;
42
43         sciErr = getVarAddressFromPosition(_piKey, 1, &piAddressVarOne);
44         if(sciErr.iErr)
45         {
46                 printError(&sciErr, 0);
47                 return 0;
48         }
49
50         sciErr = getVarType(_piKey, piAddressVarOne, &iType);
51         if(sciErr.iErr)
52         {
53                 printError(&sciErr, 0);
54                 return 0;
55         }
56
57         if ( iType != sci_strings )
58         {
59                 Scierror(999,_("%s: Wrong type for input argument #%d: A string expected.\n"),fname,1);
60                 return 0;
61         }
62
63         /* get dimensions */
64         sciErr = getMatrixOfString(_piKey, piAddressVarOne, &m1, &n1, lenStVarOne, pStVarOne);
65         if(sciErr.iErr)
66         {
67                 printError(&sciErr, 0);
68                 return 0;
69         }
70
71         if ( m1 * n1 != 1 )
72         {
73                 Scierror(999,_("%s: Wrong type for input argument #%d: A string expected.\n"),fname,1);
74                 return 0;
75         }
76
77         lenStVarOne = (int*)MALLOC(sizeof(int));
78         if (lenStVarOne == NULL)
79         {
80                 Scierror(999,_("%s: No more memory.\n"), fname);
81                 return 0;
82         }
83
84         /* get lengths */
85         sciErr = getMatrixOfString(_piKey, piAddressVarOne, &m1, &n1, lenStVarOne, pStVarOne);
86         if(sciErr.iErr)
87         {
88                 printError(&sciErr, 0);
89                 return 0;
90         }
91
92         pStVarOne = (char **)MALLOC(sizeof(char*));
93         if (pStVarOne == NULL)
94         {
95                 Scierror(999,_("%s: No more memory.\n"), fname);
96                 return 0;
97         }
98
99         pStVarOne[0] = (char*)MALLOC(sizeof(char*) * (lenStVarOne[0] + 1));
100
101         /* get strings */
102         sciErr = getMatrixOfString(_piKey, piAddressVarOne, &m1, &n1, lenStVarOne, pStVarOne);
103         if(sciErr.iErr)
104         {
105                 printError(&sciErr, 0);
106                 return 0;
107         }
108
109         Signal::notify(getScilabJavaVM(), pStVarOne[0]);
110         freeArrayOfString(pStVarOne, 1);
111
112         LhsVar(1) = 0;
113         PutLhsVar();
114         return 0;
115 }
116 /*--------------------------------------------------------------------------*/