Custom message to be used in TracIDemo11p in OMNeT++, Veins project - omnet++

In a project, I have to use a custom beacon message. The parameters it require, differ from the parameters that are in WaveShortMessage. I defined .msg file and was able to generate _m.cc and _m.h files. To use custom message in TraCIDemo11p, I thought of replacing WSM object parameter with that of custom messages's object parameter in onBeacon() function. But that won't work as BaseWaveApplLayer too have used WSM object only.
So I created another MyAppLayer.ned, whose content was same as that of TraCIDemo11p.ned, except "sendWhileParking" parameter (which I removed in MyAppLayer.ned) and I wrote corresponding .h and .cc files for MyAppLayer.ned by looking at the structure of TraCIDemo11p.h/.cc files. Also, I carefully included all the relevant header files, including custom message's _m.h file. But it has generated lot of errors like-
scheduleAt() not defined in the scope
"MyMsg" is not defined in the scope
.
.
.
and similar.
Please help me with how to use custom message in TraCIDemo11p in place of WSM. Thank you.

first of all, you should add following code into your file
#include omnetpp.h
and
using namespace omnetpp;
Finally you should inherit cSimpleModule class in order to recognize your methods such as scheduleAt().
For example:
class className : cSimpleModule{
...
}

Related

Specify what folder to use for creating class object Ruby

I've got a small problem (maybe it isnt even a problem)
I am making an application in Ruby, and the folder/file structure goes something like this:
OrderSet/
..item.rb
..file.rb
..order_object.rb
OrderGet/
..item.rb
..files.rb
..order.rb
As you can see I got two item.rb files, they are both different in class structure. Now I need to create an OrderSet/item.rb object, how do I specify it needs to look in OrderSet and does not get the OrderGet one?
I have to make clear, all files are required in the main rb file.
I have tried doing OrderSet.Item (the class is called Item inside the item.rb) but it complains about an ininitialized constant OrderSet
Thanks in advance!
[edit]
I have also tried to make modules out of it, maybe I don't understand the concept correctly, but I have tried it with OrderSet.Item.new (OrderSet as module name)
You could use a module to create a namespace - that way each set of classes would be encapsulated to what they do (the folder name from your example). So classes in OrderSet would be wrapped in a module for example OrderSet/item.rb would become:
module OrderSet
class Item
# methods and properties
end
end
Then you could use it like
new_order_set = OrderSet::Item.new
RubyMonk has a lesson called Modules As Namespaces which has more details and examples you can run in your browser.

TSqlObject has no ContextObject property?

I'm attempting to create a T4 template that generates source code for calling stored procedures that are contained in another project in my solution. I am able to successfully enumerate the .sql files in the solution, add them to a TSqlModel, and use that model to retrieve the list of stored procedures as TSqlObject instances. Now, I need to enumerate the parameters for each stored procedure, and this is where I'm getting hung up.
When I debug my template, I can see that the TSqlObject instances have a ContextObject property, and this property contains, among other things, the list of parameters that I need to generate my code. When I attempt to access this property from my template, however, the compiler complains that the property doesn't exist:
Error 1 Compiling transformation: 'Microsoft.SqlServer.Dac.Model.TSqlObject' does not contain a definition for 'ContextObject' and no extension method 'ContextObject' accepting a first argument of type 'Microsoft.SqlServer.Dac.Model.TSqlObject' could be found (are you missing a using directive or an assembly reference?) d:\Code\cs\test_sproccodegen\CallingProject\sproc_template.tt 34 111 CallingProject
I can definitely access this ContextObject property from the Immediate window while debugging, but it is not available at compile time.
What am I doing wrong?
The property isn't listed in the API, which probably means it's internal or private. Only public and protected accessible members are included in the docs.
Checking it out in JustDecompile, you can see it is, in fact, internal.
That's an internal method as mentioned by Will in the question comments. You should use the public APIs instead. The following documenation should help you get started:
Model API Reference
Public Model Tutorial
Dac samples project. There aren't any T4 template examples but it has a lot of examples of querying and even manipulating the model. You just need to put that in T4 template form.

