Statistics
| Branch: | Revision:

root / src / org.omnetpp.ide.nativelibs / eventlog.i @ 0418c1a0

History | View | Annotate | Download (11.8 KB)

1
%module EventLogEngine
2

    
3
// covariant return type warning disabled
4
#pragma SWIG nowarn=822
5

    
6
%include "loadlib.i"
7
%include "enumtypeunsafe.swg"
8
%include "commondefs.i"
9
%include "bigdecimal.i"
10
%include "stacktrace.i"
11
%javaconst(1);
12

    
13
COMMON_ENGINE_BIGDECIMAL();
14

    
15
%{
16
#include "ievent.h"
17
#include "ieventlog.h"
18
#include "event.h"
19
#include "filteredevent.h"
20
#include "messagedependency.h"
21
#include "eventlogentry.h"
22
#include "eventlogentries.h"
23
#include "eventlogindex.h"
24
#include "eventlog.h"
25
#include "eventlogfacade.h"
26
#include "eventlogtablefacade.h"
27
#include "sequencechartfacade.h"
28
#include "filteredeventlog.h"
29
#include "filereader.h"
30
%}
31

    
32
// hide export/import macros from swig
33
#define COMMON_API
34
#define EVENTLOG_API
35
#define OPP_DLLEXPORT
36
#define OPP_DLLIMPORT
37

    
38
#define NAMESPACE_BEGIN
39
#define NAMESPACE_END
40
#define USING_NAMESPACE
41

    
42
%include "intxtypes.h"
43
%include "eventlogdefs.h"
44

    
45
/*--------------------------------------------------------------------------
46
 * ptr_t <--> long mapping
47
 *--------------------------------------------------------------------------*/
