2013-04-20

Proper event handling in a system

This will be another short post in regards to previously mentioned system about how a system should be structured for proper event handling...

I ran into next big issue, where multiple parts of the system listens to the same update events but where we need one system to be updated first and then the next one.

I really can't find a GOOD way to solve this issue from code. I can find multiple ways to solve it, but none really seems good enough. The usual and easiest way I guess would be that there will be "system wide commands" that is handled by a controller or similar and that that functions in turn calls public functions on other objects or triggers new commands that the model/view listens to.

However, I don't really like that system due to either a lot of public functions or all the issues with trying to debug a flow.

I have really come to like the idea of having a "visual schematic/flow view" where you traverse nodes and then put all synchronization and commands in that place instead of in code. Makes it easier to understand flows and easier to understand where one flow should stop and the next should start etc...

Might have to redo some things on my hobby projet... :o

2013-04-11

Useful VS shortcuts


alt + mouse drag - creates a "selectable box" that you can use to mark certain parts of vertically aligned items such as replace all "int" in a specific line or whatever
shift + alt + enter - fullscreen coding window (remove all crap windows when you don't need them)
ctrl + k + k - bookmark
ctrl + k + n - goto next bookmark
ctrl + / [or '] - command box where you can write stuff like >of melee to quick open file
ctrl + ] [or å] - goto matching brace
ctrl + shift + ] [or å] - select everything between matching brace
Ctrl + F10 - run to cursor when debugging
Ctrl + W - select current word

ctrl + shift + r - record temporary macro
ctrl + shift + p - run temporary macro
Ctrl + K + S - surround selected code with...
Ctrl + Shift + u - Make uppercase
Ctrl + u - Make lowercase

Issue with my event solution...

This will be a short update mostly as a note to self on why it is bad to use events or something with a strong connection between classes in a solution with garbage collections.

Basically, I have some home brewn event system based around

  • Singleton Controller
  • Event/Command with id[string]
  • Registering interest on controller with ( id[string], cb[Function/Delegate])
And then I would add connection between classes similar to this:
            Controller.instance.registerInterest("id_1", onSpawnParticles);
            Controller.instance.registerInterest("id_2", onReloadDatabase);

Now, due to the issue of the callback being a function, whenever I want to delete something that registered their interest at Controller I would have to manually remove all connections or else GC will always find connections to that class...

I probably should have done this solution with the help of Observer-pattern so I only get one callback and thus only have to do one "unregister" call for each class that falls out of scope... Much easier :o)

Ah well, good thing to learn the hard way :)

2013-04-01

How I finally got PS3 Media Server to work again

After many curse words I finally managed to find out why my PS3 could not find my PS3 Media Server (PS3MS).

This is the background for my scenario:

  • Running Windows 7 64-bit
  • In PS3MS traces, this text is shown : Access granted to /192.168.1.132 (my ps3 ip)
  • On PS3, I see Windows Media Server but no PS3MS
  • When I turn off windows firewall they find eachother
  • Turning it back on and looking at the pfirewall.log file (C:\windows\system32\logfiles\firewall\) with every log setting enabled I see that TCP-connections to port 5001 are dropped
  • After a lot of guessing. googling and bruteforce attempts, it turns out that those drops are due to calls to "javaw.exe".
Solution:
For me it was inbound connections that were dropped. When looking at inbound rules for Windows Firewall advanced settings.

I had all the regular things enabled (java.exe, PS3 Media server.exe and what not...)

I had the following items as blocked on my inbound rules:
TCP C:\program files (x86)\java\jre6\bin\javaw.exe
UDP C:\program files (x86)\java\jre6\bin\javaw.exe

I enabled those applications for port 5001 on the interface "Local Area Network" and I finally got a connection.

Also, make sure that C:\windows\syswow64\java.exe is enabled.

Me guessing on why this happens:
As I understand it, it seems like the issue is that PS3 Media Server is using the java binaries to handle network communication. Thus even if PS3MS is allowed communication through firewall the communication will still be dropped. Worst part is that all of this information and all this blocking is hidden for the user making it close to impossible to understand why something was blocked...