VS2013 create several dll files with different classes to serialize with cereal

I tried to split some polymorphic classes to be serialized into a dll file. Then I get an exception for unregistered polymorphic type. The problem seems to be that the code create two instances of the map used to lookup polymorphic objects (Kept by template class cereal::detail::StaticObject). If I put the CEREAL_REGISTER_TYPE into the project that do the serialization, then everything works nice.
So I wonder if anyone know if it is possible to do some tricks to be able to do the registration in the dll file?
Is it possible to force the program to use the same instance of the cereal::detail::StaticObject class?
As of cereal v1.1.0 this problem can be solved by moving the polymorphic type registration to a header file, which will ensure that any translation unit including that header properly initializes its StaticObject. Just remember to include the archives you wish to bind to prior to calling the registration macro.
There's more information available on the [main cereal documentation] site(http://uscilab.github.io/cereal/polymorphism.html), which has also been updated for 1.1.
I managed to solve this problem with 1.3.0 (should work with 1.1 too) by having the following statements in an hpp in a DLL at the bottom of my DLL dependency chain. Let's call it core.dll. In that DLL I will have a file called config.hpp with the following traditional macro. CMake will define core_EXPORTS when generating the build scripts for core.dll
#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)
# if defined(core_EXPORTS)
# define CORE_DECL __declspec(dllexport)
# else
# define CORE_DECL __declspec(dllimport)
# endif
#endif
Then in another export.hpp in core.dll I have the following
namespace cereal {
namespace detail {
// these declspecs will ensure that the polymorphic loader/saver registrations will
// all happen against the binding maps in core.dll
template class CORE_DECL StaticObject<InputBindingMap<PortableBinaryInputArchive>>;
template class CORE_DECL StaticObject<InputBindingMap<JSONInputArchive>>;
template class CORE_DECL StaticObject<OutputBindingMap<PortableBinaryOutputArchive>>;
template class CORE_DECL StaticObject<OutputBindingMap<JSONOutputArchive>>;
// add similar statements for other archive types as needed
template class CORE_DECL StaticObject<Versions>;
} // namespace detail
} // namespace cereal
All other cpp files in the other dll projects will #include core/export.hpp thereby telling the linker to use the cereal StaticObjects in core.dll. If you debug the InputBindingCreator contructor you will notice that every class is now being registered in the same binding map.
I think it would be useful to add the above to the cereal documentation on this topic.

CodeIgniter - where to put functions / classes?