48

    
49
%typemap(jni)    ptr_t "jlong"
50
%typemap(jtype)  ptr_t "long"
51
%typemap(jstype) ptr_t "long"
52
%typemap(javain) ptr_t "$javainput"
53
%typemap(javaout) ptr_t {
54
   return $jnicall;
55
}
56

    
57
%include "std_common.i"
58
%include "std_string.i"
59
%include "std_set.i"     // our custom version
60
%include "std_list.i"    // our custom version
61
%include "std_vector.i"
62
%include "std_map.i"
63

    
64
namespace std {
65

    
66
   %typemap(javacode) vector<string> %{
67
       public String[] toArray() {
68
           int sz = (int) size();
69
           String[] array = new String[sz];
70
              for (int i=0; i<sz; i++)
71
               array[i] = get(i);
72
           return array;
73
       }
74
       public static StringVector fromArray(String[] array) {
75
           StringVector vector = new StringVector();
76
           for (int i=0; i<array.length; i++)
77
               vector.add(array[i]);
78
           return vector;
79
       }
80
   %}
81

    
82
   %typemap(javacode) set<int> %{
83
       public IntSet(boolean cMemoryOwn) {
84
           this(EventLogEngineJNI.new_IntSet__SWIG_0(), cMemoryOwn);
85
       }
86
   %}
87

    
88
   %extend set<const char *> {
89
       std::vector<const char *> keys() {
90
           std::vector<const char *> vec;
91
           vec.reserve(self->size());
92
           for (std::set<const char *>::iterator it = self->begin(); it!=self->end(); it++)
93
               vec.push_back(*it);
94
           return vec;
95
       }
96
   }
97

    
98
   %extend set<string> {
99
       std::vector<std::string> keys() {
100
           std::vector<std::string> vec;
101
           vec.reserve(self->size());
102
           for (std::set<std::string>::iterator it = self->begin(); it!=self->end(); it++)
103
               vec.push_back(*it);
104
           return vec;
105
       }
106
   }
107

    
108
   %extend map<string,string> {
109
       std::vector<std::string> keys() {
110
           std::vector<std::string> vec;
111
           vec.reserve(self->size());
112
           for (std::map<std::string,std::string>::iterator it = self->begin(); it!=self->end(); it++)
113
               vec.push_back(it->first);
114
           return vec;
115
       }
116
   }
117

    
118
   %template(PStringSet) set<const char *>;
119
   %template(StringSet) set<string>;
120
   %template(StringVector) vector<string>;
121
   %template(PStringVector) vector<const char *>;
122

    
123
   //specialize_std_map_on_both(string,,,,string,,,);
124
   //%template(StringMap) map<string,string>;
125

    
126
   %template(ModuleCreatedEntryList) vector<ModuleCreatedEntry*>;
127
   %template(IMessageDependencyList) vector<IMessageDependency*>;
128
   %template(MessageDependencyList) vector<MessageDependency*>;
129
   %template(FilteredMessageDependencyList) vector<FilteredMessageDependency*>;
130

    
131
   %template(IntSet) set<int>;
132
   %template(PtrSet) set<ptr_t>;
133

    
134
   specialize_std_map_on_both(int,,,,int,,,);
135
   %template(IntIntMap) map<int,int>;
136

    
137
   %template(IntVector) vector<int>;
138
   %template(LongVector) vector<long>;
139
   %template(PtrVector) vector<ptr_t>;
140
};
141

    
142
%ignore EventLog::writeTrace;
143

    
144
%define FIX_STRING_MEMBER(STRUCT,MEMBER,CAPITALIZEDMEMBER)
145
%ignore STRUCT::MEMBER;
146
%extend STRUCT {
147
   std::string get ## CAPITALIZEDMEMBER() {return self->MEMBER;}
148
   void set ## CAPITALIZEDMEMBER(std::string __a) {self->MEMBER = __a;}
149
}
150
%enddef
151

    
152
%define FIX_CHARPTR_MEMBER(STRUCT,MEMBER,CAPITALIZEDMEMBER)
153
%ignore STRUCT::MEMBER;
154
%extend STRUCT {
155
   const char * get ## CAPITALIZEDMEMBER() {return self->MEMBER;}
156
}
157
%enddef
158

    
159
%{
160
   JNIEnv *progressDelegateJenv;
161

    
162
   std::string fromJavaString(JNIEnv *jenv, jstring stringObject)
163
   {
164
      if (!stringObject)
165
        return "<null>";
166
      jboolean isCopy;
167
      const char *buf = jenv->GetStringUTFChars(stringObject, &isCopy);
168
      std::string str = buf ? buf : "";
169
      jenv->ReleaseStringUTFChars(stringObject, buf);
170
      return str;
171
   }
172

    
173
   void delegateProgressToJava(IEventLog *eventLog, void *data)
174
   {
175
      JNIEnv *jenv = progressDelegateJenv;
176
      jobject object = (jobject)data;
177
      jclass clazz = jenv->GetObjectClass(object);
178
      jmethodID progressMethod = jenv->GetMethodID(clazz, "progress", "()V");
179
      jenv->ExceptionClear();
180
      jenv->CallVoidMethod(object, progressMethod);
181

    
182
       jthrowable exceptionObject = jenv->ExceptionOccurred();
183
       if (exceptionObject)
184
       {
185
          jenv->ExceptionDescribe();
186
          jenv->ExceptionClear();
187

    
188
          jclass throwableClass = jenv->GetObjectClass(exceptionObject);
189
          jmethodID method = jenv->GetMethodID(throwableClass, "toString", "()Ljava/lang/String;");
190
          jstring msg = (jstring)jenv->CallObjectMethod(exceptionObject, method);
191
          throw opp_runtime_error(fromJavaString(jenv, msg).c_str());
192
      }
193
   }
194
%}
195

    
196
%extend IEventLog {
197
   void setJavaProgressMonitor(JNIEnv *jenv, jobject object) {
198
      progressDelegateJenv = jenv;
199
      ProgressMonitor newProgressMonitor(object ? &delegateProgressToJava : NULL, object ? jenv->NewGlobalRef(object) : NULL);
200
      ProgressMonitor oldProgressMonitor = self->setProgressMonitor(newProgressMonitor);
201
      jobject oldObject = (jobject)oldProgressMonitor.data;
202
      if (oldObject)
203
         jenv->DeleteGlobalRef(oldObject);
204
   }
205
}
206

    
207
%typemap(in) JNIEnv * {
208
  $1 = jenv;
209
}
210

    
211
%typemap(javaout) EventLogEntry * {
212
   return EventLogEntry.newEventLogEntry($jnicall, $owner);
213
}
214

    
215
%typemap(javaimports) EventLogEntry %{
216
import java.lang.reflect.Constructor;
217
%}
218

    
219
%typemap(javacode) EventLogEntry %{
220

    
221
   @SuppressWarnings("unchecked")
222
   private static Constructor[] eventLogEntryConstructors = new Constructor[100];
223

    
224
   public long getCPtr() {
225
      return swigCPtr;
226
   }
227

    
228
   public boolean equals(Object obj) {
229
      return (obj instanceof EventLogEntry) && getCPtr(this)==getCPtr((EventLogEntry)obj);
230
   }
231

    
232
   public int hashCode() {
233
      return (int)getCPtr(this);
234
   }
235

    
236
   @SuppressWarnings("unchecked")
237
   public static EventLogEntry newEventLogEntry(long cPtr, boolean isOwner) {
238
      try {
239
         if (cPtr == 0)
240
            return null;
241

    
242
         int index = EventLogEngineJNI.EventLogEntry_getClassIndex(cPtr, null);
243
         Constructor constructor = eventLogEntryConstructors[index];
244

    
245
         if (constructor == null)
246
         {
247
            String name = "org.omnetpp.eventlog.engine." + EventLogEngineJNI.EventLogEntry_getClassName(cPtr, null);
248
            Class clazz = Class.forName(name);
249
            constructor = clazz.getDeclaredConstructor(long.class, boolean.class);
250
            eventLogEntryConstructors[index] = constructor;
251
         }
252

    
253
         return (EventLogEntry)constructor.newInstance(cPtr, isOwner);
254
      }
255
      catch (Exception e) {
256
         throw new RuntimeException(e);
257
      }
258
   }
259
%}
260

    
261
%typemap(javaout) IMessageDependency * {
262
   return IMessageDependency.newIMessageDependency($jnicall, $owner);
263
}
264

    
265
%typemap(javaimports) IMessageDependency %{
266
import java.lang.reflect.Constructor;
267
%}
268

    
269
%typemap(javacode) IMessageDependency %{
270

    
271
   @SuppressWarnings("unchecked")
272
   private static Constructor[] messageDependencyConstructors = new Constructor[100];
273

    
274
   public long getCPtr() {
275
       return swigCPtr;
276
   }
277

    
278
   public boolean equals(Object obj) {
279
      return (obj instanceof IMessageDependency) && getCPtr(this)==getCPtr((IMessageDependency)obj);
280
   }
281

    
282
   public int hashCode() {
283
      return (int)getCPtr(this);
284
   }
285

    
286
   @SuppressWarnings("unchecked")
287
   public static IMessageDependency newIMessageDependency(long cPtr, boolean isOwner) {
288
      try {
289
         if (cPtr == 0)
290
            return null;
291

    
292
         int index = EventLogEngineJNI.IMessageDependency_getClassIndex(cPtr, null);
293
         Constructor constructor = messageDependencyConstructors[index];
294

    
295
         if (constructor == null)
296
         {
297
            String name = "org.omnetpp.eventlog.engine." + EventLogEngineJNI.IMessageDependency_getClassName(cPtr, null);
298
            Class clazz = Class.forName(name);
299
            constructor = clazz.getDeclaredConstructor(long.class, boolean.class);
300
            messageDependencyConstructors[index] = constructor;
301
         }
302

    
303
         return (IMessageDependency)constructor.newInstance(cPtr, isOwner);
304
      }
305
      catch (Exception e) {
306
         throw new RuntimeException(e);
307
      }
308
   }
309
%}
310

    
311
%typemap(javacode) IEventLog %{
312
    public IEventLog own() {
313
        swigCMemOwn = true;
314
        return this;
315
    }
316

    
317
    public IEventLog disown() {
318
        swigCMemOwn = false;
319
        return this;
320
    }
321

    
322
    public boolean equals(Object obj) {
323
        return (obj instanceof IEventLog) && getCPtr(this)==getCPtr((IEventLog)obj);
324
    }
325
%}
326

    
327
%typemap(javacode) FileReader %{
328
    public FileReader(String fileName, boolean cMemoryOwn) {
329
        this(fileName);
330
        this.swigCMemOwn = cMemoryOwn;
331
    }
332
%}
333

    
334
%typemap(javacode) IEvent %{
335
    public long getCPtr() {
336
        return swigCPtr;
337
    }
338

    
339
    public boolean equals(Object obj) {
340
        return (obj instanceof IEvent) && getCPtr(this)==getCPtr((IEvent)obj);
341
    }
342
%}
343

    
344
%newobject SequenceChartFacade::getModuleMethodBeginEntries;
345
%newobject SequenceChartFacade::getIntersectingMessageDependencies;
346

    
347
%ignore eventLogStringPool;
348
%ignore FILE;
349
%ignore *::parse;
350
%ignore *::print(FILE *);
351
%ignore *::print(FILE *, bool);
352
%ignore *::print(FILE *, long);
353
%ignore *::print(FILE *, long, long);
354
%ignore *::print(FILE *, long, long, bool);
355
%ignore *::print(FILE *, long, long, bool, bool);
356
%ignore *::printInitializationLogEntries(FILE *);
357
%ignore *::printEvents(FILE *);
358
%ignore *::printEvents(FILE *, long);
359
%ignore *::printEvents(FILE *, long, long);
360
%ignore *::printEvents(FILE *, long, long, bool);
361
%ignore *::printCause(FILE *);
362
%ignore *::printConsequence(FILE *);
363
%ignore *::printMiddle(FILE *);
364

    
365
FIX_CHARPTR_MEMBER(EventLogMessageEntry, text, Text);
366
FIX_CHARPTR_MEMBER(SimulationBeginEntry, runId, RunId);
367
FIX_CHARPTR_MEMBER(BubbleEntry, text, Text);
368
FIX_CHARPTR_MEMBER(ModuleMethodBeginEntry, method, Method);
369
FIX_CHARPTR_MEMBER(ModuleCreatedEntry, moduleClassName, ModuleClassName);
370
FIX_CHARPTR_MEMBER(ModuleCreatedEntry, fullName, FullName);
371
FIX_CHARPTR_MEMBER(GateCreatedEntry, name, Name);
372
FIX_CHARPTR_MEMBER(ConnectionDisplayStringChangedEntry, displayString, DisplayString);
373
FIX_CHARPTR_MEMBER(ModuleDisplayStringChangedEntry, displayString, DisplayString);
374
FIX_CHARPTR_MEMBER(BeginSendEntry, messageClassName, MessageClassName);
375
FIX_CHARPTR_MEMBER(BeginSendEntry, messageFullName, MessageFullName);
376
FIX_CHARPTR_MEMBER(BeginSendEntry, detail, Detail);
377

    
378
%include "ievent.h"
379
%include "ieventlog.h"
380
%include "event.h"
381
%include "filteredevent.h"
382
%include "messagedependency.h"
383
%include "eventlogentry.h"
384
%include "eventlogentries.h"
385
%include "eventlogindex.h"
386
%include "eventlog.h"
387
%include "eventlogfacade.h"
388
%include "eventlogtablefacade.h"
389
%include "sequencechartfacade.h"
390
%include "filteredeventlog.h"
391
%include "filereader.h"