Am having problems understanding where classes should be kept in CI. I am building an application that describes / markets mobile phones.
I would like for all of my functions (i.e. getphone, getdetails etc.) to reside in one class called Mobile - I understand that this file should be called Mobile.php and reside in the controllers folder.
Can I then have multiple functions inside Mobile.php? E.g.
public function getphone() {
xxx
xx
xx
}
public function getdetails() {
xxx
xx
xx
}
Or do I need to put each function in its own class?
I'd really appreciate looking at some sample code that works. I've been going through the documentation and google for a few hours, and tried all sorts of variations in the URL to find a test class, but without much luck! I've even messed around with the routes and .htaccess...
All I am trying to achieve is the following:
http:///model/HTC-Desire/ to be re-routed to a function that accepts HTC-Desire as a parameter (as I need it for a DB lookup). The default controller works fine, but can't get anything to work thereafter.
Any ideas?
Thanks
Actually it works like this:
Controllers and Models go to their perspective folders as you know it
If you want to create functions that are not methods of an object, you must create a helper file. More info here :
http://codeigniter.com/user_guide/general/helpers.html
Now if you want to create your own datatypes (classes that don't extend Models and Controllers), you add them to the library folder. So if let's say you want to create a class "Car" you create this file:
class Car{
function __construct(){}
}
and save it in the libraries folder as car.php
To create an instance of the Car class you must do the following:
$this->load->library('car');
$my_car = new Car();
More information on libraries here:
http://codeigniter.com/user_guide/general/creating_libraries.html
Yes, you can have as many functions in a controller class as you'd like. They are accessible via the url /class/function.
You can catch parameters in the class functions, though it's not advisable.
class Mobile extends CI_Controller{
public function getPhone($phoneModel=''){
echo $phoneModel;
//echo $this->input->post('phoneModel');
}
}
http://site.com/mobile/getPhone/HTC-Rad theoretically would echo out "HTC-Rad". HOWEVER, special characters are not welcome in URL's in CI by default, so in this example you may be met with a 'Disallowed URI characters" error instead. You'd be better off passing the phone model (or any other parameters) via $_POST to the controller.
Classes can exist both as Controllers and Models, as CodeIgniter implements the MVC pattern. I recommend reading more about that to understand how your classes/functions/etc. can best be organized.
Off the top of my head, Pyro CMS is an application built with CodeIgniter and the source code is freely available. I'm sure there are others.
I think it's best you handle it from one perspective, that is; create a utility class with all your functions in it.
The answer to the question of where to put/place the class file is the "libraries" folder.
This is clearly stated in the documentation. Place your class in the libraries folder.
When we use the term “Libraries” we are normally referring to the
classes that are located in the libraries directory and described in
the Class Reference of this user guide.
You can read more on creating and using libraries Creating Libraries — CodeIgniter 3.1.10 documentation
After placing the newly created class in the libraries folder, to use just simply load the library within your controller as shown below:
$this->load->library('yourphpclassname');
If you wish to receive several arguments within you constructor you have to modify it to receive an argument which would be an array and you loading/initialization would then be slightly different as shown below:
$params = array('type' => 'large', 'color' => 'red');
$this->load->library('yourphpclassname', $params);
Then, to access any of the functions within the class simply do that as shown below:
$this->yourphpclassname->some_method();
I hope this answers your question if you have further question do leave a comment and I would do well to respond to them.

C++/CLI: Public ref struct generates C2011: 'class' type redefinition

I have a header file in a managed DLL project like so:
Enums.h:
#pragma once
...
public ref struct ManagedStruct {
Bitmap^ image;
}
...
This header is referenced both from another class in the DLL and from a separate executable. The managed struct alone is generating:
error C2011: 'ManagedStruct' : 'class' type redefinition.
If I move the struct to the main header file in the DLL it works fine, and is publicly accessible, so that's what I'm doing, but I would very much like to learn why this is happening when I just move it to another file.
I have checked all necessary includes and namespaces AND tried the obvious header guards, to no avail; I still get the error.
Thanks very much for any insight!
You have to de-tune the traditional C/C++ header file think a bit when you work with managed code. The principal source of type declarations is the assembly metadata. This is very different from the native C/C++ compilation model where you have to have a header file for types that you make visible to other modules.
I'm going to guess that you get this C2011 error in the EXE project. Where you both added a reference to the DLL project assembly (like you should) and used #include on the header file. Like you should not. That's a guaranteed duplicate definition, #pragma once doesn't fix that.
Don't use header files for exported type definitions. Always use assembly references.
I Know this question is a bit old, but I'm writing this for future usage:
I had the following problem, which was similar:
managed DLL had a managed class.
managed.h:
namespace Managed {
ref class CManagedClass {...}
}
in an unamanged class I wanted to use this above class and so in unmanaged.h
#include "managed.h"
in another DLL I also did:
#include "unmanged.h"
which resolved in the type redefinition error.
I have found a solution to this issue using the following method:
forward declaration in the unmanaged.h
namespace Managed {
ref class CManagedClass;
}
and include the managed.h in the unmanaged.cpp file as usual.

Resources